From 37faef47ba50518ce2a972ddd619bc67440c8a56 Mon Sep 17 00:00:00 2001 From: foreman Date: Wed, 14 Feb 2018 15:08:01 -0500 Subject: [PATCH] P4 to Git Change 1516173 by skudchad@skudchad_rocm on 2018/02/14 15:02:45 SWDEV-145570 - Initial hip api checkin Affected files ... ... //depot/stg/opencl/drivers/opencl/api/hip/hip_memory.cpp#2 edit --- api/hip/hip_memory.cpp | 53 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/api/hip/hip_memory.cpp b/api/hip/hip_memory.cpp index 41ec466623..6edbe068fe 100644 --- a/api/hip/hip_memory.cpp +++ b/api/hip/hip_memory.cpp @@ -66,4 +66,57 @@ hipError_t hipFree(void* ptr) return hipSuccess; } +hipError_t hipMemcpy(void* dst, const void* src, size_t sizeBytes, hipMemcpyKind kind) +{ + HIP_INIT_API(dst, src, sizeBytes, kind); + + amd::Context* context = as_amd(g_currentCtx); + amd::Device* device = context->devices()[0]; + + // FIXME : Do we create a queue here or create at init and just reuse + amd::HostQueue* queue = new amd::HostQueue(*context, *device, 0, + amd::CommandQueue::RealTimeDisabled, + amd::CommandQueue::Priority::Normal); + if (!queue) { + return hipErrorOutOfMemory; + } + + amd::Buffer* srcBuffer = as_amd(reinterpret_cast(const_cast(src)))->asBuffer(); + amd::Buffer* dstBuffer = as_amd(reinterpret_cast(const_cast(dst)))->asBuffer(); + + amd::Command* command; + amd::Command::EventWaitList waitList; + + switch (kind) { + case hipMemcpyDeviceToHost: + command = new amd::ReadMemoryCommand(*queue, CL_COMMAND_READ_BUFFER, waitList, + srcBuffer, 0, sizeBytes, dst); + break; + case hipMemcpyHostToDevice: + command = new amd::WriteMemoryCommand(*queue, CL_COMMAND_WRITE_BUFFER, waitList, + dstBuffer, 0, sizeBytes, src); + break; + default: + assert(!"Shouldn't reach here"); + break; + } + if (!command) { + return hipErrorOutOfMemory; + } + + // Make sure we have memory for the command execution + if (CL_SUCCESS != command->validateMemory()) { + delete command; + return hipErrorMemoryAllocation; + } + + + command->enqueue(); + command->awaitCompletion(); + command->release(); + + queue->release(); + + return hipSuccess; +}