From 2ed585ec08592975c273f138952a04f38aeebf88 Mon Sep 17 00:00:00 2001
From: foreman
Date: Tue, 13 Feb 2018 19:45:32 -0500
Subject: [PATCH 001/282] P4 to Git Change 1515837 by skudchad@skudchad_rocm on
2018/02/13 19:37:06
SWDEV-145570 - Initial hip api checkin
Affected files ...
... //depot/stg/opencl/drivers/opencl/api/Makefile#10 edit
... //depot/stg/opencl/drivers/opencl/api/hip/Makefile#1 add
... //depot/stg/opencl/drivers/opencl/api/hip/build/Makefile#1 add
... //depot/stg/opencl/drivers/opencl/api/hip/build/Makefile.hip#1 add
... //depot/stg/opencl/drivers/opencl/api/hip/hip_memory.cpp#1 add
---
api/hip/hip_memory.cpp | 69 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 69 insertions(+)
create mode 100644 api/hip/hip_memory.cpp
diff --git a/api/hip/hip_memory.cpp b/api/hip/hip_memory.cpp
new file mode 100644
index 0000000000..41ec466623
--- /dev/null
+++ b/api/hip/hip_memory.cpp
@@ -0,0 +1,69 @@
+/*
+Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#include
+
+#include "hip_internal.hpp"
+
+hipError_t hipMalloc(void** ptr, size_t sizeBytes)
+{
+ HIP_INIT_API(ptr, sizeBytes);
+
+ amd::Context* context = as_amd(g_currentCtx);
+
+ if (sizeBytes == 0) {
+ *ptr = nullptr;
+ return hipSuccess;
+ }
+ else if (!is_valid(context) || !ptr) {
+ return hipErrorInvalidValue;
+ }
+
+ auto deviceHandle = as_amd(g_deviceArray[0]);
+ if ((deviceHandle->info().maxMemAllocSize_ < size)) {
+ return hipErrorOutOfMemory;
+ }
+
+ amd::Memory* mem = new (*context) amd::Buffer(*context, 0, sizeBytes);
+ if (!mem) {
+ return hipErrorOutOfMemory;
+ }
+
+ if (!mem->create(nullptr)) {
+ return hipErrorMemoryAllocation;
+ }
+
+ *ptr = reinterpret_cast(as_cl(mem));
+
+ return hipSuccess;
+}
+
+hipError_t hipFree(void* ptr)
+{
+ if (!is_valid(reinterpret_cast(ptr))) {
+ return hipErrorInvalidValue;
+ }
+ as_amd(reinterpret_cast(ptr))->release();
+ return hipSuccess;
+}
+
+
From 37faef47ba50518ce2a972ddd619bc67440c8a56 Mon Sep 17 00:00:00 2001
From: foreman
Date: Wed, 14 Feb 2018 15:08:01 -0500
Subject: [PATCH 002/282] 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;
+}
From 4fd1eb28eb1c3d8ccca01d2d1355ddd25fb01e9a Mon Sep 17 00:00:00 2001
From: foreman
Date: Tue, 27 Feb 2018 18:38:56 -0500
Subject: [PATCH 003/282] P4 to Git Change 1520507 by
skudchad@skudchad_test2_win_opencl on 2018/02/27 18:32:09
SWDEV-145570 - Populate some HIP Device Management functions.
ReviewBoardURL = http://ocltc.amd.com/reviews/r/14310/diff/
Affected files ...
... //depot/stg/opencl/drivers/opencl/api/hip/hip_device.cpp#1 add
... //depot/stg/opencl/drivers/opencl/api/hip/hip_internal.hpp#1 add
---
api/hip/hip_device.cpp | 377 +++++++++++++++++++++++++++++++++++++++
api/hip/hip_internal.hpp | 43 +++++
2 files changed, 420 insertions(+)
create mode 100644 api/hip/hip_device.cpp
create mode 100644 api/hip/hip_internal.hpp
diff --git a/api/hip/hip_device.cpp b/api/hip/hip_device.cpp
new file mode 100644
index 0000000000..557ee56643
--- /dev/null
+++ b/api/hip/hip_device.cpp
@@ -0,0 +1,377 @@
+/*
+Copyright (c) 2018 - present Advanced Micro Devices, Inc. All rights reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#include
+
+#include "hip_internal.hpp"
+
+cl_device_id* g_deviceArray = NULL;
+unsigned g_deviceCnt = 0;
+
+hipError_t hipGetDevice(int *deviceId) {
+
+ HIP_INIT_API(deviceId);
+
+ if (deviceId != NULL) {
+ // this needs to return default device. For now return 0 always
+ *deviceId = 0;
+ } else {
+ return hipErrorInvalidValue;
+ }
+
+ return hipSuccess;
+}
+
+hipError_t hipDeviceGet(hipDevice_t *device, int deviceId)
+{
+ HIP_INIT_API(device, deviceId);
+
+ if (device != nullptr) {
+ *device = deviceId;
+ } else {
+ return hipErrorInvalidValue;
+ }
+
+ return hipSuccess;
+};
+
+hipError_t hipDeviceCount(int* count) {
+
+ HIP_INIT_API(count);
+
+ if (count == NULL) {
+ return hipErrorInvalidValue;
+ }
+
+ // Get all available devices
+ if (!amd::Device::getDeviceIDs(CL_DEVICE_TYPE_GPU, 0, NULL, count, false)) {
+ return hipErrorNoDevice;
+ }
+
+ return hipSuccess;
+}
+
+hipError_t hipDeviceGetAttribute(int* pi, hipDeviceAttribute_t attr, int device) {
+
+ HIP_INIT_API(pi, attr, device);
+
+ if(pi == NULL) {
+ return hipErrorInvalidValue;
+ }
+
+ auto deviceHandle = as_amd(g_deviceArray[hipDevice]);
+
+ if (deviceHandle == NULL) {
+ return hipErrorInvalidDevice;
+ }
+
+ hipDeviceProp_t *prop = deviceHandle->_props;
+
+ switch (attr) {
+ case hipDeviceAttributeMaxThreadsPerBlock:
+ *pi = prop->maxThreadsPerBlock;
+ break;
+ case hipDeviceAttributeMaxBlockDimX:
+ *pi = prop->maxThreadsDim[0];
+ break;
+ case hipDeviceAttributeMaxBlockDimY:
+ *pi = prop->maxThreadsDim[1];
+ break;
+ case hipDeviceAttributeMaxBlockDimZ:
+ *pi = prop->maxThreadsDim[2];
+ break;
+ case hipDeviceAttributeMaxGridDimX:
+ *pi = prop->maxGridSize[0];
+ break;
+ case hipDeviceAttributeMaxGridDimY:
+ *pi = prop->maxGridSize[1];
+ break;
+ case hipDeviceAttributeMaxGridDimZ:
+ *pi = prop->maxGridSize[2];
+ break;
+ case hipDeviceAttributeMaxSharedMemoryPerBlock:
+ *pi = prop->sharedMemPerBlock;
+ break;
+ case hipDeviceAttributeTotalConstantMemory:
+ *pi = prop->totalConstMem;
+ break;
+ case hipDeviceAttributeWarpSize:
+ *pi = prop->warpSize;
+ break;
+ case hipDeviceAttributeMaxRegistersPerBlock:
+ *pi = prop->regsPerBlock;
+ break;
+ case hipDeviceAttributeClockRate:
+ *pi = prop->clockRate;
+ break;
+ case hipDeviceAttributeMemoryClockRate:
+ *pi = prop->memoryClockRate;
+ break;
+ case hipDeviceAttributeMemoryBusWidth:
+ *pi = prop->memoryBusWidth;
+ break;
+ case hipDeviceAttributeMultiprocessorCount:
+ *pi = prop->multiProcessorCount;
+ break;
+ case hipDeviceAttributeComputeMode:
+ *pi = prop->computeMode;
+ break;
+ case hipDeviceAttributeL2CacheSize:
+ *pi = prop->l2CacheSize;
+ break;
+ case hipDeviceAttributeMaxThreadsPerMultiProcessor:
+ *pi = prop->maxThreadsPerMultiProcessor;
+ break;
+ case hipDeviceAttributeComputeCapabilityMajor:
+ *pi = prop->major;
+ break;
+ case hipDeviceAttributeComputeCapabilityMinor:
+ *pi = prop->minor;
+ break;
+ case hipDeviceAttributePciBusId:
+ *pi = prop->pciBusID;
+ break;
+ case hipDeviceAttributeConcurrentKernels:
+ *pi = prop->concurrentKernels;
+ break;
+ case hipDeviceAttributePciDeviceId:
+ *pi = prop->pciDeviceID;
+ break;
+ case hipDeviceAttributeMaxSharedMemoryPerMultiprocessor:
+ *pi = prop->maxSharedMemoryPerMultiProcessor;
+ break;
+ case hipDeviceAttributeIsMultiGpuBoard:
+ *pi = prop->isMultiGpuBoard;
+ break;
+ default:
+ return hipErrorInvalidValue;
+ }
+
+ return hipSuccess;
+}
+
+hipError_t hipGetDeviceProperties(hipDeviceProp_t* props, int device) {
+
+ HIP_INIT_API(props, device);
+
+ if (props == NULL) {
+ return hipErrorInvalidValue;
+ }
+
+ auto deviceHandle = as_amd(g_deviceArray[device]);
+ if (deviceHandle == NULL) {
+ return hipErrorInvalidDevice;
+ }
+
+ hipDeviceProp_t deviceProps = {0};
+
+ const auto& info = deviceHandle->info();
+ ::strncpy(deviceProps.name, info.boardName_, 128);
+ deviceProps.totalGlobalMem = info.globalMemSize_;
+ deviceProps.sharedMemPerBlock = info.localMemSizePerCU_;
+ deviceProps.regsPerBlock = info.availableSGPRs_;
+ deviceProps.warpSize = info.wavefrontWidth_;
+ deviceProps.maxThreadsPerBlock = info.maxWorkGroupSize_;
+ deviceProps.maxThreadsDim[0] = info.maxWorkItemSizes_[0];
+ deviceProps.maxThreadsDim[1] = info.maxWorkItemSizes_[1];
+ deviceProps.maxThreadsDim[2] = info.maxWorkItemSizes_[2];
+ deviceProps.maxGridSize[0] = UINT32_MAX;
+ deviceProps.maxGridSize[1] = UINT32_MAX;
+ deviceProps.maxGridSize[2] = UINT32_MAX;
+ deviceProps.clockRate = info.maxEngineClockFrequency_;
+ deviceProps.memoryClockRate = info.maxMemoryClockFrequency_;
+ deviceProps.memoryBusWidth = info.globalMemChannels_ * 32;
+ deviceProps.totalConstMem = info.maxConstantBufferSize_;
+ deviceProps.major = info.gfxipVersion_ / 100;
+ deviceProps.minor = info.gfxipVersion_ % 100;
+ deviceProps.multiProcessorCount = info.maxComputeUnits_;
+ deviceProps.l2CacheSize = info.l2CacheSize_;
+ deviceProps.maxThreadsPerMultiProcessor = info.simdPerCU_;
+ deviceProps.computeMode = 0;
+ deviceProps.clockInstructionRate = info.timeStampFrequency_;
+ deviceProps.arch.hasGlobalInt32Atomics = 1;
+ deviceProps.arch.hasGlobalFloatAtomicExch = 1;
+ deviceProps.arch.hasSharedInt32Atomics = 1;
+ deviceProps.arch.hasSharedFloatAtomicExch = 1;
+ deviceProps.arch.hasFloatAtomicAdd = 0;
+ deviceProps.arch.hasGlobalInt64Atomics = 1;
+ deviceProps.arch.hasSharedInt64Atomics = 1;
+ deviceProps.arch.hasDoubles = 1;
+ deviceProps.arch.hasWarpVote = 0;
+ deviceProps.arch.hasWarpBallot = 0;
+ deviceProps.arch.hasWarpShuffle = 0;
+ deviceProps.arch.hasFunnelShift = 0;
+ deviceProps.arch.hasThreadFenceSystem = 1;
+ deviceProps.arch.hasSyncThreadsExt = 0;
+ deviceProps.arch.hasSurfaceFuncs = 0;
+ deviceProps.arch.has3dGrid = 1;
+ deviceProps.arch.hasDynamicParallelism = 0;
+ deviceProps.concurrentKernels = 1;
+ deviceProps.pciDomainID = info.deviceTopology_.function;
+ deviceProps.pciBusID = info.deviceTopology_.bus;
+ deviceProps.pciDeviceID = info.deviceTopology_.device;
+ deviceProps.maxSharedMemoryPerMultiProcessor = info.localMemSizePerCU_;
+ deviceProps.isMultiGpuBoard = info.;
+ deviceProps.canMapHostMemory = 1;
+ deviceProps.gcnArch = info.gfxipVersion_;
+
+ *props = deviceProps;
+ return hipSuccess;
+}
+
+hipError_t hipDeviceSetCacheConfig(hipFuncCache_t cacheConfig) {
+
+ HIP_INIT_API(cacheConfig);
+
+ // No way to set cache config yet.
+
+ return hipSuccess;
+}
+
+hipError_t hipDeviceGetCacheConfig(hipFuncCache_t *cacheConfig) {
+ HIP_INIT_API(cacheConfig);
+
+ if(cacheConfig == NULL) {
+ return hipErrorInvalidValue;
+ }
+
+ *cacheConfig = 0;
+
+ return hipSuccess;
+}
+
+hipError_t hipGetDeviceProperties(hipDeviceProp_t* properties, int device) {
+
+ HIP_INIT_API(properties, device);
+ if ((properties == NULL) || (device < 0) || (device >= g_deviceCnt)) {
+ return hipErrorInvalidDevice;
+ }
+
+ auto * deviceHandle = as_amd(g_deviceArray[device]);
+ if (deviceHandle != NULL) {
+ *properties = deviceHandle->_props;
+ return hipSuccess;
+ }
+
+ return hipErrorInvalidDevice;
+}
+
+hipError_t hipSetDeviceFlags(unsigned int flags) {
+
+ HIP_INIT_API(flags);
+
+ assert(0 && "Unimplemented")
+
+ return hipSuccess;
+};
+
+hipError_t hipDeviceGetLimit (size_t *pValue, hipLimit_t limit) {
+
+ HIP_INIT_API(pValue, limit);
+
+ assert(0 && "Unimplemented")
+
+ return hipSuccess;
+}
+
+hipError_t hipFuncSetCacheConfig (const void* func, hipFuncCache_t cacheConfig) {
+
+ HIP_INIT_API(cacheConfig);
+
+ assert(0 && "Not supported")
+
+ return hipSuccess;
+}
+
+hipError_t hipDeviceSetSharedMemConfig (hipSharedMemConfig config) {
+
+ HIP_INIT_API(config);
+
+ assert(0 && "Not Supported")
+
+ return hipSuccess;
+}
+
+hipError_t hipDeviceGetSharedMemConfig (hipSharedMemConfig *pConfig) {
+
+ HIP_INIT_API(pConfig);
+
+ assert(0 && "Not supported")
+
+ return hipSuccess;
+}
+
+
+hipError_t hipChooseDevice(int* device, const hipDeviceProp_t* properties) {
+
+ HIP_INIT_API(device, properties);
+
+ assert(0 && "Unimplemented")
+
+ return hipSuccess;
+}
+
+
+hipError_t hipDeviceGetByPCIBusId (int* device, const char* pciBusId) {
+
+ HIP_INIT_API(device,pciBusId);
+
+ assert(0 && "Unimplemented")
+
+ return hipSuccess;
+}
+
+
+hipError_t hipDeviceTotalMem (size_t *bytes,hipDevice_t device) {
+
+ HIP_INIT_API(bytes, device);
+
+ assert(0 && "Unimplemented")
+
+ return hipSuccess;
+}
+
+hipError_t hipDeviceComputeCapability(int *major, int *minor, hipDevice_t device) {
+
+ HIP_INIT_API(major,minor, device);
+ assert(0 && "Unimplemented")
+
+ return hipSuccess;
+}
+
+hipError_t hipDeviceGetName(char *name,int len, hipDevice_t device) {
+
+ HIP_INIT_API((void*)name,len, device);
+
+ assert(0 && "Unimplemented")
+
+ return hipSuccess;
+}
+
+hipError_t hipDeviceGetPCIBusId (char *pciBusId,int len, int device) {
+
+ HIP_INIT_API((void*)pciBusId, len, device);
+
+ assert(0 && "Unimplemented")
+
+ return hipSuccess;
+}
\ No newline at end of file
diff --git a/api/hip/hip_internal.hpp b/api/hip/hip_internal.hpp
new file mode 100644
index 0000000000..7e7b27c143
--- /dev/null
+++ b/api/hip/hip_internal.hpp
@@ -0,0 +1,43 @@
+/*
+Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#ifndef HIP_SRC_HIP_INTERNAL_H
+#define HIP_SRC_HIP_INTERNAL_H
+
+#include "cl_common.hpp"
+
+#define HIP_INIT()\
+ amd::Thread* thread = amd::Thread::current(); \
+ if (!CL_CHECK_THREAD(thread)) { \
+ return hipErrorOutOfMemory; \
+ }
+
+
+// This macro should be called at the beginning of every HIP API.
+#define HIP_INIT_API(...) \
+ HIP_INIT()
+
+extern cl_device_id* g_deviceArray;
+extern unsigned g_deviceCnt;
+extern thread_local cl_context g_currentCtx;
+
+#endif // HIP_SRC_HIP_INTERNAL_H
From 73cb309e2bd65be2a056c6c8dcda9f31381c953a Mon Sep 17 00:00:00 2001
From: foreman
Date: Thu, 1 Mar 2018 22:57:20 -0500
Subject: [PATCH 004/282] P4 to Git Change 1521675 by
lmoriche@lmoriche_opencl_dev2 on 2018/03/01 22:50:06
SWDEV-145570 - [HIP] - Hip Rearchitecture
- Add initial prototype implementation
Affected files ...
... //depot/stg/opencl/drivers/opencl/api/Makefile#11 edit
... //depot/stg/opencl/drivers/opencl/api/hip/fixme.cpp#1 add
... //depot/stg/opencl/drivers/opencl/api/hip/hip_context.cpp#1 add
... //depot/stg/opencl/drivers/opencl/api/hip/hip_device.cpp#2 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_error.cpp#1 add
... //depot/stg/opencl/drivers/opencl/api/hip/hip_event.cpp#1 add
... //depot/stg/opencl/drivers/opencl/api/hip/hip_hcc.def.in#1 add
... //depot/stg/opencl/drivers/opencl/api/hip/hip_hcc.map.in#1 add
... //depot/stg/opencl/drivers/opencl/api/hip/hip_hcc.rc#1 add
... //depot/stg/opencl/drivers/opencl/api/hip/hip_internal.hpp#2 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_memory.cpp#3 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_module.cpp#1 add
... //depot/stg/opencl/drivers/opencl/api/hip/hip_platform.cpp#1 add
---
api/hip/fixme.cpp | 33 +++++++
api/hip/hip_context.cpp | 58 ++++++++++++
api/hip/hip_device.cpp | 140 +++++++++++++---------------
api/hip/hip_error.cpp | 48 ++++++++++
api/hip/hip_event.cpp | 67 ++++++++++++++
api/hip/hip_hcc.def.in | 129 ++++++++++++++++++++++++++
api/hip/hip_hcc.map.in | 133 +++++++++++++++++++++++++++
api/hip/hip_hcc.rc | 75 +++++++++++++++
api/hip/hip_internal.hpp | 4 +-
api/hip/hip_memory.cpp | 133 +++++++++++++--------------
api/hip/hip_module.cpp | 144 +++++++++++++++++++++++++++++
api/hip/hip_platform.cpp | 193 +++++++++++++++++++++++++++++++++++++++
12 files changed, 1010 insertions(+), 147 deletions(-)
create mode 100644 api/hip/fixme.cpp
create mode 100644 api/hip/hip_context.cpp
create mode 100644 api/hip/hip_error.cpp
create mode 100644 api/hip/hip_event.cpp
create mode 100644 api/hip/hip_hcc.def.in
create mode 100644 api/hip/hip_hcc.map.in
create mode 100644 api/hip/hip_hcc.rc
create mode 100644 api/hip/hip_module.cpp
create mode 100644 api/hip/hip_platform.cpp
diff --git a/api/hip/fixme.cpp b/api/hip/fixme.cpp
new file mode 100644
index 0000000000..3d062e2dbc
--- /dev/null
+++ b/api/hip/fixme.cpp
@@ -0,0 +1,33 @@
+/*
+Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#include "cl_common.hpp"
+
+KHRicdVendorDispatch amd::ICDDispatchedObject::icdVendorDispatch_[] = {0};
+amd::PlatformIDS amd::PlatformID::Platform = {amd::ICDDispatchedObject::icdVendorDispatch_};
+
+RUNTIME_ENTRY(cl_int, clGetDeviceIDs,
+ (cl_platform_id platform, cl_device_type device_type, cl_uint num_entries,
+ cl_device_id* devices, cl_uint* num_devices)) {
+ return CL_SUCCESS;
+}
+RUNTIME_EXIT
diff --git a/api/hip/hip_context.cpp b/api/hip/hip_context.cpp
new file mode 100644
index 0000000000..0e6ff2116a
--- /dev/null
+++ b/api/hip/hip_context.cpp
@@ -0,0 +1,58 @@
+/*
+Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#include
+
+#include "hip_internal.hpp"
+#include "platform/runtime.hpp"
+
+
+amd::Context* g_context = nullptr;
+
+hipError_t hipInit(unsigned int flags)
+{
+ HIP_INIT_API(flags);
+
+ if (!amd::Runtime::initialized()) {
+ amd::Runtime::init();
+ }
+
+ // FIXME: move the global VDI context to hipInit.
+ g_context = new amd::Context(
+ amd::Device::getDevices(CL_DEVICE_TYPE_GPU, false), amd::Context::Info());
+ if (!g_context) return hipErrorOutOfMemory;
+
+ if (g_context && CL_SUCCESS != g_context->create(nullptr)) {
+ g_context->release();
+ return hipErrorUnknown;
+ }
+
+ return hipSuccess;
+}
+
+hipError_t hipCtxCreate(hipCtx_t *ctx, unsigned int flags, hipDevice_t device)
+{
+ HIP_INIT_API(ctx, flags, device);
+
+ return hipSuccess;
+}
+
diff --git a/api/hip/hip_device.cpp b/api/hip/hip_device.cpp
index 557ee56643..7296eabb17 100644
--- a/api/hip/hip_device.cpp
+++ b/api/hip/hip_device.cpp
@@ -24,9 +24,6 @@ THE SOFTWARE.
#include "hip_internal.hpp"
-cl_device_id* g_deviceArray = NULL;
-unsigned g_deviceCnt = 0;
-
hipError_t hipGetDevice(int *deviceId) {
HIP_INIT_API(deviceId);
@@ -54,7 +51,7 @@ hipError_t hipDeviceGet(hipDevice_t *device, int deviceId)
return hipSuccess;
};
-hipError_t hipDeviceCount(int* count) {
+hipError_t hipGetDeviceCount(int* count) {
HIP_INIT_API(count);
@@ -63,9 +60,7 @@ hipError_t hipDeviceCount(int* count) {
}
// Get all available devices
- if (!amd::Device::getDeviceIDs(CL_DEVICE_TYPE_GPU, 0, NULL, count, false)) {
- return hipErrorNoDevice;
- }
+ *count = g_context->devices().size();
return hipSuccess;
}
@@ -74,93 +69,95 @@ hipError_t hipDeviceGetAttribute(int* pi, hipDeviceAttribute_t attr, int device)
HIP_INIT_API(pi, attr, device);
- if(pi == NULL) {
+ if (pi == nullptr) {
return hipErrorInvalidValue;
}
- auto deviceHandle = as_amd(g_deviceArray[hipDevice]);
+ //if (unsigned(device) >= g_context->devices().size()) {
+ // return hipErrorInvalidDevice;
+ //}
+ //auto* deviceHandle = g_context->devices()[device];
- if (deviceHandle == NULL) {
- return hipErrorInvalidDevice;
- }
-
- hipDeviceProp_t *prop = deviceHandle->_props;
+ //FIXME: should we cache the props, or just select from deviceHandle->info_?
+ hipDeviceProp_t prop = {0};
+ hipError_t err = hipGetDeviceProperties(&prop, device);
+ if (err != hipSuccess) return err;
switch (attr) {
case hipDeviceAttributeMaxThreadsPerBlock:
- *pi = prop->maxThreadsPerBlock;
+ *pi = prop.maxThreadsPerBlock;
break;
case hipDeviceAttributeMaxBlockDimX:
- *pi = prop->maxThreadsDim[0];
+ *pi = prop.maxThreadsDim[0];
break;
case hipDeviceAttributeMaxBlockDimY:
- *pi = prop->maxThreadsDim[1];
+ *pi = prop.maxThreadsDim[1];
break;
case hipDeviceAttributeMaxBlockDimZ:
- *pi = prop->maxThreadsDim[2];
+ *pi = prop.maxThreadsDim[2];
break;
case hipDeviceAttributeMaxGridDimX:
- *pi = prop->maxGridSize[0];
+ *pi = prop.maxGridSize[0];
break;
case hipDeviceAttributeMaxGridDimY:
- *pi = prop->maxGridSize[1];
+ *pi = prop.maxGridSize[1];
break;
case hipDeviceAttributeMaxGridDimZ:
- *pi = prop->maxGridSize[2];
+ *pi = prop.maxGridSize[2];
break;
case hipDeviceAttributeMaxSharedMemoryPerBlock:
- *pi = prop->sharedMemPerBlock;
+ *pi = prop.sharedMemPerBlock;
break;
case hipDeviceAttributeTotalConstantMemory:
- *pi = prop->totalConstMem;
+ *pi = prop.totalConstMem;
break;
case hipDeviceAttributeWarpSize:
- *pi = prop->warpSize;
+ *pi = prop.warpSize;
break;
case hipDeviceAttributeMaxRegistersPerBlock:
- *pi = prop->regsPerBlock;
+ *pi = prop.regsPerBlock;
break;
case hipDeviceAttributeClockRate:
- *pi = prop->clockRate;
+ *pi = prop.clockRate;
break;
case hipDeviceAttributeMemoryClockRate:
- *pi = prop->memoryClockRate;
+ *pi = prop.memoryClockRate;
break;
case hipDeviceAttributeMemoryBusWidth:
- *pi = prop->memoryBusWidth;
+ *pi = prop.memoryBusWidth;
break;
case hipDeviceAttributeMultiprocessorCount:
- *pi = prop->multiProcessorCount;
+ *pi = prop.multiProcessorCount;
break;
case hipDeviceAttributeComputeMode:
- *pi = prop->computeMode;
+ *pi = prop.computeMode;
break;
case hipDeviceAttributeL2CacheSize:
- *pi = prop->l2CacheSize;
+ *pi = prop.l2CacheSize;
break;
case hipDeviceAttributeMaxThreadsPerMultiProcessor:
- *pi = prop->maxThreadsPerMultiProcessor;
+ *pi = prop.maxThreadsPerMultiProcessor;
break;
case hipDeviceAttributeComputeCapabilityMajor:
- *pi = prop->major;
+ *pi = prop.major;
break;
case hipDeviceAttributeComputeCapabilityMinor:
- *pi = prop->minor;
+ *pi = prop.minor;
break;
case hipDeviceAttributePciBusId:
- *pi = prop->pciBusID;
+ *pi = prop.pciBusID;
break;
case hipDeviceAttributeConcurrentKernels:
- *pi = prop->concurrentKernels;
+ *pi = prop.concurrentKernels;
break;
case hipDeviceAttributePciDeviceId:
- *pi = prop->pciDeviceID;
+ *pi = prop.pciDeviceID;
break;
case hipDeviceAttributeMaxSharedMemoryPerMultiprocessor:
- *pi = prop->maxSharedMemoryPerMultiProcessor;
+ *pi = prop.maxSharedMemoryPerMultiProcessor;
break;
case hipDeviceAttributeIsMultiGpuBoard:
- *pi = prop->isMultiGpuBoard;
+ *pi = prop.isMultiGpuBoard;
break;
default:
return hipErrorInvalidValue;
@@ -177,10 +174,10 @@ hipError_t hipGetDeviceProperties(hipDeviceProp_t* props, int device) {
return hipErrorInvalidValue;
}
- auto deviceHandle = as_amd(g_deviceArray[device]);
- if (deviceHandle == NULL) {
+ if (unsigned(device) >= g_context->devices().size()) {
return hipErrorInvalidDevice;
}
+ auto* deviceHandle = g_context->devices()[device];
hipDeviceProp_t deviceProps = {0};
@@ -226,11 +223,11 @@ hipError_t hipGetDeviceProperties(hipDeviceProp_t* props, int device) {
deviceProps.arch.has3dGrid = 1;
deviceProps.arch.hasDynamicParallelism = 0;
deviceProps.concurrentKernels = 1;
- deviceProps.pciDomainID = info.deviceTopology_.function;
- deviceProps.pciBusID = info.deviceTopology_.bus;
- deviceProps.pciDeviceID = info.deviceTopology_.device;
+ deviceProps.pciDomainID = info.deviceTopology_.pcie.function;
+ deviceProps.pciBusID = info.deviceTopology_.pcie.bus;
+ deviceProps.pciDeviceID = info.deviceTopology_.pcie.device;
deviceProps.maxSharedMemoryPerMultiProcessor = info.localMemSizePerCU_;
- deviceProps.isMultiGpuBoard = info.;
+ //deviceProps.isMultiGpuBoard = info.;
deviceProps.canMapHostMemory = 1;
deviceProps.gcnArch = info.gfxipVersion_;
@@ -254,32 +251,16 @@ hipError_t hipDeviceGetCacheConfig(hipFuncCache_t *cacheConfig) {
return hipErrorInvalidValue;
}
- *cacheConfig = 0;
+ *cacheConfig = hipFuncCache_t();
return hipSuccess;
}
-hipError_t hipGetDeviceProperties(hipDeviceProp_t* properties, int device) {
-
- HIP_INIT_API(properties, device);
- if ((properties == NULL) || (device < 0) || (device >= g_deviceCnt)) {
- return hipErrorInvalidDevice;
- }
-
- auto * deviceHandle = as_amd(g_deviceArray[device]);
- if (deviceHandle != NULL) {
- *properties = deviceHandle->_props;
- return hipSuccess;
- }
-
- return hipErrorInvalidDevice;
-}
-
hipError_t hipSetDeviceFlags(unsigned int flags) {
HIP_INIT_API(flags);
- assert(0 && "Unimplemented")
+ assert(0 && "Unimplemented");
return hipSuccess;
};
@@ -288,7 +269,7 @@ hipError_t hipDeviceGetLimit (size_t *pValue, hipLimit_t limit) {
HIP_INIT_API(pValue, limit);
- assert(0 && "Unimplemented")
+ assert(0 && "Unimplemented");
return hipSuccess;
}
@@ -297,7 +278,7 @@ hipError_t hipFuncSetCacheConfig (const void* func, hipFuncCache_t cacheConfig)
HIP_INIT_API(cacheConfig);
- assert(0 && "Not supported")
+ assert(0 && "Not supported");
return hipSuccess;
}
@@ -306,7 +287,7 @@ hipError_t hipDeviceSetSharedMemConfig (hipSharedMemConfig config) {
HIP_INIT_API(config);
- assert(0 && "Not Supported")
+ assert(0 && "Not Supported");
return hipSuccess;
}
@@ -315,17 +296,17 @@ hipError_t hipDeviceGetSharedMemConfig (hipSharedMemConfig *pConfig) {
HIP_INIT_API(pConfig);
- assert(0 && "Not supported")
+ assert(0 && "Not supported");
return hipSuccess;
}
-hipError_t hipChooseDevice(int* device, const hipDeviceProp_t* properties) {
+hipError_t hipChooseDevice(int* device, const hipDeviceProp_t* properties) {
HIP_INIT_API(device, properties);
-
- assert(0 && "Unimplemented")
+
+ assert(0 && "Unimplemented");
return hipSuccess;
}
@@ -335,7 +316,7 @@ hipError_t hipDeviceGetByPCIBusId (int* device, const char* pciBusId) {
HIP_INIT_API(device,pciBusId);
- assert(0 && "Unimplemented")
+ assert(0 && "Unimplemented");
return hipSuccess;
}
@@ -345,7 +326,7 @@ hipError_t hipDeviceTotalMem (size_t *bytes,hipDevice_t device) {
HIP_INIT_API(bytes, device);
- assert(0 && "Unimplemented")
+ assert(0 && "Unimplemented");
return hipSuccess;
}
@@ -353,7 +334,8 @@ hipError_t hipDeviceTotalMem (size_t *bytes,hipDevice_t device) {
hipError_t hipDeviceComputeCapability(int *major, int *minor, hipDevice_t device) {
HIP_INIT_API(major,minor, device);
- assert(0 && "Unimplemented")
+
+ assert(0 && "Unimplemented");
return hipSuccess;
}
@@ -362,7 +344,7 @@ hipError_t hipDeviceGetName(char *name,int len, hipDevice_t device) {
HIP_INIT_API((void*)name,len, device);
- assert(0 && "Unimplemented")
+ assert(0 && "Unimplemented");
return hipSuccess;
}
@@ -371,7 +353,13 @@ hipError_t hipDeviceGetPCIBusId (char *pciBusId,int len, int device) {
HIP_INIT_API((void*)pciBusId, len, device);
- assert(0 && "Unimplemented")
+ assert(0 && "Unimplemented");
return hipSuccess;
-}
\ No newline at end of file
+}
+
+hipError_t hipDeviceSynchronize(void)
+{
+ // FIXME: should wait on all streams
+ return hipSuccess;
+}
diff --git a/api/hip/hip_error.cpp b/api/hip/hip_error.cpp
new file mode 100644
index 0000000000..2a8785c375
--- /dev/null
+++ b/api/hip/hip_error.cpp
@@ -0,0 +1,48 @@
+/*
+Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#include
+
+#include "hip_internal.hpp"
+
+hipError_t hipGetLastError()
+{
+ HIP_INIT_API();
+ return hipErrorUnknown;
+}
+
+hipError_t hipPeekAtLastError()
+{
+ HIP_INIT_API();
+ return hipErrorUnknown;
+}
+
+const char *hipGetErrorName(hipError_t hip_error)
+{
+ return "";
+}
+
+const char *hipGetErrorString(hipError_t hip_error)
+{
+ return "";
+}
+
diff --git a/api/hip/hip_event.cpp b/api/hip/hip_event.cpp
new file mode 100644
index 0000000000..117b28355e
--- /dev/null
+++ b/api/hip/hip_event.cpp
@@ -0,0 +1,67 @@
+/*
+Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#include
+
+#include "hip_internal.hpp"
+
+hipError_t hipEventCreateWithFlags(hipEvent_t* event, unsigned flags)
+{
+ HIP_INIT_API(event, flags);
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipEventCreate(hipEvent_t* event)
+{
+ HIP_INIT_API(event);
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipEventDestroy(hipEvent_t event)
+{
+ HIP_INIT_API(event);
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipEventElapsedTime(float *ms, hipEvent_t start, hipEvent_t stop)
+{
+ HIP_INIT_API(ms, start, stop);
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipEventRecord(hipEvent_t event, hipStream_t stream)
+{
+ HIP_INIT_API(event, stream);
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipEventSynchronize(hipEvent_t event)
+{
+ HIP_INIT_API(event);
+
+ return hipErrorUnknown;
+}
diff --git a/api/hip/hip_hcc.def.in b/api/hip/hip_hcc.def.in
new file mode 100644
index 0000000000..6b4793ea94
--- /dev/null
+++ b/api/hip/hip_hcc.def.in
@@ -0,0 +1,129 @@
+EXPORTS
+hipChooseDevice
+hipCtxCreate
+hipCtxDestroy
+hipCtxDisablePeerAccess
+hipCtxEnablePeerAccess
+hipCtxGetApiVersion
+hipCtxGetCacheConfig
+hipCtxGetCurrent
+hipCtxGetDevice
+hipCtxGetFlags
+hipCtxGetSharedMemConfig
+hipCtxPopCurrent
+hipCtxPushCurrent
+hipCtxSetCacheConfig
+hipCtxSetCurrent
+hipCtxSetSharedMemConfig
+hipCtxSynchronize
+hipDeviceCanAccessPeer
+hipDeviceComputeCapability
+hipDeviceDisablePeerAccess
+hipDeviceEnablePeerAccess
+hipDeviceGet
+hipDeviceGetAttribute
+hipDeviceGetByPCIBusId
+hipDeviceGetCacheConfig
+hipDeviceGetLimit
+hipDeviceGetName
+hipDeviceGetPCIBusId
+hipDeviceGetSharedMemConfig
+hipDevicePrimaryCtxGetState
+hipDevicePrimaryCtxRelease
+hipDevicePrimaryCtxReset
+hipDevicePrimaryCtxRetain
+hipDevicePrimaryCtxSetFlags
+hipDeviceReset
+hipDeviceSetCacheConfig
+hipDeviceSetSharedMemConfig
+hipDeviceSynchronize
+hipDeviceTotalMem
+hipDriverGetVersion
+hipEventCreate
+hipEventCreateWithFlags
+hipEventDestroy
+hipEventElapsedTime
+hipEventQuery
+hipEventRecord
+hipEventSynchronize
+hipFree
+hipFreeArray
+hipFreeHost
+hipFuncSetCacheConfig
+hipGetDevice
+hipGetDeviceCount
+hipGetDeviceProperties
+hipGetErrorName
+hipGetErrorString
+hipGetLastError
+hipHostAlloc
+hipHostFree
+hipHostGetDevicePointer
+hipHostGetFlags
+hipHostMalloc
+hipHostRegister
+hipHostUnregister
+hipInit
+hipIpcCloseMemHandle
+hipIpcGetMemHandle
+hipIpcOpenMemHandle
+hipMalloc
+hipMalloc3DArray
+hipMallocArray
+hipMallocHost
+hipMallocPitch
+hipMemcpy
+hipMemcpy2D
+hipMemcpy2DAsync
+hipMemcpy2DToArray
+hipMemcpy3D
+hipMemcpyAsync
+hipMemcpyDtoD
+hipMemcpyDtoDAsync
+hipMemcpyDtoH
+hipMemcpyDtoHAsync
+hipMemcpyFromSymbol
+hipMemcpyFromSymbolAsync
+hipMemcpyHtoD
+hipMemcpyHtoDAsync
+hipMemcpyPeer
+hipMemcpyPeerAsync
+hipMemcpyToArray
+hipMemcpyToSymbol
+hipMemcpyToSymbolAsync
+hipMemGetAddressRange
+hipMemGetInfo
+hipMemPtrGetInfo
+hipMemset
+hipMemset2D
+hipMemsetAsync
+hipMemsetD8
+hipModuleGetFunction
+hipModuleGetGlobal
+hipModuleLaunchKernel
+hipModuleLoad
+hipModuleLoadData
+hipModuleLoadDataEx
+hipModuleUnload
+hipPeekAtLastError
+hipPointerGetAttributes
+hipProfilerStart
+hipProfilerStop
+hipRuntimeGetVersion
+hipSetDevice
+hipSetDeviceFlags
+hipStreamAddCallback
+hipStreamCreate
+hipStreamCreateWithFlags
+hipStreamDestroy
+hipStreamGetFlags
+hipStreamQuery
+hipStreamSynchronize
+hipStreamWaitEvent
+__cudaRegisterFatBinary
+__cudaRegisterFunction
+__cudaRegisterVariable
+__cudaUnregisterFatBinary
+cudaConfigureCall
+cudaSetupArgument
+cudaLaunch
diff --git a/api/hip/hip_hcc.map.in b/api/hip/hip_hcc.map.in
new file mode 100644
index 0000000000..e4025606bc
--- /dev/null
+++ b/api/hip/hip_hcc.map.in
@@ -0,0 +1,133 @@
+HIP_1.0 {
+global:
+ hipChooseDevice;
+ hipCtxCreate;
+ hipCtxDestroy;
+ hipCtxDisablePeerAccess;
+ hipCtxEnablePeerAccess;
+ hipCtxGetApiVersion;
+ hipCtxGetCacheConfig;
+ hipCtxGetCurrent;
+ hipCtxGetDevice;
+ hipCtxGetFlags;
+ hipCtxGetSharedMemConfig;
+ hipCtxPopCurrent;
+ hipCtxPushCurrent;
+ hipCtxSetCacheConfig;
+ hipCtxSetCurrent;
+ hipCtxSetSharedMemConfig;
+ hipCtxSynchronize;
+ hipDeviceCanAccessPeer;
+ hipDeviceComputeCapability;
+ hipDeviceDisablePeerAccess;
+ hipDeviceEnablePeerAccess;
+ hipDeviceGet;
+ hipDeviceGetAttribute;
+ hipDeviceGetByPCIBusId;
+ hipDeviceGetCacheConfig;
+ hipDeviceGetLimit;
+ hipDeviceGetName;
+ hipDeviceGetPCIBusId;
+ hipDeviceGetSharedMemConfig;
+ hipDevicePrimaryCtxGetState;
+ hipDevicePrimaryCtxRelease;
+ hipDevicePrimaryCtxReset;
+ hipDevicePrimaryCtxRetain;
+ hipDevicePrimaryCtxSetFlags;
+ hipDeviceReset;
+ hipDeviceSetCacheConfig;
+ hipDeviceSetSharedMemConfig;
+ hipDeviceSynchronize;
+ hipDeviceTotalMem;
+ hipDriverGetVersion;
+ hipEventCreate;
+ hipEventCreateWithFlags;
+ hipEventDestroy;
+ hipEventElapsedTime;
+ hipEventQuery;
+ hipEventRecord;
+ hipEventSynchronize;
+ hipFree;
+ hipFreeArray;
+ hipFreeHost;
+ hipFuncSetCacheConfig;
+ hipGetDevice;
+ hipGetDeviceCount;
+ hipGetDeviceProperties;
+ hipGetErrorName;
+ hipGetErrorString;
+ hipGetLastError;
+ hipHostAlloc;
+ hipHostFree;
+ hipHostGetDevicePointer;
+ hipHostGetFlags;
+ hipHostMalloc;
+ hipHostRegister;
+ hipHostUnregister;
+ hipInit;
+ hipIpcCloseMemHandle;
+ hipIpcGetMemHandle;
+ hipIpcOpenMemHandle;
+ hipMalloc;
+ hipMalloc3DArray;
+ hipMallocArray;
+ hipMallocHost;
+ hipMallocPitch;
+ hipMemcpy;
+ hipMemcpy2D;
+ hipMemcpy2DAsync;
+ hipMemcpy2DToArray;
+ hipMemcpy3D;
+ hipMemcpyAsync;
+ hipMemcpyDtoD;
+ hipMemcpyDtoDAsync;
+ hipMemcpyDtoH;
+ hipMemcpyDtoHAsync;
+ hipMemcpyFromSymbol;
+ hipMemcpyFromSymbolAsync;
+ hipMemcpyHtoD;
+ hipMemcpyHtoDAsync;
+ hipMemcpyPeer;
+ hipMemcpyPeerAsync;
+ hipMemcpyToArray;
+ hipMemcpyToSymbol;
+ hipMemcpyToSymbolAsync;
+ hipMemGetAddressRange;
+ hipMemGetInfo;
+ hipMemPtrGetInfo;
+ hipMemset;
+ hipMemset2D;
+ hipMemsetAsync;
+ hipMemsetD8;
+ hipModuleGetFunction;
+ hipModuleGetGlobal;
+ hipModuleLaunchKernel;
+ hipModuleLoad;
+ hipModuleLoadData;
+ hipModuleLoadDataEx;
+ hipModuleUnload;
+ hipPeekAtLastError;
+ hipPointerGetAttributes;
+ hipProfilerStart;
+ hipProfilerStop;
+ hipRuntimeGetVersion;
+ hipSetDevice;
+ hipSetDeviceFlags;
+ hipStreamAddCallback;
+ hipStreamCreate;
+ hipStreamCreateWithFlags;
+ hipStreamDestroy;
+ hipStreamGetFlags;
+ hipStreamQuery;
+ hipStreamSynchronize;
+ hipStreamWaitEvent;
+ __cudaRegisterFatBinary;
+ __cudaRegisterFunction;
+ __cudaRegisterVariable;
+ __cudaUnregisterFatBinary;
+ cudaConfigureCall;
+ cudaSetupArgument;
+ cudaLaunch;
+local:
+ *;
+};
diff --git a/api/hip/hip_hcc.rc b/api/hip/hip_hcc.rc
new file mode 100644
index 0000000000..009dc30c18
--- /dev/null
+++ b/api/hip/hip_hcc.rc
@@ -0,0 +1,75 @@
+#define STR(__macro__) #__macro__
+#define XSTR(__macro__) STR(__macro__)
+
+#if defined(_DEBUG)
+#define DEBUG_ONLY(x) x
+#else
+#define DEBUG_ONLY(x)
+#endif
+
+#define VERSION_PREFIX_MAJOR 2
+#define VERSION_PREFIX_MINOR 0
+
+
+#define APSTUDIO_READONLY_SYMBOLS
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 2 resource.
+//
+#include "winresrc.h"
+#include "utils/versions.hpp"
+
+/////////////////////////////////////////////////////////////////////////////
+#undef APSTUDIO_READONLY_SYMBOLS
+
+/////////////////////////////////////////////////////////////////////////////
+// English (U.S.) resources
+
+#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
+#ifdef _WIN32
+LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
+#pragma code_page(1252)
+#endif //_WIN32
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Version
+//
+
+VS_VERSION_INFO VERSIONINFO
+ FILEVERSION 10,0,AMD_PLATFORM_BUILD_NUMBER,AMD_PLATFORM_REVISION_NUMBER
+ PRODUCTVERSION 10,0,AMD_PLATFORM_BUILD_NUMBER,AMD_PLATFORM_REVISION_NUMBER
+ FILEFLAGSMASK 0x3fL
+#ifdef _DEBUG
+ FILEFLAGS 0x1L
+#else
+ FILEFLAGS 0x0L
+#endif
+ FILEOS 0x40004L
+ FILETYPE 0x2L
+ FILESUBTYPE 0x0L
+BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "040904b0"
+ BEGIN
+ VALUE "Comments", " \0"
+ VALUE "CompanyName", "Advanced Micro Devices Inc.\0"
+ VALUE "FileDescription", AMD_PLATFORM_NAME " OpenCL " XSTR(VERSION_PREFIX_MAJOR) "." XSTR(VERSION_PREFIX_MINOR) " Runtime\0"
+ VALUE "FileVersion", "10.0." XSTR(AMD_PLATFORM_BUILD_NUMBER) "." XSTR(AMD_PLATFORM_REVISION_NUMBER)
+ VALUE "InternalName", "OpenCL"
+ VALUE "LegalCopyright", "Copyright (C) 2011 Advanced Micro Devices Inc.\0"
+ VALUE "OriginalFilename", "OpenCL.dll"
+ VALUE "ProductName", "OpenCL " XSTR(VERSION_PREFIX_MAJOR) "." XSTR(VERSION_PREFIX_MINOR) " " AMD_PLATFORM_INFO "\0"
+ VALUE "ProductVersion", "10.0." XSTR(AMD_PLATFORM_BUILD_NUMBER) "." XSTR(AMD_PLATFORM_REVISION_NUMBER)
+ END
+ END
+ BLOCK "VarFileInfo"
+ BEGIN
+ VALUE "Translation", 0x409, 1200
+ END
+END
+
+#endif // English (U.S.) resources
+/////////////////////////////////////////////////////////////////////////////
diff --git a/api/hip/hip_internal.hpp b/api/hip/hip_internal.hpp
index 7e7b27c143..b1d906d870 100644
--- a/api/hip/hip_internal.hpp
+++ b/api/hip/hip_internal.hpp
@@ -36,8 +36,6 @@ THE SOFTWARE.
#define HIP_INIT_API(...) \
HIP_INIT()
-extern cl_device_id* g_deviceArray;
-extern unsigned g_deviceCnt;
-extern thread_local cl_context g_currentCtx;
+extern amd::Context* g_context;
#endif // HIP_SRC_HIP_INTERNAL_H
diff --git a/api/hip/hip_memory.cpp b/api/hip/hip_memory.cpp
index 6edbe068fe..2dba003ba6 100644
--- a/api/hip/hip_memory.cpp
+++ b/api/hip/hip_memory.cpp
@@ -26,97 +26,94 @@ THE SOFTWARE.
hipError_t hipMalloc(void** ptr, size_t sizeBytes)
{
- HIP_INIT_API(ptr, sizeBytes);
-
- amd::Context* context = as_amd(g_currentCtx);
-
- if (sizeBytes == 0) {
- *ptr = nullptr;
- return hipSuccess;
- }
- else if (!is_valid(context) || !ptr) {
- return hipErrorInvalidValue;
- }
-
- auto deviceHandle = as_amd(g_deviceArray[0]);
- if ((deviceHandle->info().maxMemAllocSize_ < size)) {
- return hipErrorOutOfMemory;
- }
-
- amd::Memory* mem = new (*context) amd::Buffer(*context, 0, sizeBytes);
- if (!mem) {
- return hipErrorOutOfMemory;
- }
-
- if (!mem->create(nullptr)) {
- return hipErrorMemoryAllocation;
- }
-
- *ptr = reinterpret_cast(as_cl(mem));
+ HIP_INIT_API(ptr, sizeBytes);
+ if (sizeBytes == 0) {
+ *ptr = nullptr;
return hipSuccess;
+ }
+ else if (!ptr) {
+ return hipErrorInvalidValue;
+ }
+
+ if (g_context->devices()[0]->info().maxMemAllocSize_ < sizeBytes) {
+ return hipErrorOutOfMemory;
+ }
+
+ amd::Memory* mem = new (*g_context) amd::Buffer(*g_context, 0, sizeBytes);
+ if (!mem) {
+ return hipErrorOutOfMemory;
+ }
+
+ if (!mem->create(nullptr)) {
+ return hipErrorMemoryAllocation;
+ }
+
+ *ptr = reinterpret_cast(as_cl(mem));
+
+ return hipSuccess;
}
hipError_t hipFree(void* ptr)
{
- if (!is_valid(reinterpret_cast(ptr))) {
- return hipErrorInvalidValue;
- }
- as_amd(reinterpret_cast(ptr))->release();
- return hipSuccess;
+ if (!is_valid(reinterpret_cast(ptr))) {
+ return hipErrorInvalidValue;
+ }
+ as_amd(reinterpret_cast(ptr))->release();
+ return hipSuccess;
}
hipError_t hipMemcpy(void* dst, const void* src, size_t sizeBytes, hipMemcpyKind kind)
{
- HIP_INIT_API(dst, src, sizeBytes, kind);
+ HIP_INIT_API(dst, src, sizeBytes, kind);
- amd::Context* context = as_amd(g_currentCtx);
- amd::Device* device = context->devices()[0];
+ amd::Device* device = g_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::HostQueue* queue = new amd::HostQueue(*g_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::Buffer* srcBuffer = as_amd(reinterpret_cast(const_cast(src)))->asBuffer();
+ amd::Buffer* dstBuffer = as_amd(reinterpret_cast(dst))->asBuffer();
- amd::Command* command;
- amd::Command::EventWaitList waitList;
+ amd::Command* command;
+ amd::Command::EventWaitList waitList;
- switch (kind) {
- case hipMemcpyDeviceToHost:
+ switch (kind) {
+ case hipMemcpyDeviceToHost:
command = new amd::ReadMemoryCommand(*queue, CL_COMMAND_READ_BUFFER, waitList,
- srcBuffer, 0, sizeBytes, dst);
+ *srcBuffer, 0, sizeBytes, dst);
break;
- case hipMemcpyHostToDevice:
+ case hipMemcpyHostToDevice:
command = new amd::WriteMemoryCommand(*queue, CL_COMMAND_WRITE_BUFFER, waitList,
- dstBuffer, 0, sizeBytes, src);
+ *dstBuffer, 0, sizeBytes, src);
break;
- default:
- assert(!"Shouldn't reach here");
+ default:
+ assert(!"Shouldn't reach here");
break;
- }
- if (!command) {
- return hipErrorOutOfMemory;
- }
+ }
+ if (!command) {
+ return hipErrorOutOfMemory;
+ }
- // Make sure we have memory for the command execution
- if (CL_SUCCESS != command->validateMemory()) {
- delete command;
- return hipErrorMemoryAllocation;
- }
+// FIXME: virtualize MemoryCommand::validateMemory()
+#if 0
+ // Make sure we have memory for the command execution
+ if (CL_SUCCESS != command->validateMemory()) {
+ delete command;
+ return hipErrorMemoryAllocation;
+ }
+#endif
+ command->enqueue();
+ command->awaitCompletion();
+ command->release();
- command->enqueue();
- command->awaitCompletion();
- command->release();
+ queue->release();
- queue->release();
-
- return hipSuccess;
+ return hipSuccess;
}
diff --git a/api/hip/hip_module.cpp b/api/hip/hip_module.cpp
new file mode 100644
index 0000000000..dde0c4e790
--- /dev/null
+++ b/api/hip/hip_module.cpp
@@ -0,0 +1,144 @@
+/*
+Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#include
+#include
+
+#include "hip_internal.hpp"
+#include "platform/program.hpp"
+
+static uint64_t ElfSize(const void *emi)
+{
+ const Elf64_Ehdr *ehdr = (const Elf64_Ehdr*)emi;
+ const Elf64_Shdr *shdr = (const Elf64_Shdr*)((char*)emi + ehdr->e_shoff);
+
+ uint64_t max_offset = ehdr->e_shoff;
+ uint64_t total_size = max_offset + ehdr->e_shentsize * ehdr->e_shnum;
+
+ for (uint16_t i=0; i < ehdr->e_shnum; ++i){
+ uint64_t cur_offset = static_cast(shdr[i].sh_offset);
+ if (max_offset < cur_offset) {
+ max_offset = cur_offset;
+ total_size = max_offset;
+ if(SHT_NOBITS != shdr[i].sh_type) {
+ total_size += static_cast(shdr[i].sh_size);
+ }
+ }
+ }
+ return total_size;
+}
+
+hipError_t hipModuleLoadData(hipModule_t *module, const void *image)
+{
+ HIP_INIT_API(module, image);
+
+ amd::Program* program = new amd::Program(*g_context);
+ if (program == NULL) {
+ return hipErrorOutOfMemory;
+ }
+
+ if (CL_SUCCESS != program->addDeviceProgram(*g_context->devices()[0], image, ElfSize(image)) ||
+ CL_SUCCESS != program->build(g_context->devices(), nullptr, nullptr, nullptr)) {
+ return hipErrorUnknown;
+ }
+
+ *module = reinterpret_cast(as_cl(program));
+
+ return hipSuccess;
+}
+
+hipError_t hipModuleGetFunction(hipFunction_t *hfunc, hipModule_t hmod, const char *name)
+{
+ HIP_INIT_API(hfunc, hmod, name);
+
+ amd::Program* program = as_amd(reinterpret_cast(hmod));
+
+ const amd::Symbol* symbol = program->findSymbol(name);
+ if (!symbol) {
+ return hipErrorNotFound;
+ }
+
+ amd::Kernel* kernel = new amd::Kernel(*program, *symbol, name);
+ if (!kernel) {
+ return hipErrorOutOfMemory;
+ }
+
+ *hfunc = reinterpret_cast(as_cl(kernel));
+
+ return hipSuccess;
+}
+
+hipError_t hipModuleLaunchKernel(hipFunction_t f,
+ uint32_t gridDimX, uint32_t gridDimY, uint32_t gridDimZ,
+ uint32_t blockDimX, uint32_t blockDimY, uint32_t blockDimZ,
+ uint32_t sharedMemBytes, hipStream_t hStream,
+ void **kernelParams, void **extra)
+{
+ HIP_INIT_API(f, gridDimX, gridDimY, gridDimZ,
+ blockDimX, blockDimY, blockDimZ,
+ sharedMemBytes, hStream,
+ kernelParams, extra);
+
+ amd::Kernel* kernel = as_amd(reinterpret_cast(f));
+ amd::Device* device = g_context->devices()[0];
+
+ amd::HostQueue* queue = new amd::HostQueue(*g_context, *device, 0,
+ amd::CommandQueue::RealTimeDisabled,
+ amd::CommandQueue::Priority::Normal);
+ if (!queue) {
+ return hipErrorOutOfMemory;
+ }
+
+ size_t globalWorkOffset[3] = {0};
+ size_t globalWorkSize[3] = { gridDimX, gridDimY, gridDimZ };
+ size_t localWorkSize[3] = { blockDimX, blockDimY, blockDimZ };
+ amd::NDRangeContainer ndrange(3, globalWorkOffset, globalWorkSize, localWorkSize);
+ amd::Command::EventWaitList waitList;
+
+ assert(!kernelParams && extra && "check this code");
+ const amd::KernelSignature& signature = kernel->signature();
+ for (size_t i = 0; i < signature.numParameters(); ++i) {
+ const amd::KernelParameterDescriptor& desc = signature.at(i);
+ kernel->parameters().set(i, desc.size_, reinterpret_cast(extra[1]) + desc.offset_);
+ }
+
+ amd::NDRangeKernelCommand* command = new amd::NDRangeKernelCommand(*queue, waitList, *kernel, ndrange);
+ 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;
+}
+
+
diff --git a/api/hip/hip_platform.cpp b/api/hip/hip_platform.cpp
new file mode 100644
index 0000000000..aed3342483
--- /dev/null
+++ b/api/hip/hip_platform.cpp
@@ -0,0 +1,193 @@
+/*
+Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#include
+
+#include "hip_internal.hpp"
+#include "platform/program.hpp"
+#include "platform/runtime.hpp"
+
+constexpr unsigned __cudaFatMAGIC = 0x1ee55a01;
+constexpr unsigned __cudaFatMAGIC2 = 0x466243b1;
+constexpr unsigned __cudaFatMAGIC3 = 0xba55ed50;
+
+struct __CudaFatBinaryWrapper {
+ unsigned int magic;
+ unsigned int version;
+ void* binary;
+ void* dummy1;
+};
+
+struct __CudaFatBinaryHeader {
+ unsigned int magic;
+ unsigned short version;
+ unsigned short headerSize;
+ unsigned long long int fatSize;
+};
+
+struct __CudaPartHeader{
+ unsigned short type;
+ unsigned short dummy1;
+ unsigned int headerSize;
+ unsigned long long int partSize;
+ unsigned long long int dummy2;
+ unsigned int dummy3;
+ unsigned int subarch;
+};
+
+extern "C" hipModule_t __cudaRegisterFatBinary(void* bundle)
+{
+ if (!amd::Runtime::initialized()) { // FIXME: fix initialization
+ hipInit(0);
+ }
+
+ amd::Program* program = new amd::Program(*g_context);
+ if (!program) return nullptr;
+
+ struct __CudaFatBinaryWrapper* fbwrapper = (struct __CudaFatBinaryWrapper*)bundle;
+ if (fbwrapper->magic != __cudaFatMAGIC2 || fbwrapper->version != 1) {
+ return nullptr;
+ }
+ struct __CudaFatBinaryHeader* fbheader = (struct __CudaFatBinaryHeader*)fbwrapper->binary;
+ if (fbheader->magic != __cudaFatMAGIC3 || fbheader->version != 1) {
+ return nullptr;
+ }
+ struct __CudaPartHeader* pheader = (struct __CudaPartHeader*)(
+ (uintptr_t)fbheader + fbheader->headerSize);
+ struct __CudaPartHeader* end = (struct __CudaPartHeader*)(
+ (uintptr_t)pheader + fbheader->fatSize);
+
+ while (pheader < end) {
+ if (true/*pheader->subarch == match a device in the context*/) {
+ void *image = (void*)((uintptr_t)pheader + pheader->headerSize);
+ size_t size = pheader->partSize;
+ if (CL_SUCCESS != program->addDeviceProgram(*g_context->devices()[0], image, size) ||
+ CL_SUCCESS != program->build(g_context->devices(), nullptr, nullptr, nullptr)) {
+ return nullptr;
+ }
+ break;
+ }
+ pheader = (struct __CudaPartHeader*)(
+ (uintptr_t)pheader + pheader->headerSize + pheader->partSize);
+ }
+
+ return reinterpret_cast(as_cl(program));
+}
+
+std::map g_functions;
+
+
+extern "C" void __cudaRegisterFunction(
+ hipModule_t module,
+ const void* hostFunction,
+ char* deviceFunction,
+ const char* deviceName,
+ unsigned int threadLimit,
+ uint3* tid,
+ uint3* bid,
+ dim3* blockDim,
+ dim3* gridDim,
+ int* wSize)
+{
+ amd::Program* program = as_amd(reinterpret_cast(module));
+
+ const amd::Symbol* symbol = program->findSymbol(deviceName);
+ if (!symbol) return;
+
+ amd::Kernel* kernel = new amd::Kernel(*program, *symbol, deviceName);
+ if (!kernel) return;
+
+ // FIXME: not thread safe
+ g_functions.insert(std::make_pair(hostFunction, reinterpret_cast(as_cl(kernel))));
+}
+
+extern "C" void __cudaRegisterVar(
+ hipModule_t module,
+ char* hostVar,
+ char* deviceVar,
+ const char* deviceName,
+ int ext,
+ int size,
+ int constant,
+ int global)
+{
+}
+
+extern "C" void __cudaUnregisterFatBinary(
+ hipModule_t module
+)
+{
+}
+
+dim3 g_gridDim; // FIXME: place in execution stack
+dim3 g_blockDim; // FIXME: place in execution stack
+size_t g_sharedMem; // FIXME: place in execution stack
+hipStream_t g_stream; // FIXME: place in execution stack
+
+extern "C" hipError_t cudaConfigureCall(
+ dim3 gridDim,
+ dim3 blockDim,
+ size_t sharedMem,
+ hipStream_t stream)
+{
+ // FIXME: should push and new entry on the execution stack
+
+ g_gridDim = gridDim;
+ g_blockDim = blockDim;
+ g_sharedMem = sharedMem;
+ g_stream = stream;
+
+ return hipSuccess;
+}
+
+char* g_arguments[1024]; // FIXME: needs to grow
+
+extern "C" hipError_t cudaSetupArgument(
+ const void *arg,
+ size_t size,
+ size_t offset)
+{
+ // FIXME: should modify the top of the execution stack
+
+ ::memcpy(g_arguments + offset, arg, size);
+ return hipSuccess;
+}
+
+extern "C" hipError_t cudaLaunch(const void *hostFunction)
+{
+ std::map::iterator it;
+ if ((it = g_functions.find(hostFunction)) == g_functions.end())
+ return hipErrorUnknown;
+
+ // FIXME: should pop an entry from the execution stack
+
+ void *extra[] = {
+ HIP_LAUNCH_PARAM_BUFFER_POINTER, g_arguments,
+ HIP_LAUNCH_PARAM_BUFFER_SIZE, 0 /* FIXME: not needed, but should be correct*/,
+ HIP_LAUNCH_PARAM_END
+ };
+
+ return hipModuleLaunchKernel(it->second,
+ g_gridDim.x, g_gridDim.y, g_gridDim.z,
+ g_blockDim.x, g_blockDim.y, g_blockDim.z,
+ g_sharedMem, g_stream, nullptr, extra);
+}
From d8a344113f444c595fb543c9f9ab9d75e43f0513 Mon Sep 17 00:00:00 2001
From: foreman
Date: Fri, 2 Mar 2018 17:55:48 -0500
Subject: [PATCH 005/282] P4 to Git Change 1522211 by
lmoriche@lmoriche_opencl_dev2 on 2018/03/02 17:41:47
SWDEV-145570 - [HIP] - Hip Rearchitecture
- Rename cuda* launch functions -> hip*
- Add more function prototypes to compile the HIP tests
Affected files ...
... //depot/stg/opencl/drivers/opencl/api/hip/hip_context.cpp#2 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_device.cpp#3 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_hcc.def.in#2 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_hcc.map.in#2 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_memory.cpp#4 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_module.cpp#2 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_platform.cpp#2 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_stream.cpp#1 add
---
api/hip/hip_context.cpp | 13 +++++++
api/hip/hip_device.cpp | 19 ++++++++++
api/hip/hip_hcc.def.in | 14 ++++----
api/hip/hip_hcc.map.in | 14 ++++----
api/hip/hip_memory.cpp | 56 ++++++++++++++++++++++++++---
api/hip/hip_module.cpp | 19 ++++++++++
api/hip/hip_platform.cpp | 14 ++++----
api/hip/hip_stream.cpp | 76 ++++++++++++++++++++++++++++++++++++++++
8 files changed, 199 insertions(+), 26 deletions(-)
create mode 100644 api/hip/hip_stream.cpp
diff --git a/api/hip/hip_context.cpp b/api/hip/hip_context.cpp
index 0e6ff2116a..78e65e99c5 100644
--- a/api/hip/hip_context.cpp
+++ b/api/hip/hip_context.cpp
@@ -24,6 +24,7 @@ THE SOFTWARE.
#include "hip_internal.hpp"
#include "platform/runtime.hpp"
+#include "utils/versions.hpp"
amd::Context* g_context = nullptr;
@@ -56,3 +57,15 @@ hipError_t hipCtxCreate(hipCtx_t *ctx, unsigned int flags, hipDevice_t device)
return hipSuccess;
}
+hipError_t hipRuntimeGetVersion(int *runtimeVersion)
+{
+ HIP_INIT_API(runtimeVersion);
+
+ if (!runtimeVersion) {
+ return hipErrorInvalidValue;
+ }
+
+ *runtimeVersion = AMD_PLATFORM_BUILD_NUMBER;
+
+ return hipSuccess;
+}
diff --git a/api/hip/hip_device.cpp b/api/hip/hip_device.cpp
index 7296eabb17..b5da0c34b5 100644
--- a/api/hip/hip_device.cpp
+++ b/api/hip/hip_device.cpp
@@ -358,6 +358,25 @@ hipError_t hipDeviceGetPCIBusId (char *pciBusId,int len, int device) {
return hipSuccess;
}
+hipError_t hipSetDevice(int deviceId)
+{
+ HIP_INIT_API(deviceId);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipDeviceReset(void)
+{
+ HIP_INIT_API();
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+
hipError_t hipDeviceSynchronize(void)
{
// FIXME: should wait on all streams
diff --git a/api/hip/hip_hcc.def.in b/api/hip/hip_hcc.def.in
index 6b4793ea94..10113dc2bd 100644
--- a/api/hip/hip_hcc.def.in
+++ b/api/hip/hip_hcc.def.in
@@ -120,10 +120,10 @@ hipStreamGetFlags
hipStreamQuery
hipStreamSynchronize
hipStreamWaitEvent
-__cudaRegisterFatBinary
-__cudaRegisterFunction
-__cudaRegisterVariable
-__cudaUnregisterFatBinary
-cudaConfigureCall
-cudaSetupArgument
-cudaLaunch
+__hipRegisterFatBinary
+__hipRegisterFunction
+__hipRegisterVariable
+__hipUnregisterFatBinary
+hipConfigureCall
+hipSetupArgument
+hipLaunchByPtr
diff --git a/api/hip/hip_hcc.map.in b/api/hip/hip_hcc.map.in
index e4025606bc..a4153ee56f 100644
--- a/api/hip/hip_hcc.map.in
+++ b/api/hip/hip_hcc.map.in
@@ -121,13 +121,13 @@ global:
hipStreamQuery;
hipStreamSynchronize;
hipStreamWaitEvent;
- __cudaRegisterFatBinary;
- __cudaRegisterFunction;
- __cudaRegisterVariable;
- __cudaUnregisterFatBinary;
- cudaConfigureCall;
- cudaSetupArgument;
- cudaLaunch;
+ __hipRegisterFatBinary;
+ __hipRegisterFunction;
+ __hipRegisterVariable;
+ __hipUnregisterFatBinary;
+ hipConfigureCall;
+ hipSetupArgument;
+ hipLaunchByPtr;
local:
*;
};
diff --git a/api/hip/hip_memory.cpp b/api/hip/hip_memory.cpp
index 2dba003ba6..0911f61e4c 100644
--- a/api/hip/hip_memory.cpp
+++ b/api/hip/hip_memory.cpp
@@ -54,6 +54,15 @@ hipError_t hipMalloc(void** ptr, size_t sizeBytes)
return hipSuccess;
}
+hipError_t hipHostMalloc(void** ptr, size_t sizeBytes, unsigned int flags)
+{
+ HIP_INIT_API(ptr, sizeBytes, flags);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
hipError_t hipFree(void* ptr)
{
if (!is_valid(reinterpret_cast(ptr))) {
@@ -63,6 +72,20 @@ hipError_t hipFree(void* ptr)
return hipSuccess;
}
+hipError_t hipMemcpyAsync(void* dst,
+ const void* src,
+ size_t sizeBytes,
+ hipMemcpyKind kind,
+ hipStream_t stream)
+{
+ HIP_INIT_API(dst, src, sizeBytes, kind, stream);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+
hipError_t hipMemcpy(void* dst, const void* src, size_t sizeBytes, hipMemcpyKind kind)
{
HIP_INIT_API(dst, src, sizeBytes, kind);
@@ -76,20 +99,17 @@ hipError_t hipMemcpy(void* dst, const void* src, size_t sizeBytes, hipMemcpyKind
return hipErrorOutOfMemory;
}
- amd::Buffer* srcBuffer = as_amd(reinterpret_cast(const_cast(src)))->asBuffer();
- amd::Buffer* dstBuffer = as_amd(reinterpret_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);
+ *as_amd(reinterpret_cast(const_cast(src)))->asBuffer(), 0, sizeBytes, dst);
break;
case hipMemcpyHostToDevice:
command = new amd::WriteMemoryCommand(*queue, CL_COMMAND_WRITE_BUFFER, waitList,
- *dstBuffer, 0, sizeBytes, src);
+ *as_amd(reinterpret_cast(dst))->asBuffer(), 0, sizeBytes, src);
break;
default:
assert(!"Shouldn't reach here");
@@ -117,3 +137,29 @@ hipError_t hipMemcpy(void* dst, const void* src, size_t sizeBytes, hipMemcpyKind
return hipSuccess;
}
+hipError_t hipMemsetAsync(void* dst, int value, size_t sizeBytes, hipStream_t stream )
+{
+ HIP_INIT_API(dst, value, sizeBytes, stream);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipMemset(void* dst, int value, size_t sizeBytes)
+{
+ HIP_INIT_API(dst, value, sizeBytes);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipMemPtrGetInfo(void *ptr, size_t *size)
+{
+ HIP_INIT_API(ptr, size);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
diff --git a/api/hip/hip_module.cpp b/api/hip/hip_module.cpp
index dde0c4e790..fd7729c6e5 100644
--- a/api/hip/hip_module.cpp
+++ b/api/hip/hip_module.cpp
@@ -47,6 +47,25 @@ static uint64_t ElfSize(const void *emi)
return total_size;
}
+hipError_t hipModuleLoad(hipModule_t *module, const char *fname)
+{
+ HIP_INIT_API(module, fname);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+
+hipError_t hipModuleUnload(hipModule_t hmod)
+{
+ HIP_INIT_API(hmod);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
hipError_t hipModuleLoadData(hipModule_t *module, const void *image)
{
HIP_INIT_API(module, image);
diff --git a/api/hip/hip_platform.cpp b/api/hip/hip_platform.cpp
index aed3342483..0cc6a3b1c2 100644
--- a/api/hip/hip_platform.cpp
+++ b/api/hip/hip_platform.cpp
@@ -54,7 +54,7 @@ struct __CudaPartHeader{
unsigned int subarch;
};
-extern "C" hipModule_t __cudaRegisterFatBinary(void* bundle)
+extern "C" hipModule_t __hipRegisterFatBinary(void* bundle)
{
if (!amd::Runtime::initialized()) { // FIXME: fix initialization
hipInit(0);
@@ -96,7 +96,7 @@ extern "C" hipModule_t __cudaRegisterFatBinary(void* bundle)
std::map g_functions;
-extern "C" void __cudaRegisterFunction(
+extern "C" void __hipRegisterFunction(
hipModule_t module,
const void* hostFunction,
char* deviceFunction,
@@ -120,7 +120,7 @@ extern "C" void __cudaRegisterFunction(
g_functions.insert(std::make_pair(hostFunction, reinterpret_cast(as_cl(kernel))));
}
-extern "C" void __cudaRegisterVar(
+extern "C" void __hipRegisterVar(
hipModule_t module,
char* hostVar,
char* deviceVar,
@@ -132,7 +132,7 @@ extern "C" void __cudaRegisterVar(
{
}
-extern "C" void __cudaUnregisterFatBinary(
+extern "C" void __hipUnregisterFatBinary(
hipModule_t module
)
{
@@ -143,7 +143,7 @@ dim3 g_blockDim; // FIXME: place in execution stack
size_t g_sharedMem; // FIXME: place in execution stack
hipStream_t g_stream; // FIXME: place in execution stack
-extern "C" hipError_t cudaConfigureCall(
+extern "C" hipError_t hipConfigureCall(
dim3 gridDim,
dim3 blockDim,
size_t sharedMem,
@@ -161,7 +161,7 @@ extern "C" hipError_t cudaConfigureCall(
char* g_arguments[1024]; // FIXME: needs to grow
-extern "C" hipError_t cudaSetupArgument(
+extern "C" hipError_t hipSetupArgument(
const void *arg,
size_t size,
size_t offset)
@@ -172,7 +172,7 @@ extern "C" hipError_t cudaSetupArgument(
return hipSuccess;
}
-extern "C" hipError_t cudaLaunch(const void *hostFunction)
+extern "C" hipError_t hipLaunchByPtr(const void *hostFunction)
{
std::map::iterator it;
if ((it = g_functions.find(hostFunction)) == g_functions.end())
diff --git a/api/hip/hip_stream.cpp b/api/hip/hip_stream.cpp
new file mode 100644
index 0000000000..efecb5174d
--- /dev/null
+++ b/api/hip/hip_stream.cpp
@@ -0,0 +1,76 @@
+/*
+Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#include
+
+#include "hip_internal.hpp"
+
+hipError_t hipStreamCreateWithFlags(hipStream_t *stream, unsigned int flags)
+{
+ HIP_INIT_API(stream, flags);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+
+hipError_t hipStreamCreate(hipStream_t *stream)
+{
+ HIP_INIT_API(stream);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+
+hipError_t hipStreamGetFlags(hipStream_t stream, unsigned int *flags)
+{
+ HIP_INIT_API(stream, flags);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+
+hipError_t hipStreamSynchronize(hipStream_t stream)
+{
+ HIP_INIT_API(stream);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+
+hipError_t hipStreamDestroy(hipStream_t stream)
+{
+ HIP_INIT_API(stream);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+
From cd4f8ccac976c9e3a108466ca1aa5df57d5966cb Mon Sep 17 00:00:00 2001
From: foreman
Date: Sat, 3 Mar 2018 21:02:59 -0500
Subject: [PATCH 006/282] P4 to Git Change 1522302 by
skudchad@skudchad_test2_win_opencl on 2018/03/03 20:41:25
SWDEV-145570 - [HIP] - Hip Rearchitecture
- Implemented most of device* functions
ReviewBoardURL = http://ocltc.amd.com/reviews/r/14340/diff/
Affected files ...
... //depot/stg/opencl/drivers/opencl/api/hip/hip_device.cpp#4 edit
---
api/hip/hip_device.cpp | 223 +++++++++++++++++++++++++++++++++++++----
1 file changed, 201 insertions(+), 22 deletions(-)
diff --git a/api/hip/hip_device.cpp b/api/hip/hip_device.cpp
index b5da0c34b5..c719f30122 100644
--- a/api/hip/hip_device.cpp
+++ b/api/hip/hip_device.cpp
@@ -28,7 +28,7 @@ hipError_t hipGetDevice(int *deviceId) {
HIP_INIT_API(deviceId);
- if (deviceId != NULL) {
+ if (deviceId != nullptr) {
// this needs to return default device. For now return 0 always
*deviceId = 0;
} else {
@@ -55,7 +55,7 @@ hipError_t hipGetDeviceCount(int* count) {
HIP_INIT_API(count);
- if (count == NULL) {
+ if (count == nullptr) {
return hipErrorInvalidValue;
}
@@ -170,7 +170,7 @@ hipError_t hipGetDeviceProperties(hipDeviceProp_t* props, int device) {
HIP_INIT_API(props, device);
- if (props == NULL) {
+ if (props == nullptr) {
return hipErrorInvalidValue;
}
@@ -247,7 +247,7 @@ hipError_t hipDeviceSetCacheConfig(hipFuncCache_t cacheConfig) {
hipError_t hipDeviceGetCacheConfig(hipFuncCache_t *cacheConfig) {
HIP_INIT_API(cacheConfig);
- if(cacheConfig == NULL) {
+ if(cacheConfig == nullptr) {
return hipErrorInvalidValue;
}
@@ -269,16 +269,26 @@ hipError_t hipDeviceGetLimit (size_t *pValue, hipLimit_t limit) {
HIP_INIT_API(pValue, limit);
- assert(0 && "Unimplemented");
+ auto* deviceHandle = g_context->devices()[0];
+ const auto& info = deviceHandle->info();
+
+ if(pValue == nullptr) {
+ return hipErrorInvalidValue;
+ }
+ if(limit == hipLimitMallocHeapSize) {
+ *pValue = info.globalMemSize_;
+ return hipSuccess;
+ } else {
+ return hipErrorUnsupportedLimit;
+ }
- return hipSuccess;
}
hipError_t hipFuncSetCacheConfig (const void* func, hipFuncCache_t cacheConfig) {
HIP_INIT_API(cacheConfig);
- assert(0 && "Not supported");
+ // No way to set cache config yet.
return hipSuccess;
}
@@ -287,7 +297,7 @@ hipError_t hipDeviceSetSharedMemConfig (hipSharedMemConfig config) {
HIP_INIT_API(config);
- assert(0 && "Not Supported");
+ // No way to set cache config yet.
return hipSuccess;
}
@@ -296,7 +306,7 @@ hipError_t hipDeviceGetSharedMemConfig (hipSharedMemConfig *pConfig) {
HIP_INIT_API(pConfig);
- assert(0 && "Not supported");
+ *pConfig = hipSharedMemBankSizeFourByte;
return hipSuccess;
}
@@ -306,54 +316,223 @@ hipError_t hipChooseDevice(int* device, const hipDeviceProp_t* properties) {
HIP_INIT_API(device, properties);
- assert(0 && "Unimplemented");
+ if (device == nullptr || properties == nullptr) {
+ return hipErrorInvalidValue;
+ }
+
+ *device = 0;
+ cl_uint maxMatchedCount = 0;
+
+ for (cl_uint i = 0; i< g_context->devices().size(); ++i) {
+ hipDeviceProp_t currentProp = {0};
+ cl_uint validPropCount = 0;
+ cl_uint matchedCount = 0;
+ hipError_t err = hipGetDeviceProperties(¤tProp, i);
+ if (properties->major != 0) {
+ validPropCount++;
+ if(currentProp.major >= properties->major) {
+ matchedCount++;
+ }
+ }
+ if (properties->minor != 0) {
+ validPropCount++;
+ if(currentProp.minor >= properties->minor) {
+ matchedCount++;
+ }
+ }
+ if(properties->totalGlobalMem != 0) {
+ validPropCount++;
+ if(currentProp.totalGlobalMem >= properties->totalGlobalMem) {
+ matchedCount++;
+ }
+ }
+ if(properties->sharedMemPerBlock != 0) {
+ validPropCount++;
+ if(currentProp.sharedMemPerBlock >= properties->sharedMemPerBlock) {
+ matchedCount++;
+ }
+ }
+ if(properties->maxThreadsPerBlock != 0) {
+ validPropCount++;
+ if(currentProp.maxThreadsPerBlock >= properties->maxThreadsPerBlock ) {
+ matchedCount++;
+ }
+ }
+ if(properties->totalConstMem != 0) {
+ validPropCount++;
+ if(currentProp.totalConstMem >= properties->totalConstMem ) {
+ matchedCount++;
+ }
+ }
+ if(properties->multiProcessorCount != 0) {
+ validPropCount++;
+ if(currentProp.multiProcessorCount >=
+ properties->multiProcessorCount ) {
+ matchedCount++;
+ }
+ }
+ if(properties->maxThreadsPerMultiProcessor != 0) {
+ validPropCount++;
+ if(currentProp.maxThreadsPerMultiProcessor >=
+ properties->maxThreadsPerMultiProcessor ) {
+ matchedCount++;
+ }
+ }
+ if(properties->memoryClockRate != 0) {
+ validPropCount++;
+ if(currentProp.memoryClockRate >= properties->memoryClockRate ) {
+ matchedCount++;
+ }
+ }
+ if(properties->memoryBusWidth != 0) {
+ validPropCount++;
+ if(currentProp.memoryBusWidth >= properties->memoryBusWidth ) {
+ matchedCount++;
+ }
+ }
+ if(properties->l2CacheSize != 0) {
+ validPropCount++;
+ if(currentProp.l2CacheSize >= properties->l2CacheSize ) {
+ matchedCount++;
+ }
+ }
+ if(properties->regsPerBlock != 0) {
+ validPropCount++;
+ if(currentProp.regsPerBlock >= properties->regsPerBlock ) {
+ matchedCount++;
+ }
+ }
+ if(properties->maxSharedMemoryPerMultiProcessor != 0) {
+ validPropCount++;
+ if(currentProp.maxSharedMemoryPerMultiProcessor >=
+ properties->maxSharedMemoryPerMultiProcessor ) {
+ matchedCount++;
+ }
+ }
+ if(properties->warpSize != 0) {
+ validPropCount++;
+ if(currentProp.warpSize >= properties->warpSize ) {
+ matchedCount++;
+ }
+ }
+ if(validPropCount == matchedCount) {
+ *device = matchedCount > maxMatchedCount ? i : *device;
+ maxMatchedCount = std::max(matchedCount, maxMatchedCount);
+ }
+ }
return hipSuccess;
}
-hipError_t hipDeviceGetByPCIBusId (int* device, const char* pciBusId) {
+hipError_t hipDeviceGetByPCIBusId (int* device, const char* pciBusIdstr) {
- HIP_INIT_API(device,pciBusId);
+ HIP_INIT_API(device, pciBusIdstr);
- assert(0 && "Unimplemented");
+ if (device == nullptr || pciBusIdstr == nullptr) {
+ return hipErrorInvalidValue;
+ }
+
+ int pciBusID = -1;
+ int pciDeviceID = -1;
+ int pciDomainID = -1;
+
+ if (sscanf (pciBusIdstr, "%04x:%02x:%02x", &pciDomainID, &pciBusID, &pciDeviceID) == 0x3) {
+ for (cl_uint i = 0; i < g_context->devices().size(); i++) {
+ auto* deviceHandle = g_context->devices()[i];
+ auto& info = deviceHandle->info();
+
+ if (pciBusID == info.deviceTopology_.pcie.bus) {
+ *device = i;
+ break;
+ }
+ }
+ }
return hipSuccess;
}
-hipError_t hipDeviceTotalMem (size_t *bytes,hipDevice_t device) {
+hipError_t hipDeviceTotalMem (size_t *bytes, hipDevice_t device) {
HIP_INIT_API(bytes, device);
- assert(0 && "Unimplemented");
+ if (device < 0 || device > (cl_int)g_context->devices().size()) {
+ return hipErrorInvalidDevice;
+ }
+
+ if (bytes == nullptr) {
+ return hipErrorInvalidValue;
+ }
+
+ auto* deviceHandle = g_context->devices()[device];
+ const auto& info = deviceHandle->info();
+
+ *bytes = info.globalMemSize_;
return hipSuccess;
}
hipError_t hipDeviceComputeCapability(int *major, int *minor, hipDevice_t device) {
- HIP_INIT_API(major,minor, device);
+ HIP_INIT_API(major, minor, device);
- assert(0 && "Unimplemented");
+ if (device < 0 || device > (cl_int)g_context->devices().size()) {
+ return hipErrorInvalidDevice;
+ }
+
+ if (major == nullptr || minor == nullptr) {
+ return hipErrorInvalidValue;
+ }
+
+ auto* deviceHandle = g_context->devices()[device];
+ const auto& info = deviceHandle->info();
+ *major = info.gfxipVersion_ / 100;
+ *minor = info.gfxipVersion_ % 100;
return hipSuccess;
}
-hipError_t hipDeviceGetName(char *name,int len, hipDevice_t device) {
+hipError_t hipDeviceGetName(char *name, int len, hipDevice_t device) {
- HIP_INIT_API((void*)name,len, device);
+ HIP_INIT_API((void*)name, len, device);
- assert(0 && "Unimplemented");
+ if (device < 0 || device > (cl_int)g_context->devices().size()) {
+ return hipErrorInvalidDevice;
+ }
+
+ if (name == nullptr) {
+ return hipErrorInvalidValue;
+ }
+
+ auto* deviceHandle = g_context->devices()[device];
+ const auto& info = deviceHandle->info();
+
+ len = ((cl_uint)len < ::strlen(info.boardName_)) ? len : 128;
+ ::strncpy(name, info.boardName_, len);
return hipSuccess;
}
-hipError_t hipDeviceGetPCIBusId (char *pciBusId,int len, int device) {
+hipError_t hipDeviceGetPCIBusId (char *pciBusId, int len, int device) {
HIP_INIT_API((void*)pciBusId, len, device);
- assert(0 && "Unimplemented");
+ if (device < 0 || device > (cl_int)g_context->devices().size()) {
+ return hipErrorInvalidDevice;
+ }
+
+ if (pciBusId == nullptr || len < 0) {
+ return hipErrorInvalidValue;
+ }
+
+ auto* deviceHandle = g_context->devices()[device];
+ const auto& info = deviceHandle->info();
+ snprintf (pciBusId, len, "%04x:%02x:%02x.0",
+ info.deviceTopology_.pcie.function,
+ info.deviceTopology_.pcie.bus,
+ info.deviceTopology_.pcie.device);
+
return hipSuccess;
}
From f99db275fe935b46bc6a87467a05903fa3e84e37 Mon Sep 17 00:00:00 2001
From: foreman
Date: Wed, 7 Mar 2018 20:03:36 -0500
Subject: [PATCH 007/282] P4 to Git Change 1524135 by
cpaquot@cpaquot-ocl-lc-lnx on 2018/03/07 19:52:00
SWDEV-145570 - [HIP] Hip Rearchitecture
Implemented hipHostAlloc
Affected files ...
... //depot/stg/opencl/drivers/opencl/api/hip/hip_memory.cpp#5 edit
---
api/hip/hip_memory.cpp | 23 +++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/api/hip/hip_memory.cpp b/api/hip/hip_memory.cpp
index 0911f61e4c..ddebc8623c 100644
--- a/api/hip/hip_memory.cpp
+++ b/api/hip/hip_memory.cpp
@@ -58,13 +58,32 @@ hipError_t hipHostMalloc(void** ptr, size_t sizeBytes, unsigned int flags)
{
HIP_INIT_API(ptr, sizeBytes, flags);
- assert(0 && "Unimplemented");
+ if (sizeBytes == 0) {
+ *ptr = nullptr;
+ return hipSuccess;
+ }
+ else if (!ptr) {
+ return hipErrorInvalidValue;
+ }
- return hipErrorUnknown;
+ if (g_context->devices()[0]->info().maxMemAllocSize_ < sizeBytes) {
+ return hipErrorOutOfMemory;
+ }
+
+ *ptr = amd::SvmBuffer::malloc(*g_context, 0, sizeBytes, g_context->devices()[0]->info().memBaseAddrAlign_);
+ if (!*ptr) {
+ return hipErrorOutOfMemory;
+ }
+
+ return hipSuccess;
}
hipError_t hipFree(void* ptr)
{
+ if (amd::SvmBuffer::malloced(ptr)) {
+ amd::SvmBuffer::free(*g_context, ptr);
+ return hipSuccess;
+ }
if (!is_valid(reinterpret_cast(ptr))) {
return hipErrorInvalidValue;
}
From 22aeb7f4f3fc9f7f0b79451a3301619d0129fe3b Mon Sep 17 00:00:00 2001
From: foreman
Date: Tue, 13 Mar 2018 12:33:01 -0400
Subject: [PATCH 008/282] P4 to Git Change 1526407 by
cpaquot@cpaquot-ocl-lc-lnx on 2018/03/13 12:24:51
SWDEV-145570 - [HIP] Separate device runtime and driver APIs
Affected files ...
... //depot/stg/opencl/drivers/opencl/api/hip/hip_device.cpp#5 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_device_runtime.cpp#1 add
---
api/hip/hip_device.cpp | 455 ----------------------------
api/hip/hip_device_runtime.cpp | 533 +++++++++++++++++++++++++++++++++
2 files changed, 533 insertions(+), 455 deletions(-)
create mode 100644 api/hip/hip_device_runtime.cpp
diff --git a/api/hip/hip_device.cpp b/api/hip/hip_device.cpp
index c719f30122..ae9cba963d 100644
--- a/api/hip/hip_device.cpp
+++ b/api/hip/hip_device.cpp
@@ -24,20 +24,6 @@ THE SOFTWARE.
#include "hip_internal.hpp"
-hipError_t hipGetDevice(int *deviceId) {
-
- HIP_INIT_API(deviceId);
-
- if (deviceId != nullptr) {
- // this needs to return default device. For now return 0 always
- *deviceId = 0;
- } else {
- return hipErrorInvalidValue;
- }
-
- return hipSuccess;
-}
-
hipError_t hipDeviceGet(hipDevice_t *device, int deviceId)
{
HIP_INIT_API(device, deviceId);
@@ -51,239 +37,6 @@ hipError_t hipDeviceGet(hipDevice_t *device, int deviceId)
return hipSuccess;
};
-hipError_t hipGetDeviceCount(int* count) {
-
- HIP_INIT_API(count);
-
- if (count == nullptr) {
- return hipErrorInvalidValue;
- }
-
- // Get all available devices
- *count = g_context->devices().size();
-
- return hipSuccess;
-}
-
-hipError_t hipDeviceGetAttribute(int* pi, hipDeviceAttribute_t attr, int device) {
-
- HIP_INIT_API(pi, attr, device);
-
- if (pi == nullptr) {
- return hipErrorInvalidValue;
- }
-
- //if (unsigned(device) >= g_context->devices().size()) {
- // return hipErrorInvalidDevice;
- //}
- //auto* deviceHandle = g_context->devices()[device];
-
- //FIXME: should we cache the props, or just select from deviceHandle->info_?
- hipDeviceProp_t prop = {0};
- hipError_t err = hipGetDeviceProperties(&prop, device);
- if (err != hipSuccess) return err;
-
- switch (attr) {
- case hipDeviceAttributeMaxThreadsPerBlock:
- *pi = prop.maxThreadsPerBlock;
- break;
- case hipDeviceAttributeMaxBlockDimX:
- *pi = prop.maxThreadsDim[0];
- break;
- case hipDeviceAttributeMaxBlockDimY:
- *pi = prop.maxThreadsDim[1];
- break;
- case hipDeviceAttributeMaxBlockDimZ:
- *pi = prop.maxThreadsDim[2];
- break;
- case hipDeviceAttributeMaxGridDimX:
- *pi = prop.maxGridSize[0];
- break;
- case hipDeviceAttributeMaxGridDimY:
- *pi = prop.maxGridSize[1];
- break;
- case hipDeviceAttributeMaxGridDimZ:
- *pi = prop.maxGridSize[2];
- break;
- case hipDeviceAttributeMaxSharedMemoryPerBlock:
- *pi = prop.sharedMemPerBlock;
- break;
- case hipDeviceAttributeTotalConstantMemory:
- *pi = prop.totalConstMem;
- break;
- case hipDeviceAttributeWarpSize:
- *pi = prop.warpSize;
- break;
- case hipDeviceAttributeMaxRegistersPerBlock:
- *pi = prop.regsPerBlock;
- break;
- case hipDeviceAttributeClockRate:
- *pi = prop.clockRate;
- break;
- case hipDeviceAttributeMemoryClockRate:
- *pi = prop.memoryClockRate;
- break;
- case hipDeviceAttributeMemoryBusWidth:
- *pi = prop.memoryBusWidth;
- break;
- case hipDeviceAttributeMultiprocessorCount:
- *pi = prop.multiProcessorCount;
- break;
- case hipDeviceAttributeComputeMode:
- *pi = prop.computeMode;
- break;
- case hipDeviceAttributeL2CacheSize:
- *pi = prop.l2CacheSize;
- break;
- case hipDeviceAttributeMaxThreadsPerMultiProcessor:
- *pi = prop.maxThreadsPerMultiProcessor;
- break;
- case hipDeviceAttributeComputeCapabilityMajor:
- *pi = prop.major;
- break;
- case hipDeviceAttributeComputeCapabilityMinor:
- *pi = prop.minor;
- break;
- case hipDeviceAttributePciBusId:
- *pi = prop.pciBusID;
- break;
- case hipDeviceAttributeConcurrentKernels:
- *pi = prop.concurrentKernels;
- break;
- case hipDeviceAttributePciDeviceId:
- *pi = prop.pciDeviceID;
- break;
- case hipDeviceAttributeMaxSharedMemoryPerMultiprocessor:
- *pi = prop.maxSharedMemoryPerMultiProcessor;
- break;
- case hipDeviceAttributeIsMultiGpuBoard:
- *pi = prop.isMultiGpuBoard;
- break;
- default:
- return hipErrorInvalidValue;
- }
-
- return hipSuccess;
-}
-
-hipError_t hipGetDeviceProperties(hipDeviceProp_t* props, int device) {
-
- HIP_INIT_API(props, device);
-
- if (props == nullptr) {
- return hipErrorInvalidValue;
- }
-
- if (unsigned(device) >= g_context->devices().size()) {
- return hipErrorInvalidDevice;
- }
- auto* deviceHandle = g_context->devices()[device];
-
- hipDeviceProp_t deviceProps = {0};
-
- const auto& info = deviceHandle->info();
- ::strncpy(deviceProps.name, info.boardName_, 128);
- deviceProps.totalGlobalMem = info.globalMemSize_;
- deviceProps.sharedMemPerBlock = info.localMemSizePerCU_;
- deviceProps.regsPerBlock = info.availableSGPRs_;
- deviceProps.warpSize = info.wavefrontWidth_;
- deviceProps.maxThreadsPerBlock = info.maxWorkGroupSize_;
- deviceProps.maxThreadsDim[0] = info.maxWorkItemSizes_[0];
- deviceProps.maxThreadsDim[1] = info.maxWorkItemSizes_[1];
- deviceProps.maxThreadsDim[2] = info.maxWorkItemSizes_[2];
- deviceProps.maxGridSize[0] = UINT32_MAX;
- deviceProps.maxGridSize[1] = UINT32_MAX;
- deviceProps.maxGridSize[2] = UINT32_MAX;
- deviceProps.clockRate = info.maxEngineClockFrequency_;
- deviceProps.memoryClockRate = info.maxMemoryClockFrequency_;
- deviceProps.memoryBusWidth = info.globalMemChannels_ * 32;
- deviceProps.totalConstMem = info.maxConstantBufferSize_;
- deviceProps.major = info.gfxipVersion_ / 100;
- deviceProps.minor = info.gfxipVersion_ % 100;
- deviceProps.multiProcessorCount = info.maxComputeUnits_;
- deviceProps.l2CacheSize = info.l2CacheSize_;
- deviceProps.maxThreadsPerMultiProcessor = info.simdPerCU_;
- deviceProps.computeMode = 0;
- deviceProps.clockInstructionRate = info.timeStampFrequency_;
- deviceProps.arch.hasGlobalInt32Atomics = 1;
- deviceProps.arch.hasGlobalFloatAtomicExch = 1;
- deviceProps.arch.hasSharedInt32Atomics = 1;
- deviceProps.arch.hasSharedFloatAtomicExch = 1;
- deviceProps.arch.hasFloatAtomicAdd = 0;
- deviceProps.arch.hasGlobalInt64Atomics = 1;
- deviceProps.arch.hasSharedInt64Atomics = 1;
- deviceProps.arch.hasDoubles = 1;
- deviceProps.arch.hasWarpVote = 0;
- deviceProps.arch.hasWarpBallot = 0;
- deviceProps.arch.hasWarpShuffle = 0;
- deviceProps.arch.hasFunnelShift = 0;
- deviceProps.arch.hasThreadFenceSystem = 1;
- deviceProps.arch.hasSyncThreadsExt = 0;
- deviceProps.arch.hasSurfaceFuncs = 0;
- deviceProps.arch.has3dGrid = 1;
- deviceProps.arch.hasDynamicParallelism = 0;
- deviceProps.concurrentKernels = 1;
- deviceProps.pciDomainID = info.deviceTopology_.pcie.function;
- deviceProps.pciBusID = info.deviceTopology_.pcie.bus;
- deviceProps.pciDeviceID = info.deviceTopology_.pcie.device;
- deviceProps.maxSharedMemoryPerMultiProcessor = info.localMemSizePerCU_;
- //deviceProps.isMultiGpuBoard = info.;
- deviceProps.canMapHostMemory = 1;
- deviceProps.gcnArch = info.gfxipVersion_;
-
- *props = deviceProps;
- return hipSuccess;
-}
-
-hipError_t hipDeviceSetCacheConfig(hipFuncCache_t cacheConfig) {
-
- HIP_INIT_API(cacheConfig);
-
- // No way to set cache config yet.
-
- return hipSuccess;
-}
-
-hipError_t hipDeviceGetCacheConfig(hipFuncCache_t *cacheConfig) {
- HIP_INIT_API(cacheConfig);
-
- if(cacheConfig == nullptr) {
- return hipErrorInvalidValue;
- }
-
- *cacheConfig = hipFuncCache_t();
-
- return hipSuccess;
-}
-
-hipError_t hipSetDeviceFlags(unsigned int flags) {
-
- HIP_INIT_API(flags);
-
- assert(0 && "Unimplemented");
-
- return hipSuccess;
-};
-
-hipError_t hipDeviceGetLimit (size_t *pValue, hipLimit_t limit) {
-
- HIP_INIT_API(pValue, limit);
-
- auto* deviceHandle = g_context->devices()[0];
- const auto& info = deviceHandle->info();
-
- if(pValue == nullptr) {
- return hipErrorInvalidValue;
- }
- if(limit == hipLimitMallocHeapSize) {
- *pValue = info.globalMemSize_;
- return hipSuccess;
- } else {
- return hipErrorUnsupportedLimit;
- }
-
-}
-
hipError_t hipFuncSetCacheConfig (const void* func, hipFuncCache_t cacheConfig) {
HIP_INIT_API(cacheConfig);
@@ -293,166 +46,6 @@ hipError_t hipFuncSetCacheConfig (const void* func, hipFuncCache_t cacheConfig)
return hipSuccess;
}
-hipError_t hipDeviceSetSharedMemConfig (hipSharedMemConfig config) {
-
- HIP_INIT_API(config);
-
- // No way to set cache config yet.
-
- return hipSuccess;
-}
-
-hipError_t hipDeviceGetSharedMemConfig (hipSharedMemConfig *pConfig) {
-
- HIP_INIT_API(pConfig);
-
- *pConfig = hipSharedMemBankSizeFourByte;
-
- return hipSuccess;
-}
-
-
-hipError_t hipChooseDevice(int* device, const hipDeviceProp_t* properties) {
-
- HIP_INIT_API(device, properties);
-
- if (device == nullptr || properties == nullptr) {
- return hipErrorInvalidValue;
- }
-
- *device = 0;
- cl_uint maxMatchedCount = 0;
-
- for (cl_uint i = 0; i< g_context->devices().size(); ++i) {
- hipDeviceProp_t currentProp = {0};
- cl_uint validPropCount = 0;
- cl_uint matchedCount = 0;
- hipError_t err = hipGetDeviceProperties(¤tProp, i);
- if (properties->major != 0) {
- validPropCount++;
- if(currentProp.major >= properties->major) {
- matchedCount++;
- }
- }
- if (properties->minor != 0) {
- validPropCount++;
- if(currentProp.minor >= properties->minor) {
- matchedCount++;
- }
- }
- if(properties->totalGlobalMem != 0) {
- validPropCount++;
- if(currentProp.totalGlobalMem >= properties->totalGlobalMem) {
- matchedCount++;
- }
- }
- if(properties->sharedMemPerBlock != 0) {
- validPropCount++;
- if(currentProp.sharedMemPerBlock >= properties->sharedMemPerBlock) {
- matchedCount++;
- }
- }
- if(properties->maxThreadsPerBlock != 0) {
- validPropCount++;
- if(currentProp.maxThreadsPerBlock >= properties->maxThreadsPerBlock ) {
- matchedCount++;
- }
- }
- if(properties->totalConstMem != 0) {
- validPropCount++;
- if(currentProp.totalConstMem >= properties->totalConstMem ) {
- matchedCount++;
- }
- }
- if(properties->multiProcessorCount != 0) {
- validPropCount++;
- if(currentProp.multiProcessorCount >=
- properties->multiProcessorCount ) {
- matchedCount++;
- }
- }
- if(properties->maxThreadsPerMultiProcessor != 0) {
- validPropCount++;
- if(currentProp.maxThreadsPerMultiProcessor >=
- properties->maxThreadsPerMultiProcessor ) {
- matchedCount++;
- }
- }
- if(properties->memoryClockRate != 0) {
- validPropCount++;
- if(currentProp.memoryClockRate >= properties->memoryClockRate ) {
- matchedCount++;
- }
- }
- if(properties->memoryBusWidth != 0) {
- validPropCount++;
- if(currentProp.memoryBusWidth >= properties->memoryBusWidth ) {
- matchedCount++;
- }
- }
- if(properties->l2CacheSize != 0) {
- validPropCount++;
- if(currentProp.l2CacheSize >= properties->l2CacheSize ) {
- matchedCount++;
- }
- }
- if(properties->regsPerBlock != 0) {
- validPropCount++;
- if(currentProp.regsPerBlock >= properties->regsPerBlock ) {
- matchedCount++;
- }
- }
- if(properties->maxSharedMemoryPerMultiProcessor != 0) {
- validPropCount++;
- if(currentProp.maxSharedMemoryPerMultiProcessor >=
- properties->maxSharedMemoryPerMultiProcessor ) {
- matchedCount++;
- }
- }
- if(properties->warpSize != 0) {
- validPropCount++;
- if(currentProp.warpSize >= properties->warpSize ) {
- matchedCount++;
- }
- }
- if(validPropCount == matchedCount) {
- *device = matchedCount > maxMatchedCount ? i : *device;
- maxMatchedCount = std::max(matchedCount, maxMatchedCount);
- }
- }
-
- return hipSuccess;
-}
-
-
-hipError_t hipDeviceGetByPCIBusId (int* device, const char* pciBusIdstr) {
-
- HIP_INIT_API(device, pciBusIdstr);
-
- if (device == nullptr || pciBusIdstr == nullptr) {
- return hipErrorInvalidValue;
- }
-
- int pciBusID = -1;
- int pciDeviceID = -1;
- int pciDomainID = -1;
-
- if (sscanf (pciBusIdstr, "%04x:%02x:%02x", &pciDomainID, &pciBusID, &pciDeviceID) == 0x3) {
- for (cl_uint i = 0; i < g_context->devices().size(); i++) {
- auto* deviceHandle = g_context->devices()[i];
- auto& info = deviceHandle->info();
-
- if (pciBusID == info.deviceTopology_.pcie.bus) {
- *device = i;
- break;
- }
- }
- }
-
- return hipSuccess;
-}
-
-
hipError_t hipDeviceTotalMem (size_t *bytes, hipDevice_t device) {
HIP_INIT_API(bytes, device);
@@ -513,51 +106,3 @@ hipError_t hipDeviceGetName(char *name, int len, hipDevice_t device) {
return hipSuccess;
}
-
-hipError_t hipDeviceGetPCIBusId (char *pciBusId, int len, int device) {
-
- HIP_INIT_API((void*)pciBusId, len, device);
-
- if (device < 0 || device > (cl_int)g_context->devices().size()) {
- return hipErrorInvalidDevice;
- }
-
- if (pciBusId == nullptr || len < 0) {
- return hipErrorInvalidValue;
- }
-
- auto* deviceHandle = g_context->devices()[device];
- const auto& info = deviceHandle->info();
- snprintf (pciBusId, len, "%04x:%02x:%02x.0",
- info.deviceTopology_.pcie.function,
- info.deviceTopology_.pcie.bus,
- info.deviceTopology_.pcie.device);
-
-
- return hipSuccess;
-}
-
-hipError_t hipSetDevice(int deviceId)
-{
- HIP_INIT_API(deviceId);
-
- assert(0 && "Unimplemented");
-
- return hipErrorUnknown;
-}
-
-hipError_t hipDeviceReset(void)
-{
- HIP_INIT_API();
-
- assert(0 && "Unimplemented");
-
- return hipErrorUnknown;
-}
-
-
-hipError_t hipDeviceSynchronize(void)
-{
- // FIXME: should wait on all streams
- return hipSuccess;
-}
diff --git a/api/hip/hip_device_runtime.cpp b/api/hip/hip_device_runtime.cpp
new file mode 100644
index 0000000000..b9b6ccb68e
--- /dev/null
+++ b/api/hip/hip_device_runtime.cpp
@@ -0,0 +1,533 @@
+/*
+Copyright (c) 2018 - present Advanced Micro Devices, Inc. All rights reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#include
+
+#include "hip_internal.hpp"
+
+hipError_t hipChooseDevice(int* device, const hipDeviceProp_t* properties) {
+
+ HIP_INIT_API(device, properties);
+
+ if (device == nullptr || properties == nullptr) {
+ return hipErrorInvalidValue;
+ }
+
+ *device = 0;
+ cl_uint maxMatchedCount = 0;
+
+ for (cl_uint i = 0; i< g_context->devices().size(); ++i) {
+ hipDeviceProp_t currentProp = {0};
+ cl_uint validPropCount = 0;
+ cl_uint matchedCount = 0;
+ hipError_t err = hipGetDeviceProperties(¤tProp, i);
+ if (properties->major != 0) {
+ validPropCount++;
+ if(currentProp.major >= properties->major) {
+ matchedCount++;
+ }
+ }
+ if (properties->minor != 0) {
+ validPropCount++;
+ if(currentProp.minor >= properties->minor) {
+ matchedCount++;
+ }
+ }
+ if(properties->totalGlobalMem != 0) {
+ validPropCount++;
+ if(currentProp.totalGlobalMem >= properties->totalGlobalMem) {
+ matchedCount++;
+ }
+ }
+ if(properties->sharedMemPerBlock != 0) {
+ validPropCount++;
+ if(currentProp.sharedMemPerBlock >= properties->sharedMemPerBlock) {
+ matchedCount++;
+ }
+ }
+ if(properties->maxThreadsPerBlock != 0) {
+ validPropCount++;
+ if(currentProp.maxThreadsPerBlock >= properties->maxThreadsPerBlock ) {
+ matchedCount++;
+ }
+ }
+ if(properties->totalConstMem != 0) {
+ validPropCount++;
+ if(currentProp.totalConstMem >= properties->totalConstMem ) {
+ matchedCount++;
+ }
+ }
+ if(properties->multiProcessorCount != 0) {
+ validPropCount++;
+ if(currentProp.multiProcessorCount >=
+ properties->multiProcessorCount ) {
+ matchedCount++;
+ }
+ }
+ if(properties->maxThreadsPerMultiProcessor != 0) {
+ validPropCount++;
+ if(currentProp.maxThreadsPerMultiProcessor >=
+ properties->maxThreadsPerMultiProcessor ) {
+ matchedCount++;
+ }
+ }
+ if(properties->memoryClockRate != 0) {
+ validPropCount++;
+ if(currentProp.memoryClockRate >= properties->memoryClockRate ) {
+ matchedCount++;
+ }
+ }
+ if(properties->memoryBusWidth != 0) {
+ validPropCount++;
+ if(currentProp.memoryBusWidth >= properties->memoryBusWidth ) {
+ matchedCount++;
+ }
+ }
+ if(properties->l2CacheSize != 0) {
+ validPropCount++;
+ if(currentProp.l2CacheSize >= properties->l2CacheSize ) {
+ matchedCount++;
+ }
+ }
+ if(properties->regsPerBlock != 0) {
+ validPropCount++;
+ if(currentProp.regsPerBlock >= properties->regsPerBlock ) {
+ matchedCount++;
+ }
+ }
+ if(properties->maxSharedMemoryPerMultiProcessor != 0) {
+ validPropCount++;
+ if(currentProp.maxSharedMemoryPerMultiProcessor >=
+ properties->maxSharedMemoryPerMultiProcessor ) {
+ matchedCount++;
+ }
+ }
+ if(properties->warpSize != 0) {
+ validPropCount++;
+ if(currentProp.warpSize >= properties->warpSize ) {
+ matchedCount++;
+ }
+ }
+ if(validPropCount == matchedCount) {
+ *device = matchedCount > maxMatchedCount ? i : *device;
+ maxMatchedCount = std::max(matchedCount, maxMatchedCount);
+ }
+ }
+
+ return hipSuccess;
+}
+
+hipError_t hipDeviceGetAttribute(int* pi, hipDeviceAttribute_t attr, int device) {
+
+ HIP_INIT_API(pi, attr, device);
+
+ if (pi == nullptr) {
+ return hipErrorInvalidValue;
+ }
+
+ //if (unsigned(device) >= g_context->devices().size()) {
+ // return hipErrorInvalidDevice;
+ //}
+ //auto* deviceHandle = g_context->devices()[device];
+
+ //FIXME: should we cache the props, or just select from deviceHandle->info_?
+ hipDeviceProp_t prop = {0};
+ hipError_t err = hipGetDeviceProperties(&prop, device);
+ if (err != hipSuccess) return err;
+
+ switch (attr) {
+ case hipDeviceAttributeMaxThreadsPerBlock:
+ *pi = prop.maxThreadsPerBlock;
+ break;
+ case hipDeviceAttributeMaxBlockDimX:
+ *pi = prop.maxThreadsDim[0];
+ break;
+ case hipDeviceAttributeMaxBlockDimY:
+ *pi = prop.maxThreadsDim[1];
+ break;
+ case hipDeviceAttributeMaxBlockDimZ:
+ *pi = prop.maxThreadsDim[2];
+ break;
+ case hipDeviceAttributeMaxGridDimX:
+ *pi = prop.maxGridSize[0];
+ break;
+ case hipDeviceAttributeMaxGridDimY:
+ *pi = prop.maxGridSize[1];
+ break;
+ case hipDeviceAttributeMaxGridDimZ:
+ *pi = prop.maxGridSize[2];
+ break;
+ case hipDeviceAttributeMaxSharedMemoryPerBlock:
+ *pi = prop.sharedMemPerBlock;
+ break;
+ case hipDeviceAttributeTotalConstantMemory:
+ *pi = prop.totalConstMem;
+ break;
+ case hipDeviceAttributeWarpSize:
+ *pi = prop.warpSize;
+ break;
+ case hipDeviceAttributeMaxRegistersPerBlock:
+ *pi = prop.regsPerBlock;
+ break;
+ case hipDeviceAttributeClockRate:
+ *pi = prop.clockRate;
+ break;
+ case hipDeviceAttributeMemoryClockRate:
+ *pi = prop.memoryClockRate;
+ break;
+ case hipDeviceAttributeMemoryBusWidth:
+ *pi = prop.memoryBusWidth;
+ break;
+ case hipDeviceAttributeMultiprocessorCount:
+ *pi = prop.multiProcessorCount;
+ break;
+ case hipDeviceAttributeComputeMode:
+ *pi = prop.computeMode;
+ break;
+ case hipDeviceAttributeL2CacheSize:
+ *pi = prop.l2CacheSize;
+ break;
+ case hipDeviceAttributeMaxThreadsPerMultiProcessor:
+ *pi = prop.maxThreadsPerMultiProcessor;
+ break;
+ case hipDeviceAttributeComputeCapabilityMajor:
+ *pi = prop.major;
+ break;
+ case hipDeviceAttributeComputeCapabilityMinor:
+ *pi = prop.minor;
+ break;
+ case hipDeviceAttributePciBusId:
+ *pi = prop.pciBusID;
+ break;
+ case hipDeviceAttributeConcurrentKernels:
+ *pi = prop.concurrentKernels;
+ break;
+ case hipDeviceAttributePciDeviceId:
+ *pi = prop.pciDeviceID;
+ break;
+ case hipDeviceAttributeMaxSharedMemoryPerMultiprocessor:
+ *pi = prop.maxSharedMemoryPerMultiProcessor;
+ break;
+ case hipDeviceAttributeIsMultiGpuBoard:
+ *pi = prop.isMultiGpuBoard;
+ break;
+ default:
+ return hipErrorInvalidValue;
+ }
+
+ return hipSuccess;
+}
+
+hipError_t hipDeviceGetByPCIBusId(int* device, const char*pciBusIdstr) {
+
+ HIP_INIT_API(device, pciBusIdstr);
+
+ if (device == nullptr || pciBusIdstr == nullptr) {
+ return hipErrorInvalidValue;
+ }
+
+ int pciBusID = -1;
+ int pciDeviceID = -1;
+ int pciDomainID = -1;
+
+ if (sscanf (pciBusIdstr, "%04x:%02x:%02x", &pciDomainID, &pciBusID, &pciDeviceID) == 0x3) {
+ for (cl_uint i = 0; i < g_context->devices().size(); i++) {
+ auto* deviceHandle = g_context->devices()[i];
+ auto& info = deviceHandle->info();
+
+ if (pciBusID == info.deviceTopology_.pcie.bus) {
+ *device = i;
+ break;
+ }
+ }
+ }
+
+ return hipSuccess;
+}
+
+hipError_t hipDeviceGetCacheConfig ( hipFuncCache_t * cacheConfig ) {
+ HIP_INIT_API(cacheConfig);
+
+ if(cacheConfig == nullptr) {
+ return hipErrorInvalidValue;
+ }
+
+ *cacheConfig = hipFuncCache_t();
+
+ return hipSuccess;
+}
+
+hipError_t hipDeviceGetLimit ( size_t* pValue, hipLimit_t limit ) {
+
+ HIP_INIT_API(pValue, limit);
+
+ auto* deviceHandle = g_context->devices()[0];
+ const auto& info = deviceHandle->info();
+
+ if(pValue == nullptr) {
+ return hipErrorInvalidValue;
+ }
+ if(limit == hipLimitMallocHeapSize) {
+ *pValue = info.globalMemSize_;
+ return hipSuccess;
+ } else {
+ return hipErrorUnsupportedLimit;
+ }
+}
+
+/**
+hipError_t hipDeviceGetP2PAttribute ( int* value, hipDeviceP2PAttr attr, int srcDevice, int dstDevice ) {
+ assert(0);
+ return hipSuccess;
+}
+**/
+
+hipError_t hipDeviceGetPCIBusId ( char* pciBusId, int len, int device ) {
+
+ HIP_INIT_API((void*)pciBusId, len, device);
+
+ if (device < 0 || device > (cl_int)g_context->devices().size()) {
+ return hipErrorInvalidDevice;
+ }
+
+ if (pciBusId == nullptr || len < 0) {
+ return hipErrorInvalidValue;
+ }
+
+ auto* deviceHandle = g_context->devices()[device];
+ const auto& info = deviceHandle->info();
+ snprintf (pciBusId, len, "%04x:%02x:%02x.0",
+ info.deviceTopology_.pcie.function,
+ info.deviceTopology_.pcie.bus,
+ info.deviceTopology_.pcie.device);
+
+
+ return hipSuccess;
+}
+
+hipError_t hipDeviceGetSharedMemConfig ( hipSharedMemConfig * pConfig ) {
+ HIP_INIT_API(pConfig);
+
+ *pConfig = hipSharedMemBankSizeFourByte;
+
+ return hipSuccess;
+}
+
+hipError_t hipDeviceGetStreamPriorityRange ( int* leastPriority, int* greatestPriority ) {
+ assert(0);
+ return hipSuccess;
+}
+
+hipError_t hipDeviceReset ( void ) {
+ HIP_INIT_API();
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipDeviceSetCacheConfig ( hipFuncCache_t cacheConfig ) {
+ HIP_INIT_API(cacheConfig);
+
+ // No way to set cache config yet.
+
+ return hipSuccess;
+}
+
+hipError_t hipDeviceSetLimit ( hipLimit_t limit, size_t value ) {
+ return hipErrorUnknown;
+}
+
+hipError_t hipDeviceSetSharedMemConfig ( hipSharedMemConfig config ) {
+ HIP_INIT_API(config);
+
+ // No way to set cache config yet.
+
+ return hipSuccess;
+}
+
+hipError_t hipDeviceSynchronize ( void ) {
+ return hipSuccess;
+}
+
+hipError_t hipGetDevice ( int* deviceId ) {
+ HIP_INIT_API(deviceId);
+
+ if (deviceId != nullptr) {
+ // this needs to return default device. For now return 0 always
+ *deviceId = 0;
+ } else {
+ return hipErrorInvalidValue;
+ }
+
+ return hipSuccess;
+}
+
+hipError_t hipGetDeviceCount ( int* count ) {
+ HIP_INIT_API(count);
+
+ if (count == nullptr) {
+ return hipErrorInvalidValue;
+ }
+
+ // Get all available devices
+ *count = g_context->devices().size();
+
+ return hipSuccess;
+}
+
+hipError_t hipGetDeviceFlags ( unsigned int* flags ) {
+ return hipErrorUnknown;
+}
+
+hipError_t hipGetDeviceProperties ( hipDeviceProp_t* props, int device ) {
+ HIP_INIT_API(props, device);
+
+ if (props == nullptr) {
+ return hipErrorInvalidValue;
+ }
+
+ if (unsigned(device) >= g_context->devices().size()) {
+ return hipErrorInvalidDevice;
+ }
+ auto* deviceHandle = g_context->devices()[device];
+
+ hipDeviceProp_t deviceProps = {0};
+
+ const auto& info = deviceHandle->info();
+ ::strncpy(deviceProps.name, info.boardName_, 128);
+ deviceProps.totalGlobalMem = info.globalMemSize_;
+ deviceProps.sharedMemPerBlock = info.localMemSizePerCU_;
+ deviceProps.regsPerBlock = info.availableSGPRs_;
+ deviceProps.warpSize = info.wavefrontWidth_;
+ deviceProps.maxThreadsPerBlock = info.maxWorkGroupSize_;
+ deviceProps.maxThreadsDim[0] = info.maxWorkItemSizes_[0];
+ deviceProps.maxThreadsDim[1] = info.maxWorkItemSizes_[1];
+ deviceProps.maxThreadsDim[2] = info.maxWorkItemSizes_[2];
+ deviceProps.maxGridSize[0] = UINT32_MAX;
+ deviceProps.maxGridSize[1] = UINT32_MAX;
+ deviceProps.maxGridSize[2] = UINT32_MAX;
+ deviceProps.clockRate = info.maxEngineClockFrequency_;
+ deviceProps.memoryClockRate = info.maxMemoryClockFrequency_;
+ deviceProps.memoryBusWidth = info.globalMemChannels_ * 32;
+ deviceProps.totalConstMem = info.maxConstantBufferSize_;
+ deviceProps.major = info.gfxipVersion_ / 100;
+ deviceProps.minor = info.gfxipVersion_ % 100;
+ deviceProps.multiProcessorCount = info.maxComputeUnits_;
+ deviceProps.l2CacheSize = info.l2CacheSize_;
+ deviceProps.maxThreadsPerMultiProcessor = info.simdPerCU_;
+ deviceProps.computeMode = 0;
+ deviceProps.clockInstructionRate = info.timeStampFrequency_;
+ deviceProps.arch.hasGlobalInt32Atomics = 1;
+ deviceProps.arch.hasGlobalFloatAtomicExch = 1;
+ deviceProps.arch.hasSharedInt32Atomics = 1;
+ deviceProps.arch.hasSharedFloatAtomicExch = 1;
+ deviceProps.arch.hasFloatAtomicAdd = 0;
+ deviceProps.arch.hasGlobalInt64Atomics = 1;
+ deviceProps.arch.hasSharedInt64Atomics = 1;
+ deviceProps.arch.hasDoubles = 1;
+ deviceProps.arch.hasWarpVote = 0;
+ deviceProps.arch.hasWarpBallot = 0;
+ deviceProps.arch.hasWarpShuffle = 0;
+ deviceProps.arch.hasFunnelShift = 0;
+ deviceProps.arch.hasThreadFenceSystem = 1;
+ deviceProps.arch.hasSyncThreadsExt = 0;
+ deviceProps.arch.hasSurfaceFuncs = 0;
+ deviceProps.arch.has3dGrid = 1;
+ deviceProps.arch.hasDynamicParallelism = 0;
+ deviceProps.concurrentKernels = 1;
+ deviceProps.pciDomainID = info.deviceTopology_.pcie.function;
+ deviceProps.pciBusID = info.deviceTopology_.pcie.bus;
+ deviceProps.pciDeviceID = info.deviceTopology_.pcie.device;
+ deviceProps.maxSharedMemoryPerMultiProcessor = info.localMemSizePerCU_;
+ //deviceProps.isMultiGpuBoard = info.;
+ deviceProps.canMapHostMemory = 1;
+ deviceProps.gcnArch = info.gfxipVersion_;
+
+ *props = deviceProps;
+ return hipSuccess;
+}
+
+hipError_t hipIpcCloseMemHandle ( void* devPtr ) {
+ HIP_INIT_API(devPtr);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipIpcGetEventHandle ( hipIpcEventHandle_t* handle, hipEvent_t event ) {
+ HIP_INIT_API(handle, event);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipIpcGetMemHandle ( hipIpcMemHandle_t* handle, void* devPtr ) {
+ HIP_INIT_API(handle, devPtr);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipIpcOpenEventHandle ( hipEvent_t* event, hipIpcEventHandle_t handle ) {
+ HIP_INIT_API(event, handle);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipIpcOpenMemHandle ( void** devPtr, hipIpcMemHandle_t handle, unsigned int flags ) {
+ HIP_INIT_API(devPtr, handle, flags);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipSetDevice ( int device ) {
+ HIP_INIT_API(device);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipSetDeviceFlags ( unsigned int flags ) {
+ HIP_INIT_API(flags);
+
+ assert(0 && "Unimplemented");
+
+ return hipSuccess;
+}
+
+hipError_t hipSetValidDevices ( int* device_arr, int len ) {
+ HIP_INIT_API(device_arr, len);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
From a78a9b035042303f2ae279e0811e4dc335b44373 Mon Sep 17 00:00:00 2001
From: foreman
Date: Wed, 14 Mar 2018 19:05:10 -0400
Subject: [PATCH 009/282] P4 to Git Change 1527320 by
cpaquot@cpaquot-ocl-lc-lnx on 2018/03/14 18:54:10
SWDEV-145570 - Remove all g_context from runtime device implementation
Affected files ...
... //depot/stg/opencl/drivers/opencl/api/hip/hip_device.cpp#6 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_device_runtime.cpp#2 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_internal.hpp#3 edit
---
api/hip/hip_device.cpp | 82 +++++++++++++++++++++++
api/hip/hip_device_runtime.cpp | 117 +++++++--------------------------
api/hip/hip_internal.hpp | 2 +
3 files changed, 109 insertions(+), 92 deletions(-)
diff --git a/api/hip/hip_device.cpp b/api/hip/hip_device.cpp
index ae9cba963d..f646933bb9 100644
--- a/api/hip/hip_device.cpp
+++ b/api/hip/hip_device.cpp
@@ -86,6 +86,19 @@ hipError_t hipDeviceComputeCapability(int *major, int *minor, hipDevice_t device
return hipSuccess;
}
+hipError_t hipDeviceGetCount(int* count) {
+ HIP_INIT_API(count);
+
+ if (count == nullptr) {
+ return hipErrorInvalidValue;
+ }
+
+ // Get all available devices
+ *count = g_context->devices().size();
+
+ return hipSuccess;
+}
+
hipError_t hipDeviceGetName(char *name, int len, hipDevice_t device) {
HIP_INIT_API((void*)name, len, device);
@@ -106,3 +119,72 @@ hipError_t hipDeviceGetName(char *name, int len, hipDevice_t device) {
return hipSuccess;
}
+
+hipError_t hipGetDeviceProperties ( hipDeviceProp_t* props, hipDevice_t device ) {
+ HIP_INIT_API(props, device);
+
+ if (props == nullptr) {
+ return hipErrorInvalidValue;
+ }
+
+ if (unsigned(device) >= g_context->devices().size()) {
+ return hipErrorInvalidDevice;
+ }
+ auto* deviceHandle = g_context->devices()[device];
+
+ hipDeviceProp_t deviceProps = {0};
+
+ const auto& info = deviceHandle->info();
+ ::strncpy(deviceProps.name, info.boardName_, 128);
+ deviceProps.totalGlobalMem = info.globalMemSize_;
+ deviceProps.sharedMemPerBlock = info.localMemSizePerCU_;
+ deviceProps.regsPerBlock = info.availableSGPRs_;
+ deviceProps.warpSize = info.wavefrontWidth_;
+ deviceProps.maxThreadsPerBlock = info.maxWorkGroupSize_;
+ deviceProps.maxThreadsDim[0] = info.maxWorkItemSizes_[0];
+ deviceProps.maxThreadsDim[1] = info.maxWorkItemSizes_[1];
+ deviceProps.maxThreadsDim[2] = info.maxWorkItemSizes_[2];
+ deviceProps.maxGridSize[0] = UINT32_MAX;
+ deviceProps.maxGridSize[1] = UINT32_MAX;
+ deviceProps.maxGridSize[2] = UINT32_MAX;
+ deviceProps.clockRate = info.maxEngineClockFrequency_;
+ deviceProps.memoryClockRate = info.maxMemoryClockFrequency_;
+ deviceProps.memoryBusWidth = info.globalMemChannels_ * 32;
+ deviceProps.totalConstMem = info.maxConstantBufferSize_;
+ deviceProps.major = info.gfxipVersion_ / 100;
+ deviceProps.minor = info.gfxipVersion_ % 100;
+ deviceProps.multiProcessorCount = info.maxComputeUnits_;
+ deviceProps.l2CacheSize = info.l2CacheSize_;
+ deviceProps.maxThreadsPerMultiProcessor = info.simdPerCU_;
+ deviceProps.computeMode = 0;
+ deviceProps.clockInstructionRate = info.timeStampFrequency_;
+ deviceProps.arch.hasGlobalInt32Atomics = 1;
+ deviceProps.arch.hasGlobalFloatAtomicExch = 1;
+ deviceProps.arch.hasSharedInt32Atomics = 1;
+ deviceProps.arch.hasSharedFloatAtomicExch = 1;
+ deviceProps.arch.hasFloatAtomicAdd = 0;
+ deviceProps.arch.hasGlobalInt64Atomics = 1;
+ deviceProps.arch.hasSharedInt64Atomics = 1;
+ deviceProps.arch.hasDoubles = 1;
+ deviceProps.arch.hasWarpVote = 0;
+ deviceProps.arch.hasWarpBallot = 0;
+ deviceProps.arch.hasWarpShuffle = 0;
+ deviceProps.arch.hasFunnelShift = 0;
+ deviceProps.arch.hasThreadFenceSystem = 1;
+ deviceProps.arch.hasSyncThreadsExt = 0;
+ deviceProps.arch.hasSurfaceFuncs = 0;
+ deviceProps.arch.has3dGrid = 1;
+ deviceProps.arch.hasDynamicParallelism = 0;
+ deviceProps.concurrentKernels = 1;
+ deviceProps.pciDomainID = info.deviceTopology_.pcie.function;
+ deviceProps.pciBusID = info.deviceTopology_.pcie.bus;
+ deviceProps.pciDeviceID = info.deviceTopology_.pcie.device;
+ deviceProps.maxSharedMemoryPerMultiProcessor = info.localMemSizePerCU_;
+ //deviceProps.isMultiGpuBoard = info.;
+ deviceProps.canMapHostMemory = 1;
+ deviceProps.gcnArch = info.gfxipVersion_;
+
+ *props = deviceProps;
+ return hipSuccess;
+}
+
diff --git a/api/hip/hip_device_runtime.cpp b/api/hip/hip_device_runtime.cpp
index b9b6ccb68e..bbd0838f76 100644
--- a/api/hip/hip_device_runtime.cpp
+++ b/api/hip/hip_device_runtime.cpp
@@ -34,8 +34,10 @@ hipError_t hipChooseDevice(int* device, const hipDeviceProp_t* properties) {
*device = 0;
cl_uint maxMatchedCount = 0;
+ int count = 0;
+ hipDeviceGetCount(&count);
- for (cl_uint i = 0; i< g_context->devices().size(); ++i) {
+ for (cl_int i = 0; i< count; ++i) {
hipDeviceProp_t currentProp = {0};
cl_uint validPropCount = 0;
cl_uint matchedCount = 0;
@@ -250,11 +252,15 @@ hipError_t hipDeviceGetByPCIBusId(int* device, const char*pciBusIdstr) {
int pciDomainID = -1;
if (sscanf (pciBusIdstr, "%04x:%02x:%02x", &pciDomainID, &pciBusID, &pciDeviceID) == 0x3) {
- for (cl_uint i = 0; i < g_context->devices().size(); i++) {
- auto* deviceHandle = g_context->devices()[i];
- auto& info = deviceHandle->info();
+ int count = 0;
+ hipDeviceGetCount(&count);
+ for (cl_int i = 0; i < count; i++) {
+ int pi = 0;
+ hipDevice_t dev;
+ hipDeviceGet(&dev, i);
+ hipDeviceGetAttribute(&pi, hipDeviceAttributePciBusId, dev);
- if (pciBusID == info.deviceTopology_.pcie.bus) {
+ if (pciBusID == pi) {
*device = i;
break;
}
@@ -280,14 +286,14 @@ hipError_t hipDeviceGetLimit ( size_t* pValue, hipLimit_t limit ) {
HIP_INIT_API(pValue, limit);
- auto* deviceHandle = g_context->devices()[0];
- const auto& info = deviceHandle->info();
-
if(pValue == nullptr) {
return hipErrorInvalidValue;
}
if(limit == hipLimitMallocHeapSize) {
- *pValue = info.globalMemSize_;
+ hipDeviceProp_t prop;
+ hipGetDeviceProperties(&prop, 0);
+
+ *pValue = prop.totalGlobalMem;
return hipSuccess;
} else {
return hipErrorUnsupportedLimit;
@@ -305,7 +311,9 @@ hipError_t hipDeviceGetPCIBusId ( char* pciBusId, int len, int device ) {
HIP_INIT_API((void*)pciBusId, len, device);
- if (device < 0 || device > (cl_int)g_context->devices().size()) {
+ int count;
+ hipDeviceGetCount(&count);
+ if (device < 0 || device > count) {
return hipErrorInvalidDevice;
}
@@ -313,13 +321,13 @@ hipError_t hipDeviceGetPCIBusId ( char* pciBusId, int len, int device ) {
return hipErrorInvalidValue;
}
- auto* deviceHandle = g_context->devices()[device];
- const auto& info = deviceHandle->info();
- snprintf (pciBusId, len, "%04x:%02x:%02x.0",
- info.deviceTopology_.pcie.function,
- info.deviceTopology_.pcie.bus,
- info.deviceTopology_.pcie.device);
+ hipDeviceProp_t prop;
+ hipGetDeviceProperties(&prop, device);
+ snprintf (pciBusId, len, "%04x:%02x:%02x.0",
+ prop.pciDomainID,
+ prop.pciBusID,
+ prop.pciDeviceID);
return hipSuccess;
}
@@ -385,88 +393,13 @@ hipError_t hipGetDevice ( int* deviceId ) {
hipError_t hipGetDeviceCount ( int* count ) {
HIP_INIT_API(count);
- if (count == nullptr) {
- return hipErrorInvalidValue;
- }
-
- // Get all available devices
- *count = g_context->devices().size();
-
- return hipSuccess;
+ return hipDeviceGetCount(count);
}
hipError_t hipGetDeviceFlags ( unsigned int* flags ) {
return hipErrorUnknown;
}
-hipError_t hipGetDeviceProperties ( hipDeviceProp_t* props, int device ) {
- HIP_INIT_API(props, device);
-
- if (props == nullptr) {
- return hipErrorInvalidValue;
- }
-
- if (unsigned(device) >= g_context->devices().size()) {
- return hipErrorInvalidDevice;
- }
- auto* deviceHandle = g_context->devices()[device];
-
- hipDeviceProp_t deviceProps = {0};
-
- const auto& info = deviceHandle->info();
- ::strncpy(deviceProps.name, info.boardName_, 128);
- deviceProps.totalGlobalMem = info.globalMemSize_;
- deviceProps.sharedMemPerBlock = info.localMemSizePerCU_;
- deviceProps.regsPerBlock = info.availableSGPRs_;
- deviceProps.warpSize = info.wavefrontWidth_;
- deviceProps.maxThreadsPerBlock = info.maxWorkGroupSize_;
- deviceProps.maxThreadsDim[0] = info.maxWorkItemSizes_[0];
- deviceProps.maxThreadsDim[1] = info.maxWorkItemSizes_[1];
- deviceProps.maxThreadsDim[2] = info.maxWorkItemSizes_[2];
- deviceProps.maxGridSize[0] = UINT32_MAX;
- deviceProps.maxGridSize[1] = UINT32_MAX;
- deviceProps.maxGridSize[2] = UINT32_MAX;
- deviceProps.clockRate = info.maxEngineClockFrequency_;
- deviceProps.memoryClockRate = info.maxMemoryClockFrequency_;
- deviceProps.memoryBusWidth = info.globalMemChannels_ * 32;
- deviceProps.totalConstMem = info.maxConstantBufferSize_;
- deviceProps.major = info.gfxipVersion_ / 100;
- deviceProps.minor = info.gfxipVersion_ % 100;
- deviceProps.multiProcessorCount = info.maxComputeUnits_;
- deviceProps.l2CacheSize = info.l2CacheSize_;
- deviceProps.maxThreadsPerMultiProcessor = info.simdPerCU_;
- deviceProps.computeMode = 0;
- deviceProps.clockInstructionRate = info.timeStampFrequency_;
- deviceProps.arch.hasGlobalInt32Atomics = 1;
- deviceProps.arch.hasGlobalFloatAtomicExch = 1;
- deviceProps.arch.hasSharedInt32Atomics = 1;
- deviceProps.arch.hasSharedFloatAtomicExch = 1;
- deviceProps.arch.hasFloatAtomicAdd = 0;
- deviceProps.arch.hasGlobalInt64Atomics = 1;
- deviceProps.arch.hasSharedInt64Atomics = 1;
- deviceProps.arch.hasDoubles = 1;
- deviceProps.arch.hasWarpVote = 0;
- deviceProps.arch.hasWarpBallot = 0;
- deviceProps.arch.hasWarpShuffle = 0;
- deviceProps.arch.hasFunnelShift = 0;
- deviceProps.arch.hasThreadFenceSystem = 1;
- deviceProps.arch.hasSyncThreadsExt = 0;
- deviceProps.arch.hasSurfaceFuncs = 0;
- deviceProps.arch.has3dGrid = 1;
- deviceProps.arch.hasDynamicParallelism = 0;
- deviceProps.concurrentKernels = 1;
- deviceProps.pciDomainID = info.deviceTopology_.pcie.function;
- deviceProps.pciBusID = info.deviceTopology_.pcie.bus;
- deviceProps.pciDeviceID = info.deviceTopology_.pcie.device;
- deviceProps.maxSharedMemoryPerMultiProcessor = info.localMemSizePerCU_;
- //deviceProps.isMultiGpuBoard = info.;
- deviceProps.canMapHostMemory = 1;
- deviceProps.gcnArch = info.gfxipVersion_;
-
- *props = deviceProps;
- return hipSuccess;
-}
-
hipError_t hipIpcCloseMemHandle ( void* devPtr ) {
HIP_INIT_API(devPtr);
diff --git a/api/hip/hip_internal.hpp b/api/hip/hip_internal.hpp
index b1d906d870..159c7671ec 100644
--- a/api/hip/hip_internal.hpp
+++ b/api/hip/hip_internal.hpp
@@ -38,4 +38,6 @@ THE SOFTWARE.
extern amd::Context* g_context;
+hipError_t hipDeviceGetCount(int* count);
+
#endif // HIP_SRC_HIP_INTERNAL_H
From 96c3777e3084041cc9afb61bcd6f1a0a5a8e8f6b Mon Sep 17 00:00:00 2001
From: foreman
Date: Mon, 19 Mar 2018 13:52:17 -0400
Subject: [PATCH 010/282] P4 to Git Change 1528961 by
cpaquot@cpaquot-ocl-lc-lnx on 2018/03/19 13:43:08
SWDEV-145570 - Contexts
Create one amd::Context per device
g_context is now thread's current context
HIP doesn't want more than one context per device so we always use the primary one
Affected files ...
... //depot/stg/opencl/drivers/opencl/api/hip/hip_context.cpp#3 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_device.cpp#7 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_internal.hpp#4 edit
---
api/hip/hip_context.cpp | 45 +++++++++++++++++++++++++++++++++-------
api/hip/hip_device.cpp | 18 ++++++++--------
api/hip/hip_internal.hpp | 3 ++-
3 files changed, 48 insertions(+), 18 deletions(-)
diff --git a/api/hip/hip_context.cpp b/api/hip/hip_context.cpp
index 78e65e99c5..2a67898bf3 100644
--- a/api/hip/hip_context.cpp
+++ b/api/hip/hip_context.cpp
@@ -27,7 +27,8 @@ THE SOFTWARE.
#include "utils/versions.hpp"
-amd::Context* g_context = nullptr;
+thread_local amd::Context* g_context = nullptr;
+std::vector g_devices;
hipError_t hipInit(unsigned int flags)
{
@@ -37,14 +38,18 @@ hipError_t hipInit(unsigned int flags)
amd::Runtime::init();
}
- // FIXME: move the global VDI context to hipInit.
- g_context = new amd::Context(
- amd::Device::getDevices(CL_DEVICE_TYPE_GPU, false), amd::Context::Info());
- if (!g_context) return hipErrorOutOfMemory;
+ const std::vector& devices = amd::Device::getDevices(CL_DEVICE_TYPE_GPU, false);
- if (g_context && CL_SUCCESS != g_context->create(nullptr)) {
- g_context->release();
- return hipErrorUnknown;
+ for (unsigned int i=0; i device(1, devices[i]);
+ amd::Context* context = new amd::Context(device, amd::Context::Info());
+ if (!context) return hipErrorOutOfMemory;
+
+ if (context && CL_SUCCESS != context->create(nullptr)) {
+ context->release();
+ } else {
+ g_devices.push_back(context);
+ }
}
return hipSuccess;
@@ -54,6 +59,30 @@ hipError_t hipCtxCreate(hipCtx_t *ctx, unsigned int flags, hipDevice_t device)
{
HIP_INIT_API(ctx, flags, device);
+ if (static_cast(device) >= g_devices.size()) {
+ return hipErrorInvalidValue;
+ }
+
+ *ctx = reinterpret_cast(g_devices[device]);
+
+ return hipSuccess;
+}
+
+hipError_t hipCtxSetCurrent(hipCtx_t ctx)
+{
+ HIP_INIT_API(ctx);
+
+ g_context = reinterpret_cast(ctx);
+
+ return hipSuccess;
+}
+
+hipError_t hipCtxGetCurrent(hipCtx_t* ctx)
+{
+ HIP_INIT_API(ctx);
+
+ *ctx = reinterpret_cast(g_context);
+
return hipSuccess;
}
diff --git a/api/hip/hip_device.cpp b/api/hip/hip_device.cpp
index f646933bb9..66bae6174e 100644
--- a/api/hip/hip_device.cpp
+++ b/api/hip/hip_device.cpp
@@ -50,7 +50,7 @@ hipError_t hipDeviceTotalMem (size_t *bytes, hipDevice_t device) {
HIP_INIT_API(bytes, device);
- if (device < 0 || device > (cl_int)g_context->devices().size()) {
+ if (device < 0 || static_cast(device) >= g_devices.size()) {
return hipErrorInvalidDevice;
}
@@ -58,7 +58,7 @@ hipError_t hipDeviceTotalMem (size_t *bytes, hipDevice_t device) {
return hipErrorInvalidValue;
}
- auto* deviceHandle = g_context->devices()[device];
+ auto* deviceHandle = g_devices[device]->devices()[0];
const auto& info = deviceHandle->info();
*bytes = info.globalMemSize_;
@@ -70,7 +70,7 @@ hipError_t hipDeviceComputeCapability(int *major, int *minor, hipDevice_t device
HIP_INIT_API(major, minor, device);
- if (device < 0 || device > (cl_int)g_context->devices().size()) {
+ if (device < 0 || static_cast(device) >= g_devices.size()) {
return hipErrorInvalidDevice;
}
@@ -78,7 +78,7 @@ hipError_t hipDeviceComputeCapability(int *major, int *minor, hipDevice_t device
return hipErrorInvalidValue;
}
- auto* deviceHandle = g_context->devices()[device];
+ auto* deviceHandle = g_devices[device]->devices()[0];
const auto& info = deviceHandle->info();
*major = info.gfxipVersion_ / 100;
*minor = info.gfxipVersion_ % 100;
@@ -94,7 +94,7 @@ hipError_t hipDeviceGetCount(int* count) {
}
// Get all available devices
- *count = g_context->devices().size();
+ *count = g_devices.size();
return hipSuccess;
}
@@ -103,7 +103,7 @@ hipError_t hipDeviceGetName(char *name, int len, hipDevice_t device) {
HIP_INIT_API((void*)name, len, device);
- if (device < 0 || device > (cl_int)g_context->devices().size()) {
+ if (device < 0 || static_cast(device) >= g_devices.size()) {
return hipErrorInvalidDevice;
}
@@ -111,7 +111,7 @@ hipError_t hipDeviceGetName(char *name, int len, hipDevice_t device) {
return hipErrorInvalidValue;
}
- auto* deviceHandle = g_context->devices()[device];
+ auto* deviceHandle = g_devices[device]->devices()[0];
const auto& info = deviceHandle->info();
len = ((cl_uint)len < ::strlen(info.boardName_)) ? len : 128;
@@ -127,10 +127,10 @@ hipError_t hipGetDeviceProperties ( hipDeviceProp_t* props, hipDevice_t device )
return hipErrorInvalidValue;
}
- if (unsigned(device) >= g_context->devices().size()) {
+ if (unsigned(device) >= g_devices.size()) {
return hipErrorInvalidDevice;
}
- auto* deviceHandle = g_context->devices()[device];
+ auto* deviceHandle = g_devices[device]->devices()[0];
hipDeviceProp_t deviceProps = {0};
diff --git a/api/hip/hip_internal.hpp b/api/hip/hip_internal.hpp
index 159c7671ec..ba9446f2c1 100644
--- a/api/hip/hip_internal.hpp
+++ b/api/hip/hip_internal.hpp
@@ -36,7 +36,8 @@ THE SOFTWARE.
#define HIP_INIT_API(...) \
HIP_INIT()
-extern amd::Context* g_context;
+extern thread_local amd::Context* g_context;
+extern std::vector g_devices;
hipError_t hipDeviceGetCount(int* count);
From 8e99c0960b63769ff49e4d28fefe09f3a6fcfd6f Mon Sep 17 00:00:00 2001
From: foreman
Date: Fri, 23 Mar 2018 00:19:22 -0400
Subject: [PATCH 011/282] P4 to Git Change 1531138 by
cpaquot@cpaquot-ocl-lc-lnx on 2018/03/23 00:10:40
SWDEV-145570 - [HIP] Module
Check for correct device id in hipDeviceGetAttribute
Implement hipModuleLoad
Handle kernelParams in hipModuleLaunchKernel
Affected files ...
... //depot/stg/opencl/drivers/opencl/api/hip/hip_device.cpp#8 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_device_runtime.cpp#3 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_internal.hpp#5 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_module.cpp#3 edit
---
api/hip/hip_device.cpp | 4 ++++
api/hip/hip_device_runtime.cpp | 17 +++++++-------
api/hip/hip_internal.hpp | 2 +-
api/hip/hip_module.cpp | 41 +++++++++++++++++++++++++++++-----
4 files changed, 49 insertions(+), 15 deletions(-)
diff --git a/api/hip/hip_device.cpp b/api/hip/hip_device.cpp
index 66bae6174e..efb77fb7b0 100644
--- a/api/hip/hip_device.cpp
+++ b/api/hip/hip_device.cpp
@@ -89,6 +89,10 @@ hipError_t hipDeviceComputeCapability(int *major, int *minor, hipDevice_t device
hipError_t hipDeviceGetCount(int* count) {
HIP_INIT_API(count);
+ return ihipDeviceGetCount(count);
+}
+
+hipError_t ihipDeviceGetCount(int* count) {
if (count == nullptr) {
return hipErrorInvalidValue;
}
diff --git a/api/hip/hip_device_runtime.cpp b/api/hip/hip_device_runtime.cpp
index bbd0838f76..4d8ac9cec0 100644
--- a/api/hip/hip_device_runtime.cpp
+++ b/api/hip/hip_device_runtime.cpp
@@ -35,7 +35,7 @@ hipError_t hipChooseDevice(int* device, const hipDeviceProp_t* properties) {
*device = 0;
cl_uint maxMatchedCount = 0;
int count = 0;
- hipDeviceGetCount(&count);
+ ihipDeviceGetCount(&count);
for (cl_int i = 0; i< count; ++i) {
hipDeviceProp_t currentProp = {0};
@@ -146,10 +146,11 @@ hipError_t hipDeviceGetAttribute(int* pi, hipDeviceAttribute_t attr, int device)
return hipErrorInvalidValue;
}
- //if (unsigned(device) >= g_context->devices().size()) {
- // return hipErrorInvalidDevice;
- //}
- //auto* deviceHandle = g_context->devices()[device];
+ int count = 0;
+ ihipDeviceGetCount(&count);
+ if (device < 0 || device >= count) {
+ return hipErrorInvalidDevice;
+ }
//FIXME: should we cache the props, or just select from deviceHandle->info_?
hipDeviceProp_t prop = {0};
@@ -253,7 +254,7 @@ hipError_t hipDeviceGetByPCIBusId(int* device, const char*pciBusIdstr) {
if (sscanf (pciBusIdstr, "%04x:%02x:%02x", &pciDomainID, &pciBusID, &pciDeviceID) == 0x3) {
int count = 0;
- hipDeviceGetCount(&count);
+ ihipDeviceGetCount(&count);
for (cl_int i = 0; i < count; i++) {
int pi = 0;
hipDevice_t dev;
@@ -312,7 +313,7 @@ hipError_t hipDeviceGetPCIBusId ( char* pciBusId, int len, int device ) {
HIP_INIT_API((void*)pciBusId, len, device);
int count;
- hipDeviceGetCount(&count);
+ ihipDeviceGetCount(&count);
if (device < 0 || device > count) {
return hipErrorInvalidDevice;
}
@@ -393,7 +394,7 @@ hipError_t hipGetDevice ( int* deviceId ) {
hipError_t hipGetDeviceCount ( int* count ) {
HIP_INIT_API(count);
- return hipDeviceGetCount(count);
+ return ihipDeviceGetCount(count);
}
hipError_t hipGetDeviceFlags ( unsigned int* flags ) {
diff --git a/api/hip/hip_internal.hpp b/api/hip/hip_internal.hpp
index ba9446f2c1..239538e613 100644
--- a/api/hip/hip_internal.hpp
+++ b/api/hip/hip_internal.hpp
@@ -39,6 +39,6 @@ THE SOFTWARE.
extern thread_local amd::Context* g_context;
extern std::vector g_devices;
-hipError_t hipDeviceGetCount(int* count);
+hipError_t ihipDeviceGetCount(int* count);
#endif // HIP_SRC_HIP_INTERNAL_H
diff --git a/api/hip/hip_module.cpp b/api/hip/hip_module.cpp
index fd7729c6e5..6fd0cc9ac9 100644
--- a/api/hip/hip_module.cpp
+++ b/api/hip/hip_module.cpp
@@ -22,10 +22,13 @@ THE SOFTWARE.
#include
#include
+#include
#include "hip_internal.hpp"
#include "platform/program.hpp"
+hipError_t ihipModuleLoadData(hipModule_t *module, const void *image);
+
static uint64_t ElfSize(const void *emi)
{
const Elf64_Ehdr *ehdr = (const Elf64_Ehdr*)emi;
@@ -51,9 +54,19 @@ hipError_t hipModuleLoad(hipModule_t *module, const char *fname)
{
HIP_INIT_API(module, fname);
- assert(0 && "Unimplemented");
+ if (!fname) {
+ return hipErrorInvalidValue;
+ }
- return hipErrorUnknown;
+ std::ifstream file{fname};
+
+ if (!file.is_open()) {
+ return hipErrorFileNotFound;
+ }
+
+ std::vector tmp{std::istreambuf_iterator{file}, std::istreambuf_iterator{}};
+
+ return ihipModuleLoadData(module, tmp.data());
}
@@ -61,15 +74,26 @@ hipError_t hipModuleUnload(hipModule_t hmod)
{
HIP_INIT_API(hmod);
- assert(0 && "Unimplemented");
+ if (hmod == nullptr) {
+ return hipErrorUnknown;
+ }
- return hipErrorUnknown;
+ amd::Program* program = as_amd(reinterpret_cast(hmod));
+
+ program->release();
+
+ return hipSuccess;
}
hipError_t hipModuleLoadData(hipModule_t *module, const void *image)
{
HIP_INIT_API(module, image);
+ return ihipModuleLoadData(module, image);
+}
+
+hipError_t ihipModuleLoadData(hipModule_t *module, const void *image)
+{
amd::Program* program = new amd::Program(*g_context);
if (program == NULL) {
return hipErrorOutOfMemory;
@@ -133,11 +157,16 @@ hipError_t hipModuleLaunchKernel(hipFunction_t f,
amd::NDRangeContainer ndrange(3, globalWorkOffset, globalWorkSize, localWorkSize);
amd::Command::EventWaitList waitList;
- assert(!kernelParams && extra && "check this code");
const amd::KernelSignature& signature = kernel->signature();
for (size_t i = 0; i < signature.numParameters(); ++i) {
const amd::KernelParameterDescriptor& desc = signature.at(i);
- kernel->parameters().set(i, desc.size_, reinterpret_cast(extra[1]) + desc.offset_);
+ if (kernelParams == nullptr) {
+ assert(extra);
+ kernel->parameters().set(i, desc.size_, reinterpret_cast(extra[1]) + desc.offset_);
+ } else {
+ assert(!extra);
+ kernel->parameters().set(i, desc.size_, kernelParams[i]);
+ }
}
amd::NDRangeKernelCommand* command = new amd::NDRangeKernelCommand(*queue, waitList, *kernel, ndrange);
From a2b71e69ef4cb2fdbac4ddb9ebc24816a4c0bd54 Mon Sep 17 00:00:00 2001
From: foreman
Date: Fri, 23 Mar 2018 14:18:27 -0400
Subject: [PATCH 012/282] P4 to Git Change 1531535 by skudchad@skudchad_rocm on
2018/03/23 13:57:49
SWDEV-145570 - [HIP] Add some context* functions. Add context stack.
Affected files ...
... //depot/stg/opencl/drivers/opencl/api/hip/hip_context.cpp#4 edit
---
api/hip/hip_context.cpp | 80 +++++++++++++++++++++++++++++++++++++++--
1 file changed, 77 insertions(+), 3 deletions(-)
diff --git a/api/hip/hip_context.cpp b/api/hip/hip_context.cpp
index 2a67898bf3..983dc9b13c 100644
--- a/api/hip/hip_context.cpp
+++ b/api/hip/hip_context.cpp
@@ -21,13 +21,14 @@ THE SOFTWARE.
*/
#include
-
#include "hip_internal.hpp"
#include "platform/runtime.hpp"
#include "utils/versions.hpp"
-
+#include
thread_local amd::Context* g_context = nullptr;
+thread_local std::stack g_ctxtStack;
+
std::vector g_devices;
hipError_t hipInit(unsigned int flags)
@@ -65,6 +66,9 @@ hipError_t hipCtxCreate(hipCtx_t *ctx, unsigned int flags, hipDevice_t device)
*ctx = reinterpret_cast(g_devices[device]);
+ // Increment ref count for device primary context
+ g_devices[device]->retain();
+
return hipSuccess;
}
@@ -72,7 +76,17 @@ hipError_t hipCtxSetCurrent(hipCtx_t ctx)
{
HIP_INIT_API(ctx);
- g_context = reinterpret_cast(ctx);
+ if (ctx == nullptr) {
+ if(!g_ctxtStack.empty()) {
+ g_ctxtStack.pop();
+ }
+ } else {
+ g_context = reinterpret_cast(as_amd(ctx));
+ if(!g_ctxtStack.empty()) {
+ g_ctxtStack.pop();
+ }
+ g_ctxtStack.push(g_context);
+ }
return hipSuccess;
}
@@ -98,3 +112,63 @@ hipError_t hipRuntimeGetVersion(int *runtimeVersion)
return hipSuccess;
}
+
+hipError_t hipCtxDestroy(hipCtx_t ctx)
+{
+ HIP_INIT_API(ctx);
+
+ amd::Context* amdContext = reinterpret_cast(as_amd(ctx));
+ if (amdContext == nullptr) {
+ return hipErrorInvalidValue;
+ }
+
+ // Need to remove the ctx of calling thread if its the top one
+ if (g_context == amdContext) {
+ g_ctxtStack.pop();
+ }
+
+ // Remove context from global context list
+ for (unsigned int i = 0; i < g_devices.size(); i++) {
+ if (g_devices[i] == amdContext) {
+ // Decrement ref count for device primary context
+ amdContext->release();
+ }
+ }
+
+ return hipSuccess;
+}
+
+
+hipError_t hipCtxPopCurrent(hipCtx_t* ctx)
+{
+ HIP_INIT_API(ctx);
+
+ amd::Context* amdContext = reinterpret_cast(as_amd(ctx));
+ if (amdContext == nullptr) {
+ return hipErrorInvalidContext;
+ }
+
+ if (!g_ctxtStack.empty()) {
+ amdContext = g_ctxtStack.top();
+ g_ctxtStack.pop();
+ } else {
+ return hipErrorInvalidContext;
+ }
+
+ return hipSuccess;
+}
+
+hipError_t hipCtxPushCurrent(hipCtx_t ctx)
+{
+ HIP_INIT_API(ctx);
+
+ amd::Context* amdContext = reinterpret_cast(as_amd(ctx));
+ if (amdContext == nullptr) {
+ return hipErrorInvalidContext;
+ }
+
+ g_context = amdContext;
+ g_ctxtStack.push(g_context);
+
+ return hipSuccess;
+}
\ No newline at end of file
From 01c8c585f4d4a94f06bee402e5aeac6ebad3d120 Mon Sep 17 00:00:00 2001
From: foreman
Date: Wed, 28 Mar 2018 19:23:57 -0400
Subject: [PATCH 013/282] P4 to Git Change 1534050 by
lmoriche@lmoriche_opencl_dev2 on 2018/03/28 19:09:26
SWDEV-145570 - Add support for clang offload bundles
Affected files ...
... //depot/stg/opencl/drivers/opencl/api/hip/hip_context.cpp#5 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_internal.hpp#6 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_platform.cpp#3 edit
---
api/hip/hip_context.cpp | 18 +++++--
api/hip/hip_internal.hpp | 20 ++++---
api/hip/hip_platform.cpp | 111 +++++++++++++++++++++++++++++++--------
3 files changed, 116 insertions(+), 33 deletions(-)
diff --git a/api/hip/hip_context.cpp b/api/hip/hip_context.cpp
index 983dc9b13c..9603b938b6 100644
--- a/api/hip/hip_context.cpp
+++ b/api/hip/hip_context.cpp
@@ -25,16 +25,16 @@ THE SOFTWARE.
#include "platform/runtime.hpp"
#include "utils/versions.hpp"
#include
+#include
thread_local amd::Context* g_context = nullptr;
thread_local std::stack g_ctxtStack;
std::vector g_devices;
+std::once_flag g_ihipInitialized;
-hipError_t hipInit(unsigned int flags)
+void ihipInit()
{
- HIP_INIT_API(flags);
-
if (!amd::Runtime::initialized()) {
amd::Runtime::init();
}
@@ -44,18 +44,26 @@ hipError_t hipInit(unsigned int flags)
for (unsigned int i=0; i device(1, devices[i]);
amd::Context* context = new amd::Context(device, amd::Context::Info());
- if (!context) return hipErrorOutOfMemory;
+ if (!context) return;
if (context && CL_SUCCESS != context->create(nullptr)) {
context->release();
} else {
g_devices.push_back(context);
+ g_context = context;
}
}
+}
+
+
+hipError_t hipInit(unsigned int flags)
+{
+ HIP_INIT_API(flags);
return hipSuccess;
}
+
hipError_t hipCtxCreate(hipCtx_t *ctx, unsigned int flags, hipDevice_t device)
{
HIP_INIT_API(ctx, flags, device);
@@ -171,4 +179,4 @@ hipError_t hipCtxPushCurrent(hipCtx_t ctx)
g_ctxtStack.push(g_context);
return hipSuccess;
-}
\ No newline at end of file
+}
diff --git a/api/hip/hip_internal.hpp b/api/hip/hip_internal.hpp
index 239538e613..3d334fa2ac 100644
--- a/api/hip/hip_internal.hpp
+++ b/api/hip/hip_internal.hpp
@@ -25,20 +25,26 @@ THE SOFTWARE.
#include "cl_common.hpp"
-#define HIP_INIT()\
+#include
+
+#define HIP_INIT() \
+ std::call_once(g_ihipInitialized, ihipInit);
+
+
+// This macro should be called at the beginning of every HIP API.
+#define HIP_INIT_API(...) \
+ HIP_INIT(); \
+ \
amd::Thread* thread = amd::Thread::current(); \
if (!CL_CHECK_THREAD(thread)) { \
return hipErrorOutOfMemory; \
}
-
-// This macro should be called at the beginning of every HIP API.
-#define HIP_INIT_API(...) \
- HIP_INIT()
-
+extern std::once_flag g_ihipInitialized;
extern thread_local amd::Context* g_context;
extern std::vector g_devices;
-hipError_t ihipDeviceGetCount(int* count);
+extern hipError_t ihipDeviceGetCount(int* count);
+extern void ihipInit();
#endif // HIP_SRC_HIP_INTERNAL_H
diff --git a/api/hip/hip_platform.cpp b/api/hip/hip_platform.cpp
index 0cc6a3b1c2..db7939c9e7 100644
--- a/api/hip/hip_platform.cpp
+++ b/api/hip/hip_platform.cpp
@@ -44,7 +44,7 @@ struct __CudaFatBinaryHeader {
unsigned long long int fatSize;
};
-struct __CudaPartHeader{
+struct __CudaPartHeader {
unsigned short type;
unsigned short dummy1;
unsigned int headerSize;
@@ -54,31 +54,20 @@ struct __CudaPartHeader{
unsigned int subarch;
};
-extern "C" hipModule_t __hipRegisterFatBinary(void* bundle)
+static hipModule_t registerCudaFatBinary(const __CudaFatBinaryHeader* fbheader)
{
- if (!amd::Runtime::initialized()) { // FIXME: fix initialization
- hipInit(0);
- }
+ const __CudaPartHeader* pheader = reinterpret_cast(
+ reinterpret_cast(fbheader) + fbheader->headerSize);
+ const __CudaPartHeader* end = reinterpret_cast(
+ reinterpret_cast(pheader) + fbheader->fatSize);
amd::Program* program = new amd::Program(*g_context);
if (!program) return nullptr;
- struct __CudaFatBinaryWrapper* fbwrapper = (struct __CudaFatBinaryWrapper*)bundle;
- if (fbwrapper->magic != __cudaFatMAGIC2 || fbwrapper->version != 1) {
- return nullptr;
- }
- struct __CudaFatBinaryHeader* fbheader = (struct __CudaFatBinaryHeader*)fbwrapper->binary;
- if (fbheader->magic != __cudaFatMAGIC3 || fbheader->version != 1) {
- return nullptr;
- }
- struct __CudaPartHeader* pheader = (struct __CudaPartHeader*)(
- (uintptr_t)fbheader + fbheader->headerSize);
- struct __CudaPartHeader* end = (struct __CudaPartHeader*)(
- (uintptr_t)pheader + fbheader->fatSize);
-
while (pheader < end) {
if (true/*pheader->subarch == match a device in the context*/) {
- void *image = (void*)((uintptr_t)pheader + pheader->headerSize);
+ const void *image = reinterpret_cast(
+ reinterpret_cast(pheader) + pheader->headerSize);
size_t size = pheader->partSize;
if (CL_SUCCESS != program->addDeviceProgram(*g_context->devices()[0], image, size) ||
CL_SUCCESS != program->build(g_context->devices(), nullptr, nullptr, nullptr)) {
@@ -86,13 +75,83 @@ extern "C" hipModule_t __hipRegisterFatBinary(void* bundle)
}
break;
}
- pheader = (struct __CudaPartHeader*)(
- (uintptr_t)pheader + pheader->headerSize + pheader->partSize);
+ pheader = reinterpret_cast(
+ reinterpret_cast(pheader) + pheader->headerSize + pheader->partSize);
}
return reinterpret_cast(as_cl(program));
}
+#define CLANG_OFFLOAD_BUNDLER_MAGIC_STR "__CLANG_OFFLOAD_BUNDLE__"
+#define AMDGCN_AMDHSA_TRIPLE "openmp-amdgcn--amdhsa"
+
+struct __ClangOffloadBundleDesc {
+ uint64_t offset;
+ uint64_t size;
+ uint64_t tripleSize;
+ const char triple[1];
+};
+
+struct __ClangOffloadBundleHeader {
+ const char magic[sizeof(CLANG_OFFLOAD_BUNDLER_MAGIC_STR) - 1];
+ uint64_t numBundles;
+ __ClangOffloadBundleDesc desc[1];
+};
+
+static hipModule_t registerOffloadBundle(const __ClangOffloadBundleHeader* obheader)
+{
+ amd::Program* program = new amd::Program(*g_context);
+ if (!program)
+ return nullptr;
+
+ const __ClangOffloadBundleDesc* desc = &obheader->desc[0];
+ for (uint64_t i = 0; i < obheader->numBundles; ++i,
+ desc = reinterpret_cast(
+ reinterpret_cast(&desc->triple[0]) + desc->tripleSize)) {
+
+ std::string triple(desc->triple, sizeof(AMDGCN_AMDHSA_TRIPLE) - 1);
+ if (triple.compare(AMDGCN_AMDHSA_TRIPLE))
+ continue;
+
+ std::string target(desc->triple + sizeof(AMDGCN_AMDHSA_TRIPLE),
+ desc->tripleSize - sizeof(AMDGCN_AMDHSA_TRIPLE));
+ if (target.compare(g_context->devices()[0]->info().name_))
+ continue;
+
+ const void *image = reinterpret_cast(
+ reinterpret_cast(obheader) + desc->offset);
+ size_t size = desc->size;
+
+ if (CL_SUCCESS == program->addDeviceProgram(*g_context->devices()[0], image, size) &&
+ CL_SUCCESS == program->build(g_context->devices(), nullptr, nullptr, nullptr))
+ break;
+ }
+
+ return reinterpret_cast(as_cl(program));
+}
+
+
+extern "C" hipModule_t __hipRegisterFatBinary(const void* data)
+{
+ HIP_INIT();
+
+ const __CudaFatBinaryWrapper* fbwrapper = reinterpret_cast(data);
+ if (fbwrapper->magic != __cudaFatMAGIC2 || fbwrapper->version != 1) {
+ return nullptr;
+ }
+ const __CudaFatBinaryHeader* fbheader = reinterpret_cast(fbwrapper->binary);
+ if (fbheader->magic == __cudaFatMAGIC3 && fbheader->version == 1) {
+ return registerCudaFatBinary(fbheader);
+ }
+
+ std::string magic((char*)fbwrapper->binary, sizeof(CLANG_OFFLOAD_BUNDLER_MAGIC_STR) - 1);
+ if (!magic.compare(CLANG_OFFLOAD_BUNDLER_MAGIC_STR)) {
+ return registerOffloadBundle(reinterpret_cast(fbwrapper->binary));
+ }
+
+ return nullptr;
+}
+
std::map g_functions;
@@ -108,6 +167,8 @@ extern "C" void __hipRegisterFunction(
dim3* gridDim,
int* wSize)
{
+ HIP_INIT();
+
amd::Program* program = as_amd(reinterpret_cast(module));
const amd::Symbol* symbol = program->findSymbol(deviceName);
@@ -130,12 +191,14 @@ extern "C" void __hipRegisterVar(
int constant,
int global)
{
+ HIP_INIT();
}
extern "C" void __hipUnregisterFatBinary(
hipModule_t module
)
{
+ HIP_INIT();
}
dim3 g_gridDim; // FIXME: place in execution stack
@@ -149,6 +212,8 @@ extern "C" hipError_t hipConfigureCall(
size_t sharedMem,
hipStream_t stream)
{
+ HIP_INIT_API(gridDim, blockDim, sharedMem, stream);
+
// FIXME: should push and new entry on the execution stack
g_gridDim = gridDim;
@@ -166,6 +231,8 @@ extern "C" hipError_t hipSetupArgument(
size_t size,
size_t offset)
{
+ HIP_INIT_API(arg, size, offset);
+
// FIXME: should modify the top of the execution stack
::memcpy(g_arguments + offset, arg, size);
@@ -174,6 +241,8 @@ extern "C" hipError_t hipSetupArgument(
extern "C" hipError_t hipLaunchByPtr(const void *hostFunction)
{
+ HIP_INIT_API(hostFunction);
+
std::map::iterator it;
if ((it = g_functions.find(hostFunction)) == g_functions.end())
return hipErrorUnknown;
From dd4b3806610eab9a7b3921aede99253eb4801b62 Mon Sep 17 00:00:00 2001
From: foreman
Date: Fri, 30 Mar 2018 01:06:00 -0400
Subject: [PATCH 014/282] P4 to Git Change 1534798 by
cpaquot@cpaquot-ocl-lc-lnx on 2018/03/30 00:56:35
SWDEV-145570 - [HIP] Implemented hipStream create/destroy
Use the provided stream in hipModuleLaunchKernel
Affected files ...
... //depot/stg/opencl/drivers/opencl/api/hip/hip_module.cpp#4 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_stream.cpp#2 edit
---
api/hip/hip_module.cpp | 7 ++-----
api/hip/hip_stream.cpp | 40 ++++++++++++++++++++++++++++++----------
2 files changed, 32 insertions(+), 15 deletions(-)
diff --git a/api/hip/hip_module.cpp b/api/hip/hip_module.cpp
index 6fd0cc9ac9..0bcae3551b 100644
--- a/api/hip/hip_module.cpp
+++ b/api/hip/hip_module.cpp
@@ -144,9 +144,8 @@ hipError_t hipModuleLaunchKernel(hipFunction_t f,
amd::Kernel* kernel = as_amd(reinterpret_cast(f));
amd::Device* device = g_context->devices()[0];
- amd::HostQueue* queue = new amd::HostQueue(*g_context, *device, 0,
- amd::CommandQueue::RealTimeDisabled,
- amd::CommandQueue::Priority::Normal);
+ amd::HostQueue* queue = as_amd(reinterpret_cast(hStream))->asHostQueue();
+
if (!queue) {
return hipErrorOutOfMemory;
}
@@ -184,8 +183,6 @@ hipError_t hipModuleLaunchKernel(hipFunction_t f,
command->awaitCompletion();
command->release();
- queue->release();
-
return hipSuccess;
}
diff --git a/api/hip/hip_stream.cpp b/api/hip/hip_stream.cpp
index efecb5174d..46014ebfef 100644
--- a/api/hip/hip_stream.cpp
+++ b/api/hip/hip_stream.cpp
@@ -24,13 +24,30 @@ THE SOFTWARE.
#include "hip_internal.hpp"
+static hipError_t ihipStreamCreateWithFlags(hipStream_t *stream, unsigned int flags)
+{
+ assert(flags == 0); // we don't handle flags yet
+
+ amd::Device* device = g_context->devices()[0];
+
+ amd::HostQueue* queue = new amd::HostQueue(*g_context, *device, 0,
+ amd::CommandQueue::RealTimeDisabled,
+ amd::CommandQueue::Priority::Normal);
+
+ if (queue == nullptr) {
+ return hipErrorOutOfMemory;
+ }
+
+ *stream = reinterpret_cast(as_cl(queue));
+
+ return hipSuccess;
+}
+
hipError_t hipStreamCreateWithFlags(hipStream_t *stream, unsigned int flags)
{
HIP_INIT_API(stream, flags);
- assert(0 && "Unimplemented");
-
- return hipErrorUnknown;
+ return ihipStreamCreateWithFlags(stream, flags);
}
@@ -38,9 +55,7 @@ hipError_t hipStreamCreate(hipStream_t *stream)
{
HIP_INIT_API(stream);
- assert(0 && "Unimplemented");
-
- return hipErrorUnknown;
+ return ihipStreamCreateWithFlags(stream, hipStreamDefault);
}
@@ -58,9 +73,14 @@ hipError_t hipStreamSynchronize(hipStream_t stream)
{
HIP_INIT_API(stream);
- assert(0 && "Unimplemented");
+ amd::HostQueue* hostQueue = as_amd(reinterpret_cast(stream))->asHostQueue();
+ if (hostQueue == nullptr) {
+ return hipErrorUnknown;
+ }
- return hipErrorUnknown;
+ hostQueue->finish();
+
+ return hipSuccess;
}
@@ -68,9 +88,9 @@ hipError_t hipStreamDestroy(hipStream_t stream)
{
HIP_INIT_API(stream);
- assert(0 && "Unimplemented");
+ as_amd(reinterpret_cast(stream))->release();
- return hipErrorUnknown;
+ return hipSuccess;
}
From 4574e017404668dc524fcd7477127d9c8ecec85f Mon Sep 17 00:00:00 2001
From: foreman
Date: Wed, 4 Apr 2018 13:24:15 -0400
Subject: [PATCH 015/282] P4 to Git Change 1536698 by
skudchad@skudchad_test2_win_opencl on 2018/04/04 13:18:19
SWDEV-145570 - [HIP] - Add HIP Memory api skeletons
ReviewBoardURL = http://ocltc.amd.com/reviews/r/14555/diff/
Affected files ...
... //depot/stg/opencl/drivers/opencl/api/hip/hip_device_runtime.cpp#4 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_memory.cpp#6 edit
---
api/hip/hip_device_runtime.cpp | 24 ---
api/hip/hip_memory.cpp | 371 +++++++++++++++++++++++++++++++--
2 files changed, 357 insertions(+), 38 deletions(-)
diff --git a/api/hip/hip_device_runtime.cpp b/api/hip/hip_device_runtime.cpp
index 4d8ac9cec0..7c5c063ea6 100644
--- a/api/hip/hip_device_runtime.cpp
+++ b/api/hip/hip_device_runtime.cpp
@@ -401,14 +401,6 @@ hipError_t hipGetDeviceFlags ( unsigned int* flags ) {
return hipErrorUnknown;
}
-hipError_t hipIpcCloseMemHandle ( void* devPtr ) {
- HIP_INIT_API(devPtr);
-
- assert(0 && "Unimplemented");
-
- return hipErrorUnknown;
-}
-
hipError_t hipIpcGetEventHandle ( hipIpcEventHandle_t* handle, hipEvent_t event ) {
HIP_INIT_API(handle, event);
@@ -417,14 +409,6 @@ hipError_t hipIpcGetEventHandle ( hipIpcEventHandle_t* handle, hipEvent_t event
return hipErrorUnknown;
}
-hipError_t hipIpcGetMemHandle ( hipIpcMemHandle_t* handle, void* devPtr ) {
- HIP_INIT_API(handle, devPtr);
-
- assert(0 && "Unimplemented");
-
- return hipErrorUnknown;
-}
-
hipError_t hipIpcOpenEventHandle ( hipEvent_t* event, hipIpcEventHandle_t handle ) {
HIP_INIT_API(event, handle);
@@ -433,14 +417,6 @@ hipError_t hipIpcOpenEventHandle ( hipEvent_t* event, hipIpcEventHandle_t handle
return hipErrorUnknown;
}
-hipError_t hipIpcOpenMemHandle ( void** devPtr, hipIpcMemHandle_t handle, unsigned int flags ) {
- HIP_INIT_API(devPtr, handle, flags);
-
- assert(0 && "Unimplemented");
-
- return hipErrorUnknown;
-}
-
hipError_t hipSetDevice ( int device ) {
HIP_INIT_API(device);
diff --git a/api/hip/hip_memory.cpp b/api/hip/hip_memory.cpp
index ddebc8623c..1fc000bf1d 100644
--- a/api/hip/hip_memory.cpp
+++ b/api/hip/hip_memory.cpp
@@ -91,20 +91,6 @@ hipError_t hipFree(void* ptr)
return hipSuccess;
}
-hipError_t hipMemcpyAsync(void* dst,
- const void* src,
- size_t sizeBytes,
- hipMemcpyKind kind,
- hipStream_t stream)
-{
- HIP_INIT_API(dst, src, sizeBytes, kind, stream);
-
- assert(0 && "Unimplemented");
-
- return hipErrorUnknown;
-}
-
-
hipError_t hipMemcpy(void* dst, const void* src, size_t sizeBytes, hipMemcpyKind kind)
{
HIP_INIT_API(dst, src, sizeBytes, kind);
@@ -182,3 +168,360 @@ hipError_t hipMemPtrGetInfo(void *ptr, size_t *size)
return hipErrorUnknown;
}
+
+hipError_t hipHostFree(void* ptr)
+{
+ HIP_INIT_API(ptr);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipFreeArray(hipArray* array)
+{
+ HIP_INIT_API(array);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipMemGetAddressRange(hipDeviceptr_t* pbase, size_t* psize, hipDeviceptr_t dptr)
+{
+ HIP_INIT_API(pbase, psize, dptr);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipMemGetInfo(size_t* free, size_t* total)
+{
+ HIP_INIT_API(free, total);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipMallocPitch(void** ptr, size_t* pitch, size_t width, size_t height)
+{
+ HIP_INIT_API(ptr, pitch, width, height);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipMalloc3D(hipPitchedPtr* pitchedDevPtr, hipExtent extent)
+{
+ HIP_INIT_API(pitchedDevPtr, &extent);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipArrayCreate(hipArray** array, const HIP_ARRAY_DESCRIPTOR* pAllocateArray)
+{
+ HIP_INIT_API(array, pAllocateArray);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipMallocArray(hipArray** array, const hipChannelFormatDesc* desc,
+ size_t width, size_t height, unsigned int flags)
+{
+ HIP_INIT_API(array, desc, width, height, flags);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipMalloc3DArray(hipArray_t* array, const struct hipChannelFormatDesc* desc,
+ struct hipExtent extent, unsigned int flags)
+{
+ HIP_INIT_API(array, desc, &extent, flags);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipHostGetFlags(unsigned int* flagsPtr, void* hostPtr)
+{
+ HIP_INIT_API(flagsPtr, hostPtr);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipHostRegister(void* hostPtr, size_t sizeBytes, unsigned int flags)
+{
+ HIP_INIT_API(hostPtr, sizeBytes, flags);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipHostUnregister(void* hostPtr)
+{
+ HIP_INIT_API(hostPtr);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipMemcpyToSymbol(const void* symbolName, const void* src, size_t count,
+ size_t offset, hipMemcpyKind kind)
+{
+ HIP_INIT_API(symbolName, src, count, offset, kind);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipMemcpyFromSymbol(void* dst, const void* symbolName, size_t count,
+ size_t offset, hipMemcpyKind kind)
+{
+ HIP_INIT_API(symbolName, dst, count, offset, kind);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipMemcpyToSymbolAsync(const void* symbolName, const void* src, size_t count,
+ size_t offset, hipMemcpyKind kind, hipStream_t stream)
+{
+ HIP_INIT_API(symbolName, src, count, offset, kind, stream);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipMemcpyFromSymbolAsync(void* dst, const void* symbolName, size_t count,
+ size_t offset, hipMemcpyKind kind, hipStream_t stream)
+{
+ HIP_INIT_API(symbolName, dst, count, offset, kind, stream);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipMemcpyHtoD(hipDeviceptr_t dst, void* src, size_t sizeBytes)
+{
+ HIP_INIT_API(dst, src, sizeBytes);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipMemcpyDtoH(void* dst, hipDeviceptr_t src, size_t sizeBytes)
+{
+ HIP_INIT_API(dst, src, sizeBytes);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipMemcpyDtoD(hipDeviceptr_t dst, hipDeviceptr_t src, size_t sizeBytes)
+{
+ HIP_INIT_API(dst, src, sizeBytes);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipMemcpyHtoH(void* dst, void* src, size_t sizeBytes)
+{
+ HIP_INIT_API(dst, src, sizeBytes);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipMemcpyAsync(void* dst, const void* src, size_t sizeBytes,
+ hipMemcpyKind kind, hipStream_t stream)
+{
+ HIP_INIT_API(dst, src, sizeBytes, kind, stream);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+
+hipError_t hipMemcpyHtoDAsync(hipDeviceptr_t dst, void* src, size_t sizeBytes,
+ hipStream_t stream)
+{
+ HIP_INIT_API(dst, src, sizeBytes, stream);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipMemcpyDtoDAsync(hipDeviceptr_t dst, hipDeviceptr_t src, size_t sizeBytes,
+ hipStream_t stream)
+{
+ HIP_INIT_API(dst, src, sizeBytes, stream);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipMemcpyDtoHAsync(void* dst, hipDeviceptr_t src, size_t sizeBytes,
+ hipStream_t stream)
+{
+ HIP_INIT_API(dst, src, sizeBytes, stream);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipMemcpy2D(void* dst, size_t dpitch, const void* src, size_t spitch, size_t width,
+ size_t height, hipMemcpyKind kind)
+{
+ HIP_INIT_API(dst, dpitch, src, spitch, width, height, kind);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipMemcpyParam2D(const hip_Memcpy2D* pCopy)
+{
+ HIP_INIT_API(pCopy);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipMemcpy2DAsync(void* dst, size_t dpitch, const void* src, size_t spitch, size_t width,
+ size_t height, hipMemcpyKind kind, hipStream_t stream)
+{
+ HIP_INIT_API(dst, dpitch, src, spitch, width, height, kind, stream);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipMemcpy2DToArray(hipArray* dst, size_t wOffset, size_t hOffset, const void* src,
+ size_t spitch, size_t width, size_t height, hipMemcpyKind kind)
+{
+ HIP_INIT_API(dst, wOffset, hOffset, src, spitch, width, height, kind);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipMemcpyToArray(hipArray* dst, size_t wOffset, size_t hOffset, const void* src,
+ size_t count, hipMemcpyKind kind)
+{
+ HIP_INIT_API(dst, wOffset, hOffset, src, count, kind);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipMemcpyFromArray(void* dst, hipArray_const_t srcArray, size_t wOffset, size_t hOffset,
+ size_t count, hipMemcpyKind kind)
+{
+ HIP_INIT_API(dst, srcArray, wOffset, hOffset, count, kind);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipMemcpyHtoA(hipArray* dstArray, size_t dstOffset, const void* srcHost, size_t count)
+{
+ HIP_INIT_API(dstArray, dstOffset, srcHost, count);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipMemcpyAtoH(void* dst, hipArray* srcArray, size_t srcOffset, size_t count)
+{
+ HIP_INIT_API(dst, srcArray, srcOffset, count);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipMemcpy3D(const struct hipMemcpy3DParms* p)
+{
+ HIP_INIT_API(p);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipMemset2D(void* dst, size_t pitch, int value, size_t width, size_t height)
+{
+ HIP_INIT_API(dst, pitch, value, width, height);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipMemsetD8(hipDeviceptr_t dst, unsigned char value, size_t sizeBytes)
+{
+ HIP_INIT_API(dst, value, sizeBytes);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipIpcGetMemHandle(hipIpcMemHandle_t* handle, void* devPtr)
+{
+ HIP_INIT_API(handle, devPtr);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipIpcOpenMemHandle(void** devPtr, hipIpcMemHandle_t handle, unsigned int flags)
+{
+ HIP_INIT_API(devPtr, &handle, flags);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipIpcCloseMemHandle(void* devPtr) {
+ HIP_INIT_API(devPtr);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
\ No newline at end of file
From 15f11c983f38805efe7414e1e18c83b6337d453f Mon Sep 17 00:00:00 2001
From: foreman
Date: Wed, 4 Apr 2018 18:00:17 -0400
Subject: [PATCH 016/282] P4 to Git Change 1536925 by
vsytchen@vsytchen-ocl-win10 on 2018/04/04 17:20:38
SWDEV-79445 - OCL generic changes and code clean-up
1. This change replaces the use of std::map with std::unordered_map to improve lookup/insert time.
2. Replace the use of std::make_pair and std::pair constructor with uniform initialization for cleaner code.
3. Replace the use of std::Container::iterator type with the auto keyword for cleaner code.
4. Use range based for loops where needed.
ReviewBoardURL = http://ocltc.amd.com/reviews/r/14517/diff/
Affected files ...
... //depot/stg/opencl/drivers/opencl/api/hip/hip_platform.cpp#4 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_context.cpp#58 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_d3d10.cpp#16 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_d3d10_amd.hpp#9 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_d3d11.cpp#24 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_d3d11_amd.hpp#13 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_d3d9.cpp#34 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_d3d9_amd.hpp#17 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_gl.cpp#57 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_pipe.cpp#7 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_program.cpp#46 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_svm.cpp#23 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/appprofile.hpp#14 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/cpu/cpuprogram.cpp#72 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/cpu/cpuvirtual.cpp#27 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/device.cpp#216 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/device.hpp#297 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuappprofile.cpp#13 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpubinary.cpp#59 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpucompiler.cpp#158 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpudevice.cpp#587 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpukernel.cpp#322 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuprintf.cpp#46 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuprogram.cpp#237 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuprogram.hpp#70 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuresource.cpp#242 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuvirtual.cpp#415 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuvirtual.hpp#143 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palappprofile.cpp#3 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palcompiler.cpp#22 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/paldevice.cpp#79 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palprintf.cpp#9 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palprogram.cpp#59 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palresource.cpp#60 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palvirtual.cpp#84 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palvirtual.hpp#46 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/CMakeLists.txt#11 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/pro/prodevice.cpp#4 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/pro/prodevice.hpp#5 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocbinary.hpp#6 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/roccompiler.cpp#42 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/roccounters.cpp#3 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocprintf.cpp#10 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocprogram.cpp#81 edit
... //depot/stg/opencl/drivers/opencl/runtime/platform/command.cpp#81 edit
... //depot/stg/opencl/drivers/opencl/runtime/platform/command.hpp#89 edit
... //depot/stg/opencl/drivers/opencl/runtime/platform/commandqueue.cpp#24 edit
... //depot/stg/opencl/drivers/opencl/runtime/platform/context.cpp#49 edit
... //depot/stg/opencl/drivers/opencl/runtime/platform/context.hpp#29 edit
... //depot/stg/opencl/drivers/opencl/runtime/platform/memory.cpp#129 edit
... //depot/stg/opencl/drivers/opencl/runtime/platform/memory.hpp#102 edit
... //depot/stg/opencl/drivers/opencl/runtime/platform/perfctr.hpp#7 edit
... //depot/stg/opencl/drivers/opencl/runtime/platform/program.cpp#91 edit
... //depot/stg/opencl/drivers/opencl/runtime/platform/program.hpp#43 edit
... //depot/stg/opencl/drivers/opencl/runtime/platform/sampler.hpp#9 edit
... //depot/stg/opencl/drivers/opencl/runtime/utils/flags.cpp#17 edit
---
api/hip/hip_platform.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/api/hip/hip_platform.cpp b/api/hip/hip_platform.cpp
index db7939c9e7..f1c33dabde 100644
--- a/api/hip/hip_platform.cpp
+++ b/api/hip/hip_platform.cpp
@@ -243,8 +243,8 @@ extern "C" hipError_t hipLaunchByPtr(const void *hostFunction)
{
HIP_INIT_API(hostFunction);
- std::map::iterator it;
- if ((it = g_functions.find(hostFunction)) == g_functions.end())
+ const auto it = g_functions.find(hostFunction);
+ if (it == g_functions.cend())
return hipErrorUnknown;
// FIXME: should pop an entry from the execution stack
From 204ecba4b686b7491f060d2444beef18c6c84478 Mon Sep 17 00:00:00 2001
From: foreman
Date: Thu, 5 Apr 2018 15:02:43 -0400
Subject: [PATCH 017/282] P4 to Git Change 1537228 by
skudchad@skudchad_test2_win_opencl on 2018/04/05 14:53:31
SWDEV-145570 - [HIP] - Add HIP Memory, texture, surface, context api skeletons
ReviewBoardURL = http://ocltc.amd.com/reviews/r/14565/diff/
Affected files ...
... //depot/stg/opencl/drivers/opencl/api/hip/hip_context.cpp#6 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_device.cpp#9 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_event.cpp#2 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_memory.cpp#7 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_stream.cpp#3 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_surface.cpp#1 add
... //depot/stg/opencl/drivers/opencl/api/hip/hip_texture.cpp#1 add
---
api/hip/hip_context.cpp | 126 ++++++++++++++++++++-----
api/hip/hip_device.cpp | 3 +-
api/hip/hip_event.cpp | 36 ++++---
api/hip/hip_memory.cpp | 172 +++++++++++++++++-----------------
api/hip/hip_stream.cpp | 44 ++++++---
api/hip/hip_surface.cpp | 49 ++++++++++
api/hip/hip_texture.cpp | 202 ++++++++++++++++++++++++++++++++++++++++
7 files changed, 496 insertions(+), 136 deletions(-)
create mode 100644 api/hip/hip_surface.cpp
create mode 100644 api/hip/hip_texture.cpp
diff --git a/api/hip/hip_context.cpp b/api/hip/hip_context.cpp
index 9603b938b6..9bfe4ad45d 100644
--- a/api/hip/hip_context.cpp
+++ b/api/hip/hip_context.cpp
@@ -33,8 +33,7 @@ thread_local std::stack g_ctxtStack;
std::vector g_devices;
std::once_flag g_ihipInitialized;
-void ihipInit()
-{
+void ihipInit() {
if (!amd::Runtime::initialized()) {
amd::Runtime::init();
}
@@ -55,17 +54,13 @@ void ihipInit()
}
}
-
-hipError_t hipInit(unsigned int flags)
-{
+hipError_t hipInit(unsigned int flags) {
HIP_INIT_API(flags);
return hipSuccess;
}
-
-hipError_t hipCtxCreate(hipCtx_t *ctx, unsigned int flags, hipDevice_t device)
-{
+hipError_t hipCtxCreate(hipCtx_t *ctx, unsigned int flags, hipDevice_t device) {
HIP_INIT_API(ctx, flags, device);
if (static_cast(device) >= g_devices.size()) {
@@ -80,8 +75,7 @@ hipError_t hipCtxCreate(hipCtx_t *ctx, unsigned int flags, hipDevice_t device)
return hipSuccess;
}
-hipError_t hipCtxSetCurrent(hipCtx_t ctx)
-{
+hipError_t hipCtxSetCurrent(hipCtx_t ctx) {
HIP_INIT_API(ctx);
if (ctx == nullptr) {
@@ -99,8 +93,7 @@ hipError_t hipCtxSetCurrent(hipCtx_t ctx)
return hipSuccess;
}
-hipError_t hipCtxGetCurrent(hipCtx_t* ctx)
-{
+hipError_t hipCtxGetCurrent(hipCtx_t* ctx) {
HIP_INIT_API(ctx);
*ctx = reinterpret_cast(g_context);
@@ -108,8 +101,7 @@ hipError_t hipCtxGetCurrent(hipCtx_t* ctx)
return hipSuccess;
}
-hipError_t hipRuntimeGetVersion(int *runtimeVersion)
-{
+hipError_t hipRuntimeGetVersion(int *runtimeVersion) {
HIP_INIT_API(runtimeVersion);
if (!runtimeVersion) {
@@ -121,8 +113,7 @@ hipError_t hipRuntimeGetVersion(int *runtimeVersion)
return hipSuccess;
}
-hipError_t hipCtxDestroy(hipCtx_t ctx)
-{
+hipError_t hipCtxDestroy(hipCtx_t ctx) {
HIP_INIT_API(ctx);
amd::Context* amdContext = reinterpret_cast(as_amd(ctx));
@@ -146,9 +137,7 @@ hipError_t hipCtxDestroy(hipCtx_t ctx)
return hipSuccess;
}
-
-hipError_t hipCtxPopCurrent(hipCtx_t* ctx)
-{
+hipError_t hipCtxPopCurrent(hipCtx_t* ctx) {
HIP_INIT_API(ctx);
amd::Context* amdContext = reinterpret_cast(as_amd(ctx));
@@ -166,8 +155,7 @@ hipError_t hipCtxPopCurrent(hipCtx_t* ctx)
return hipSuccess;
}
-hipError_t hipCtxPushCurrent(hipCtx_t ctx)
-{
+hipError_t hipCtxPushCurrent(hipCtx_t ctx) {
HIP_INIT_API(ctx);
amd::Context* amdContext = reinterpret_cast(as_amd(ctx));
@@ -180,3 +168,99 @@ hipError_t hipCtxPushCurrent(hipCtx_t ctx)
return hipSuccess;
}
+
+hipError_t hipCtxGetDevice(hipDevice_t* device) {
+ HIP_INIT_API(device);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipCtxGetApiVersion(hipCtx_t ctx, int* apiVersion) {
+ HIP_INIT_API(apiVersion);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipCtxGetCacheConfig(hipFuncCache_t* cacheConfig) {
+ HIP_INIT_API(cacheConfig);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipCtxSetCacheConfig(hipFuncCache_t cacheConfig) {
+ HIP_INIT_API(cacheConfig);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipCtxSetSharedMemConfig(hipSharedMemConfig config) {
+ HIP_INIT_API(config);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipCtxSynchronize(void) {
+ HIP_INIT_API(1);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipCtxGetFlags(unsigned int* flags) {
+ HIP_INIT_API(flags);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipDevicePrimaryCtxGetState(hipDevice_t dev, unsigned int* flags, int* active) {
+ HIP_INIT_API(dev, flags, active);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipDevicePrimaryCtxRelease(hipDevice_t dev) {
+ HIP_INIT_API(dev);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipDevicePrimaryCtxRetain(hipCtx_t* pctx, hipDevice_t dev) {
+ HIP_INIT_API(pctx, dev);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipDevicePrimaryCtxReset(hipDevice_t dev) {
+ HIP_INIT_API(dev);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipDevicePrimaryCtxSetFlags(hipDevice_t dev, unsigned int flags) {
+ HIP_INIT_API(dev, flags);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
\ No newline at end of file
diff --git a/api/hip/hip_device.cpp b/api/hip/hip_device.cpp
index efb77fb7b0..d067cf19a8 100644
--- a/api/hip/hip_device.cpp
+++ b/api/hip/hip_device.cpp
@@ -24,8 +24,7 @@ THE SOFTWARE.
#include "hip_internal.hpp"
-hipError_t hipDeviceGet(hipDevice_t *device, int deviceId)
-{
+hipError_t hipDeviceGet(hipDevice_t *device, int deviceId) {
HIP_INIT_API(device, deviceId);
if (device != nullptr) {
diff --git a/api/hip/hip_event.cpp b/api/hip/hip_event.cpp
index 117b28355e..1fe7be9e2f 100644
--- a/api/hip/hip_event.cpp
+++ b/api/hip/hip_event.cpp
@@ -24,44 +24,56 @@ THE SOFTWARE.
#include "hip_internal.hpp"
-hipError_t hipEventCreateWithFlags(hipEvent_t* event, unsigned flags)
-{
+hipError_t hipEventCreateWithFlags(hipEvent_t* event, unsigned flags) {
HIP_INIT_API(event, flags);
+ assert(0 && "Unimplemented");
+
return hipErrorUnknown;
}
-hipError_t hipEventCreate(hipEvent_t* event)
-{
+hipError_t hipEventCreate(hipEvent_t* event) {
HIP_INIT_API(event);
+ assert(0 && "Unimplemented");
+
return hipErrorUnknown;
}
-hipError_t hipEventDestroy(hipEvent_t event)
-{
+hipError_t hipEventDestroy(hipEvent_t event) {
HIP_INIT_API(event);
+ assert(0 && "Unimplemented");
+
return hipErrorUnknown;
}
-hipError_t hipEventElapsedTime(float *ms, hipEvent_t start, hipEvent_t stop)
-{
+hipError_t hipEventElapsedTime(float *ms, hipEvent_t start, hipEvent_t stop) {
HIP_INIT_API(ms, start, stop);
return hipErrorUnknown;
}
-hipError_t hipEventRecord(hipEvent_t event, hipStream_t stream)
-{
+hipError_t hipEventRecord(hipEvent_t event, hipStream_t stream) {
HIP_INIT_API(event, stream);
+ assert(0 && "Unimplemented");
+
return hipErrorUnknown;
}
-hipError_t hipEventSynchronize(hipEvent_t event)
-{
+hipError_t hipEventSynchronize(hipEvent_t event) {
HIP_INIT_API(event);
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipEventQuery(hipEvent_t event) {
+ HIP_INIT_API(event);
+
+ assert(0 && "Unimplemented");
+
return hipErrorUnknown;
}
diff --git a/api/hip/hip_memory.cpp b/api/hip/hip_memory.cpp
index 1fc000bf1d..f2dfcf4b4a 100644
--- a/api/hip/hip_memory.cpp
+++ b/api/hip/hip_memory.cpp
@@ -24,8 +24,7 @@ THE SOFTWARE.
#include "hip_internal.hpp"
-hipError_t hipMalloc(void** ptr, size_t sizeBytes)
-{
+hipError_t hipMalloc(void** ptr, size_t sizeBytes) {
HIP_INIT_API(ptr, sizeBytes);
if (sizeBytes == 0) {
@@ -54,8 +53,7 @@ hipError_t hipMalloc(void** ptr, size_t sizeBytes)
return hipSuccess;
}
-hipError_t hipHostMalloc(void** ptr, size_t sizeBytes, unsigned int flags)
-{
+hipError_t hipHostMalloc(void** ptr, size_t sizeBytes, unsigned int flags) {
HIP_INIT_API(ptr, sizeBytes, flags);
if (sizeBytes == 0) {
@@ -78,8 +76,7 @@ hipError_t hipHostMalloc(void** ptr, size_t sizeBytes, unsigned int flags)
return hipSuccess;
}
-hipError_t hipFree(void* ptr)
-{
+hipError_t hipFree(void* ptr) {
if (amd::SvmBuffer::malloced(ptr)) {
amd::SvmBuffer::free(*g_context, ptr);
return hipSuccess;
@@ -91,8 +88,7 @@ hipError_t hipFree(void* ptr)
return hipSuccess;
}
-hipError_t hipMemcpy(void* dst, const void* src, size_t sizeBytes, hipMemcpyKind kind)
-{
+hipError_t hipMemcpy(void* dst, const void* src, size_t sizeBytes, hipMemcpyKind kind) {
HIP_INIT_API(dst, src, sizeBytes, kind);
amd::Device* device = g_context->devices()[0];
@@ -142,8 +138,7 @@ hipError_t hipMemcpy(void* dst, const void* src, size_t sizeBytes, hipMemcpyKind
return hipSuccess;
}
-hipError_t hipMemsetAsync(void* dst, int value, size_t sizeBytes, hipStream_t stream )
-{
+hipError_t hipMemsetAsync(void* dst, int value, size_t sizeBytes, hipStream_t stream) {
HIP_INIT_API(dst, value, sizeBytes, stream);
assert(0 && "Unimplemented");
@@ -151,8 +146,7 @@ hipError_t hipMemsetAsync(void* dst, int value, size_t sizeBytes, hipStream_t s
return hipErrorUnknown;
}
-hipError_t hipMemset(void* dst, int value, size_t sizeBytes)
-{
+hipError_t hipMemset(void* dst, int value, size_t sizeBytes) {
HIP_INIT_API(dst, value, sizeBytes);
assert(0 && "Unimplemented");
@@ -160,8 +154,7 @@ hipError_t hipMemset(void* dst, int value, size_t sizeBytes)
return hipErrorUnknown;
}
-hipError_t hipMemPtrGetInfo(void *ptr, size_t *size)
-{
+hipError_t hipMemPtrGetInfo(void *ptr, size_t *size) {
HIP_INIT_API(ptr, size);
assert(0 && "Unimplemented");
@@ -169,8 +162,7 @@ hipError_t hipMemPtrGetInfo(void *ptr, size_t *size)
return hipErrorUnknown;
}
-hipError_t hipHostFree(void* ptr)
-{
+hipError_t hipHostFree(void* ptr) {
HIP_INIT_API(ptr);
assert(0 && "Unimplemented");
@@ -178,8 +170,7 @@ hipError_t hipHostFree(void* ptr)
return hipErrorUnknown;
}
-hipError_t hipFreeArray(hipArray* array)
-{
+hipError_t hipFreeArray(hipArray* array) {
HIP_INIT_API(array);
assert(0 && "Unimplemented");
@@ -187,8 +178,7 @@ hipError_t hipFreeArray(hipArray* array)
return hipErrorUnknown;
}
-hipError_t hipMemGetAddressRange(hipDeviceptr_t* pbase, size_t* psize, hipDeviceptr_t dptr)
-{
+hipError_t hipMemGetAddressRange(hipDeviceptr_t* pbase, size_t* psize, hipDeviceptr_t dptr) {
HIP_INIT_API(pbase, psize, dptr);
assert(0 && "Unimplemented");
@@ -196,8 +186,7 @@ hipError_t hipMemGetAddressRange(hipDeviceptr_t* pbase, size_t* psize, hipDevice
return hipErrorUnknown;
}
-hipError_t hipMemGetInfo(size_t* free, size_t* total)
-{
+hipError_t hipMemGetInfo(size_t* free, size_t* total) {
HIP_INIT_API(free, total);
assert(0 && "Unimplemented");
@@ -205,8 +194,7 @@ hipError_t hipMemGetInfo(size_t* free, size_t* total)
return hipErrorUnknown;
}
-hipError_t hipMallocPitch(void** ptr, size_t* pitch, size_t width, size_t height)
-{
+hipError_t hipMallocPitch(void** ptr, size_t* pitch, size_t width, size_t height) {
HIP_INIT_API(ptr, pitch, width, height);
assert(0 && "Unimplemented");
@@ -214,8 +202,7 @@ hipError_t hipMallocPitch(void** ptr, size_t* pitch, size_t width, size_t height
return hipErrorUnknown;
}
-hipError_t hipMalloc3D(hipPitchedPtr* pitchedDevPtr, hipExtent extent)
-{
+hipError_t hipMalloc3D(hipPitchedPtr* pitchedDevPtr, hipExtent extent) {
HIP_INIT_API(pitchedDevPtr, &extent);
assert(0 && "Unimplemented");
@@ -223,8 +210,7 @@ hipError_t hipMalloc3D(hipPitchedPtr* pitchedDevPtr, hipExtent extent)
return hipErrorUnknown;
}
-hipError_t hipArrayCreate(hipArray** array, const HIP_ARRAY_DESCRIPTOR* pAllocateArray)
-{
+hipError_t hipArrayCreate(hipArray** array, const HIP_ARRAY_DESCRIPTOR* pAllocateArray) {
HIP_INIT_API(array, pAllocateArray);
assert(0 && "Unimplemented");
@@ -233,8 +219,7 @@ hipError_t hipArrayCreate(hipArray** array, const HIP_ARRAY_DESCRIPTOR* pAllocat
}
hipError_t hipMallocArray(hipArray** array, const hipChannelFormatDesc* desc,
- size_t width, size_t height, unsigned int flags)
-{
+ size_t width, size_t height, unsigned int flags) {
HIP_INIT_API(array, desc, width, height, flags);
assert(0 && "Unimplemented");
@@ -243,8 +228,7 @@ hipError_t hipMallocArray(hipArray** array, const hipChannelFormatDesc* desc,
}
hipError_t hipMalloc3DArray(hipArray_t* array, const struct hipChannelFormatDesc* desc,
- struct hipExtent extent, unsigned int flags)
-{
+ struct hipExtent extent, unsigned int flags) {
HIP_INIT_API(array, desc, &extent, flags);
assert(0 && "Unimplemented");
@@ -252,8 +236,7 @@ hipError_t hipMalloc3DArray(hipArray_t* array, const struct hipChannelFormatDesc
return hipErrorUnknown;
}
-hipError_t hipHostGetFlags(unsigned int* flagsPtr, void* hostPtr)
-{
+hipError_t hipHostGetFlags(unsigned int* flagsPtr, void* hostPtr) {
HIP_INIT_API(flagsPtr, hostPtr);
assert(0 && "Unimplemented");
@@ -261,8 +244,7 @@ hipError_t hipHostGetFlags(unsigned int* flagsPtr, void* hostPtr)
return hipErrorUnknown;
}
-hipError_t hipHostRegister(void* hostPtr, size_t sizeBytes, unsigned int flags)
-{
+hipError_t hipHostRegister(void* hostPtr, size_t sizeBytes, unsigned int flags) {
HIP_INIT_API(hostPtr, sizeBytes, flags);
assert(0 && "Unimplemented");
@@ -270,8 +252,7 @@ hipError_t hipHostRegister(void* hostPtr, size_t sizeBytes, unsigned int flags)
return hipErrorUnknown;
}
-hipError_t hipHostUnregister(void* hostPtr)
-{
+hipError_t hipHostUnregister(void* hostPtr) {
HIP_INIT_API(hostPtr);
assert(0 && "Unimplemented");
@@ -280,8 +261,7 @@ hipError_t hipHostUnregister(void* hostPtr)
}
hipError_t hipMemcpyToSymbol(const void* symbolName, const void* src, size_t count,
- size_t offset, hipMemcpyKind kind)
-{
+ size_t offset, hipMemcpyKind kind) {
HIP_INIT_API(symbolName, src, count, offset, kind);
assert(0 && "Unimplemented");
@@ -290,8 +270,7 @@ hipError_t hipMemcpyToSymbol(const void* symbolName, const void* src, size_t cou
}
hipError_t hipMemcpyFromSymbol(void* dst, const void* symbolName, size_t count,
- size_t offset, hipMemcpyKind kind)
-{
+ size_t offset, hipMemcpyKind kind) {
HIP_INIT_API(symbolName, dst, count, offset, kind);
assert(0 && "Unimplemented");
@@ -300,8 +279,7 @@ hipError_t hipMemcpyFromSymbol(void* dst, const void* symbolName, size_t count,
}
hipError_t hipMemcpyToSymbolAsync(const void* symbolName, const void* src, size_t count,
- size_t offset, hipMemcpyKind kind, hipStream_t stream)
-{
+ size_t offset, hipMemcpyKind kind, hipStream_t stream) {
HIP_INIT_API(symbolName, src, count, offset, kind, stream);
assert(0 && "Unimplemented");
@@ -310,8 +288,7 @@ hipError_t hipMemcpyToSymbolAsync(const void* symbolName, const void* src, size_
}
hipError_t hipMemcpyFromSymbolAsync(void* dst, const void* symbolName, size_t count,
- size_t offset, hipMemcpyKind kind, hipStream_t stream)
-{
+ size_t offset, hipMemcpyKind kind, hipStream_t stream) {
HIP_INIT_API(symbolName, dst, count, offset, kind, stream);
assert(0 && "Unimplemented");
@@ -319,8 +296,7 @@ hipError_t hipMemcpyFromSymbolAsync(void* dst, const void* symbolName, size_t co
return hipErrorUnknown;
}
-hipError_t hipMemcpyHtoD(hipDeviceptr_t dst, void* src, size_t sizeBytes)
-{
+hipError_t hipMemcpyHtoD(hipDeviceptr_t dst, void* src, size_t sizeBytes) {
HIP_INIT_API(dst, src, sizeBytes);
assert(0 && "Unimplemented");
@@ -328,8 +304,7 @@ hipError_t hipMemcpyHtoD(hipDeviceptr_t dst, void* src, size_t sizeBytes)
return hipErrorUnknown;
}
-hipError_t hipMemcpyDtoH(void* dst, hipDeviceptr_t src, size_t sizeBytes)
-{
+hipError_t hipMemcpyDtoH(void* dst, hipDeviceptr_t src, size_t sizeBytes) {
HIP_INIT_API(dst, src, sizeBytes);
assert(0 && "Unimplemented");
@@ -337,8 +312,7 @@ hipError_t hipMemcpyDtoH(void* dst, hipDeviceptr_t src, size_t sizeBytes)
return hipErrorUnknown;
}
-hipError_t hipMemcpyDtoD(hipDeviceptr_t dst, hipDeviceptr_t src, size_t sizeBytes)
-{
+hipError_t hipMemcpyDtoD(hipDeviceptr_t dst, hipDeviceptr_t src, size_t sizeBytes) {
HIP_INIT_API(dst, src, sizeBytes);
assert(0 && "Unimplemented");
@@ -346,8 +320,7 @@ hipError_t hipMemcpyDtoD(hipDeviceptr_t dst, hipDeviceptr_t src, size_t sizeByte
return hipErrorUnknown;
}
-hipError_t hipMemcpyHtoH(void* dst, void* src, size_t sizeBytes)
-{
+hipError_t hipMemcpyHtoH(void* dst, void* src, size_t sizeBytes) {
HIP_INIT_API(dst, src, sizeBytes);
assert(0 && "Unimplemented");
@@ -356,8 +329,7 @@ hipError_t hipMemcpyHtoH(void* dst, void* src, size_t sizeBytes)
}
hipError_t hipMemcpyAsync(void* dst, const void* src, size_t sizeBytes,
- hipMemcpyKind kind, hipStream_t stream)
-{
+ hipMemcpyKind kind, hipStream_t stream) {
HIP_INIT_API(dst, src, sizeBytes, kind, stream);
assert(0 && "Unimplemented");
@@ -367,8 +339,7 @@ hipError_t hipMemcpyAsync(void* dst, const void* src, size_t sizeBytes,
hipError_t hipMemcpyHtoDAsync(hipDeviceptr_t dst, void* src, size_t sizeBytes,
- hipStream_t stream)
-{
+ hipStream_t stream) {
HIP_INIT_API(dst, src, sizeBytes, stream);
assert(0 && "Unimplemented");
@@ -377,8 +348,7 @@ hipError_t hipMemcpyHtoDAsync(hipDeviceptr_t dst, void* src, size_t sizeBytes,
}
hipError_t hipMemcpyDtoDAsync(hipDeviceptr_t dst, hipDeviceptr_t src, size_t sizeBytes,
- hipStream_t stream)
-{
+ hipStream_t stream) {
HIP_INIT_API(dst, src, sizeBytes, stream);
assert(0 && "Unimplemented");
@@ -387,8 +357,7 @@ hipError_t hipMemcpyDtoDAsync(hipDeviceptr_t dst, hipDeviceptr_t src, size_t siz
}
hipError_t hipMemcpyDtoHAsync(void* dst, hipDeviceptr_t src, size_t sizeBytes,
- hipStream_t stream)
-{
+ hipStream_t stream) {
HIP_INIT_API(dst, src, sizeBytes, stream);
assert(0 && "Unimplemented");
@@ -397,8 +366,7 @@ hipError_t hipMemcpyDtoHAsync(void* dst, hipDeviceptr_t src, size_t sizeBytes,
}
hipError_t hipMemcpy2D(void* dst, size_t dpitch, const void* src, size_t spitch, size_t width,
- size_t height, hipMemcpyKind kind)
-{
+ size_t height, hipMemcpyKind kind) {
HIP_INIT_API(dst, dpitch, src, spitch, width, height, kind);
assert(0 && "Unimplemented");
@@ -406,8 +374,7 @@ hipError_t hipMemcpy2D(void* dst, size_t dpitch, const void* src, size_t spitch,
return hipErrorUnknown;
}
-hipError_t hipMemcpyParam2D(const hip_Memcpy2D* pCopy)
-{
+hipError_t hipMemcpyParam2D(const hip_Memcpy2D* pCopy) {
HIP_INIT_API(pCopy);
assert(0 && "Unimplemented");
@@ -416,8 +383,7 @@ hipError_t hipMemcpyParam2D(const hip_Memcpy2D* pCopy)
}
hipError_t hipMemcpy2DAsync(void* dst, size_t dpitch, const void* src, size_t spitch, size_t width,
- size_t height, hipMemcpyKind kind, hipStream_t stream)
-{
+ size_t height, hipMemcpyKind kind, hipStream_t stream) {
HIP_INIT_API(dst, dpitch, src, spitch, width, height, kind, stream);
assert(0 && "Unimplemented");
@@ -426,8 +392,7 @@ hipError_t hipMemcpy2DAsync(void* dst, size_t dpitch, const void* src, size_t sp
}
hipError_t hipMemcpy2DToArray(hipArray* dst, size_t wOffset, size_t hOffset, const void* src,
- size_t spitch, size_t width, size_t height, hipMemcpyKind kind)
-{
+ size_t spitch, size_t width, size_t height, hipMemcpyKind kind) {
HIP_INIT_API(dst, wOffset, hOffset, src, spitch, width, height, kind);
assert(0 && "Unimplemented");
@@ -436,8 +401,7 @@ hipError_t hipMemcpy2DToArray(hipArray* dst, size_t wOffset, size_t hOffset, con
}
hipError_t hipMemcpyToArray(hipArray* dst, size_t wOffset, size_t hOffset, const void* src,
- size_t count, hipMemcpyKind kind)
-{
+ size_t count, hipMemcpyKind kind) {
HIP_INIT_API(dst, wOffset, hOffset, src, count, kind);
assert(0 && "Unimplemented");
@@ -446,8 +410,7 @@ hipError_t hipMemcpyToArray(hipArray* dst, size_t wOffset, size_t hOffset, const
}
hipError_t hipMemcpyFromArray(void* dst, hipArray_const_t srcArray, size_t wOffset, size_t hOffset,
- size_t count, hipMemcpyKind kind)
-{
+ size_t count, hipMemcpyKind kind) {
HIP_INIT_API(dst, srcArray, wOffset, hOffset, count, kind);
assert(0 && "Unimplemented");
@@ -455,8 +418,7 @@ hipError_t hipMemcpyFromArray(void* dst, hipArray_const_t srcArray, size_t wOffs
return hipErrorUnknown;
}
-hipError_t hipMemcpyHtoA(hipArray* dstArray, size_t dstOffset, const void* srcHost, size_t count)
-{
+hipError_t hipMemcpyHtoA(hipArray* dstArray, size_t dstOffset, const void* srcHost, size_t count) {
HIP_INIT_API(dstArray, dstOffset, srcHost, count);
assert(0 && "Unimplemented");
@@ -464,8 +426,7 @@ hipError_t hipMemcpyHtoA(hipArray* dstArray, size_t dstOffset, const void* srcHo
return hipErrorUnknown;
}
-hipError_t hipMemcpyAtoH(void* dst, hipArray* srcArray, size_t srcOffset, size_t count)
-{
+hipError_t hipMemcpyAtoH(void* dst, hipArray* srcArray, size_t srcOffset, size_t count) {
HIP_INIT_API(dst, srcArray, srcOffset, count);
assert(0 && "Unimplemented");
@@ -473,8 +434,7 @@ hipError_t hipMemcpyAtoH(void* dst, hipArray* srcArray, size_t srcOffset, size_t
return hipErrorUnknown;
}
-hipError_t hipMemcpy3D(const struct hipMemcpy3DParms* p)
-{
+hipError_t hipMemcpy3D(const struct hipMemcpy3DParms* p) {
HIP_INIT_API(p);
assert(0 && "Unimplemented");
@@ -482,8 +442,7 @@ hipError_t hipMemcpy3D(const struct hipMemcpy3DParms* p)
return hipErrorUnknown;
}
-hipError_t hipMemset2D(void* dst, size_t pitch, int value, size_t width, size_t height)
-{
+hipError_t hipMemset2D(void* dst, size_t pitch, int value, size_t width, size_t height) {
HIP_INIT_API(dst, pitch, value, width, height);
assert(0 && "Unimplemented");
@@ -491,8 +450,7 @@ hipError_t hipMemset2D(void* dst, size_t pitch, int value, size_t width, size_t
return hipErrorUnknown;
}
-hipError_t hipMemsetD8(hipDeviceptr_t dst, unsigned char value, size_t sizeBytes)
-{
+hipError_t hipMemsetD8(hipDeviceptr_t dst, unsigned char value, size_t sizeBytes) {
HIP_INIT_API(dst, value, sizeBytes);
assert(0 && "Unimplemented");
@@ -500,8 +458,7 @@ hipError_t hipMemsetD8(hipDeviceptr_t dst, unsigned char value, size_t sizeBytes
return hipErrorUnknown;
}
-hipError_t hipIpcGetMemHandle(hipIpcMemHandle_t* handle, void* devPtr)
-{
+hipError_t hipIpcGetMemHandle(hipIpcMemHandle_t* handle, void* devPtr) {
HIP_INIT_API(handle, devPtr);
assert(0 && "Unimplemented");
@@ -509,8 +466,7 @@ hipError_t hipIpcGetMemHandle(hipIpcMemHandle_t* handle, void* devPtr)
return hipErrorUnknown;
}
-hipError_t hipIpcOpenMemHandle(void** devPtr, hipIpcMemHandle_t handle, unsigned int flags)
-{
+hipError_t hipIpcOpenMemHandle(void** devPtr, hipIpcMemHandle_t handle, unsigned int flags) {
HIP_INIT_API(devPtr, &handle, flags);
assert(0 && "Unimplemented");
@@ -524,4 +480,42 @@ hipError_t hipIpcCloseMemHandle(void* devPtr) {
assert(0 && "Unimplemented");
return hipErrorUnknown;
-}
\ No newline at end of file
+}
+
+hipError_t hipMemcpyPeer(void* dst, hipCtx_t dstCtx, const void* src, hipCtx_t srcCtx,
+ size_t sizeBytes) {
+ HIP_INIT_API(dst, dstCtx, src, srcCtx, sizeBytes);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+
+hipError_t hipMemcpyPeerAsync(void* dst, hipCtx_t dstDevice, const void* src, hipCtx_t srcDevice,
+ size_t sizeBytes, hipStream_t stream) {
+ HIP_INIT_API(dst, dstDevice, src, srcDevice, sizeBytes, stream);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipMemcpyPeer(void* dst, int dstDevice, const void* src, int srcDevice,
+ size_t sizeBytes) {
+ HIP_INIT_API(dst, dstDevice, src, srcDevice, sizeBytes);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipMemcpyPeerAsync(void* dst, int dstDevice, const void* src, int srcDevice,
+ size_t sizeBytes, hipStream_t stream) {
+ HIP_INIT_API(dst, dstDevice, src, srcDevice, sizeBytes, stream);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
diff --git a/api/hip/hip_stream.cpp b/api/hip/hip_stream.cpp
index 46014ebfef..6d0da6adfc 100644
--- a/api/hip/hip_stream.cpp
+++ b/api/hip/hip_stream.cpp
@@ -24,8 +24,7 @@ THE SOFTWARE.
#include "hip_internal.hpp"
-static hipError_t ihipStreamCreateWithFlags(hipStream_t *stream, unsigned int flags)
-{
+static hipError_t ihipStreamCreateWithFlags(hipStream_t *stream, unsigned int flags) {
assert(flags == 0); // we don't handle flags yet
amd::Device* device = g_context->devices()[0];
@@ -43,24 +42,21 @@ static hipError_t ihipStreamCreateWithFlags(hipStream_t *stream, unsigned int fl
return hipSuccess;
}
-hipError_t hipStreamCreateWithFlags(hipStream_t *stream, unsigned int flags)
-{
+hipError_t hipStreamCreateWithFlags(hipStream_t *stream, unsigned int flags) {
HIP_INIT_API(stream, flags);
return ihipStreamCreateWithFlags(stream, flags);
}
-hipError_t hipStreamCreate(hipStream_t *stream)
-{
+hipError_t hipStreamCreate(hipStream_t *stream) {
HIP_INIT_API(stream);
return ihipStreamCreateWithFlags(stream, hipStreamDefault);
}
-hipError_t hipStreamGetFlags(hipStream_t stream, unsigned int *flags)
-{
+hipError_t hipStreamGetFlags(hipStream_t stream, unsigned int *flags) {
HIP_INIT_API(stream, flags);
assert(0 && "Unimplemented");
@@ -69,8 +65,7 @@ hipError_t hipStreamGetFlags(hipStream_t stream, unsigned int *flags)
}
-hipError_t hipStreamSynchronize(hipStream_t stream)
-{
+hipError_t hipStreamSynchronize(hipStream_t stream) {
HIP_INIT_API(stream);
amd::HostQueue* hostQueue = as_amd(reinterpret_cast(stream))->asHostQueue();
@@ -84,8 +79,7 @@ hipError_t hipStreamSynchronize(hipStream_t stream)
}
-hipError_t hipStreamDestroy(hipStream_t stream)
-{
+hipError_t hipStreamDestroy(hipStream_t stream) {
HIP_INIT_API(stream);
as_amd(reinterpret_cast(stream))->release();
@@ -94,3 +88,29 @@ hipError_t hipStreamDestroy(hipStream_t stream)
}
+hipError_t hipStreamWaitEvent(hipStream_t stream, hipEvent_t event, unsigned int flags) {
+ HIP_INIT_API(stream, event, flags);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipStreamQuery(hipStream_t stream) {
+ HIP_INIT_API(stream);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipStreamAddCallback(hipStream_t stream, hipStreamCallback_t callback, void* userData,
+ unsigned int flags) {
+ HIP_INIT_API(stream, callback, userData, flags);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+
diff --git a/api/hip/hip_surface.cpp b/api/hip/hip_surface.cpp
new file mode 100644
index 0000000000..ecbd9e60b9
--- /dev/null
+++ b/api/hip/hip_surface.cpp
@@ -0,0 +1,49 @@
+/*
+Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#include
+
+#include "hip_internal.hpp"
+#include
+
+struct hipSurface {
+ hipArray* array;
+ hipResourceDesc resDesc;
+};
+
+hipError_t hipCreateSurfaceObject(hipSurfaceObject_t* pSurfObject,
+ const hipResourceDesc* pResDesc) {
+ HIP_INIT_API(pSurfObject, pResDesc);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+
+hipError_t hipDestroySurfaceObject(hipSurfaceObject_t surfaceObject) {
+ HIP_INIT_API(surfaceObject);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
\ No newline at end of file
diff --git a/api/hip/hip_texture.cpp b/api/hip/hip_texture.cpp
new file mode 100644
index 0000000000..330f86a86f
--- /dev/null
+++ b/api/hip/hip_texture.cpp
@@ -0,0 +1,202 @@
+/*
+Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#include
+#include
+#include "hip_internal.hpp"
+
+struct hipTexture {
+ hipResourceDesc resDesc;
+ hipTextureDesc texDesc;
+ hipResourceViewDesc resViewDesc;
+ hsa_ext_image_t image;
+ hsa_ext_sampler_t sampler;
+};
+
+hipError_t hipCreateTextureObject(hipTextureObject_t* pTexObject, const hipResourceDesc* pResDesc,
+ const hipTextureDesc* pTexDesc,
+ const hipResourceViewDesc* pResViewDesc) {
+ HIP_INIT_API(pTexObject, pResDesc, pTexDesc, pResViewDesc);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipDestroyTextureObject(hipTextureObject_t textureObject) {
+ HIP_INIT_API(textureObject);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipGetTextureObjectResourceDesc(hipResourceDesc* pResDesc,
+ hipTextureObject_t textureObject) {
+ HIP_INIT_API(pResDesc, textureObject);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipGetTextureObjectResourceViewDesc(hipResourceViewDesc* pResViewDesc,
+ hipTextureObject_t textureObject) {
+ HIP_INIT_API(pResViewDesc, textureObject);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipGetTextureObjectTextureDesc(hipTextureDesc* pTexDesc,
+ hipTextureObject_t textureObject) {
+ HIP_INIT_API(pTexDesc, textureObject);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipBindTexture(size_t* offset, textureReference* tex, const void* devPtr,
+ const hipChannelFormatDesc* desc, size_t size) {
+ HIP_INIT_API(offset, tex, devPtr, desc, size);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipBindTexture2D(size_t* offset, textureReference* tex, const void* devPtr,
+ const hipChannelFormatDesc* desc, size_t width, size_t height,
+ size_t pitch) {
+ HIP_INIT_API(offset, tex, devPtr, desc, width, height, pitch);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipBindTextureToArray(textureReference* tex, hipArray_const_t array,
+ const hipChannelFormatDesc* desc) {
+ HIP_INIT_API(tex, array, desc);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipBindTextureToMipmappedArray(textureReference* tex,
+ hipMipmappedArray_const_t mipmappedArray,
+ const hipChannelFormatDesc* desc) {
+ HIP_INIT_API(tex, mipmappedArray, desc);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipUnbindTexture(const textureReference* tex) {
+ HIP_INIT_API(tex);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipGetChannelDesc(hipChannelFormatDesc* desc, hipArray_const_t array) {
+ HIP_INIT_API(desc, array);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipGetTextureAlignmentOffset(size_t* offset, const textureReference* tex) {
+ HIP_INIT_API(offset, tex);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipGetTextureReference(const textureReference** tex, const void* symbol) {
+ HIP_INIT_API(tex, symbol);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipTexRefSetFormat(textureReference* tex, hipArray_Format fmt, int NumPackedComponents) {
+ HIP_INIT_API(tex, fmt, NumPackedComponents);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipTexRefSetFlags(textureReference* tex, unsigned int flags) {
+ HIP_INIT_API(tex, flags);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipTexRefSetFilterMode(textureReference* tex, hipTextureFilterMode fm) {
+ HIP_INIT_API(tex, fm);
+}
+
+hipError_t hipTexRefSetAddressMode(textureReference* tex, int dim, hipTextureAddressMode am) {
+ HIP_INIT_API(tex, dim, am);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipTexRefSetArray(textureReference* tex, hipArray_const_t array, unsigned int flags) {
+ HIP_INIT_API(tex, array, flags);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipTexRefSetAddress(size_t* offset, textureReference* tex, hipDeviceptr_t devPtr,
+ size_t size) {
+ HIP_INIT_API(offset, tex, devPtr, size);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipTexRefSetAddress2D(textureReference* tex, const HIP_ARRAY_DESCRIPTOR* desc,
+ hipDeviceptr_t devPtr, size_t pitch) {
+ HIP_INIT_API(tex, desc, devPtr, pitch);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
\ No newline at end of file
From ce88da9c1b7ec98c74aa4a68a1a661f4674f734b Mon Sep 17 00:00:00 2001
From: foreman
Date: Thu, 5 Apr 2018 15:12:53 -0400
Subject: [PATCH 018/282] P4 to Git Change 1537232 by skudchad@skudchad_rocm on
2018/04/05 15:00:24
SWDEV-145570 - [HIP] - Fix typo and fix build.
Affected files ...
... //depot/stg/opencl/drivers/opencl/api/hip/hip_texture.cpp#2 edit
---
api/hip/hip_texture.cpp | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/api/hip/hip_texture.cpp b/api/hip/hip_texture.cpp
index 330f86a86f..848ec1b110 100644
--- a/api/hip/hip_texture.cpp
+++ b/api/hip/hip_texture.cpp
@@ -24,13 +24,6 @@ THE SOFTWARE.
#include
#include "hip_internal.hpp"
-struct hipTexture {
- hipResourceDesc resDesc;
- hipTextureDesc texDesc;
- hipResourceViewDesc resViewDesc;
- hsa_ext_image_t image;
- hsa_ext_sampler_t sampler;
-};
hipError_t hipCreateTextureObject(hipTextureObject_t* pTexObject, const hipResourceDesc* pResDesc,
const hipTextureDesc* pTexDesc,
@@ -164,7 +157,11 @@ hipError_t hipTexRefSetFlags(textureReference* tex, unsigned int flags) {
}
hipError_t hipTexRefSetFilterMode(textureReference* tex, hipTextureFilterMode fm) {
- HIP_INIT_API(tex, fm);
+ HIP_INIT_API(tex, fm);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
}
hipError_t hipTexRefSetAddressMode(textureReference* tex, int dim, hipTextureAddressMode am) {
From e7f206d249c6b040027397f97bd3d09af21b432f Mon Sep 17 00:00:00 2001
From: foreman
Date: Fri, 6 Apr 2018 18:08:18 -0400
Subject: [PATCH 019/282] P4 to Git Change 1537729 by
cpaquot@cpaquot-ocl-lc-lnx on 2018/04/06 17:59:29
SWDEV-145570 - [HIP] Use Svm path for both hipMalloc and hipHostMalloc
Make sure hipMemCpy uses SvmBuffer to fetch the cl_mem
Affected files ...
... //depot/stg/opencl/drivers/opencl/api/hip/hip_memory.cpp#8 edit
---
api/hip/hip_memory.cpp | 61 +++++++++++++++---------------------------
1 file changed, 21 insertions(+), 40 deletions(-)
diff --git a/api/hip/hip_memory.cpp b/api/hip/hip_memory.cpp
index f2dfcf4b4a..ef40bdbdf6 100644
--- a/api/hip/hip_memory.cpp
+++ b/api/hip/hip_memory.cpp
@@ -24,9 +24,8 @@ THE SOFTWARE.
#include "hip_internal.hpp"
-hipError_t hipMalloc(void** ptr, size_t sizeBytes) {
- HIP_INIT_API(ptr, sizeBytes);
-
+hipError_t ihipMalloc(void** ptr, size_t sizeBytes, unsigned int flags)
+{
if (sizeBytes == 0) {
*ptr = nullptr;
return hipSuccess;
@@ -39,36 +38,7 @@ hipError_t hipMalloc(void** ptr, size_t sizeBytes) {
return hipErrorOutOfMemory;
}
- amd::Memory* mem = new (*g_context) amd::Buffer(*g_context, 0, sizeBytes);
- if (!mem) {
- return hipErrorOutOfMemory;
- }
-
- if (!mem->create(nullptr)) {
- return hipErrorMemoryAllocation;
- }
-
- *ptr = reinterpret_cast(as_cl(mem));
-
- return hipSuccess;
-}
-
-hipError_t hipHostMalloc(void** ptr, size_t sizeBytes, unsigned int flags) {
- HIP_INIT_API(ptr, sizeBytes, flags);
-
- if (sizeBytes == 0) {
- *ptr = nullptr;
- return hipSuccess;
- }
- else if (!ptr) {
- return hipErrorInvalidValue;
- }
-
- if (g_context->devices()[0]->info().maxMemAllocSize_ < sizeBytes) {
- return hipErrorOutOfMemory;
- }
-
- *ptr = amd::SvmBuffer::malloc(*g_context, 0, sizeBytes, g_context->devices()[0]->info().memBaseAddrAlign_);
+ *ptr = amd::SvmBuffer::malloc(*g_context, flags, sizeBytes, g_context->devices()[0]->info().memBaseAddrAlign_);
if (!*ptr) {
return hipErrorOutOfMemory;
}
@@ -76,16 +46,24 @@ hipError_t hipHostMalloc(void** ptr, size_t sizeBytes, unsigned int flags) {
return hipSuccess;
}
+hipError_t hipMalloc(void** ptr, size_t sizeBytes) {
+ HIP_INIT_API(ptr, sizeBytes);
+
+ return ihipMalloc(ptr, sizeBytes, 0);
+}
+
+hipError_t hipHostMalloc(void** ptr, size_t sizeBytes, unsigned int flags) {
+ HIP_INIT_API(ptr, sizeBytes, flags);
+
+ return ihipMalloc(ptr, sizeBytes, CL_MEM_SVM_FINE_GRAIN_BUFFER);
+}
+
hipError_t hipFree(void* ptr) {
if (amd::SvmBuffer::malloced(ptr)) {
amd::SvmBuffer::free(*g_context, ptr);
return hipSuccess;
}
- if (!is_valid(reinterpret_cast(ptr))) {
- return hipErrorInvalidValue;
- }
- as_amd(reinterpret_cast(ptr))->release();
- return hipSuccess;
+ return hipErrorInvalidValue;
}
hipError_t hipMemcpy(void* dst, const void* src, size_t sizeBytes, hipMemcpyKind kind) {
@@ -102,15 +80,18 @@ hipError_t hipMemcpy(void* dst, const void* src, size_t sizeBytes, hipMemcpyKind
amd::Command* command;
amd::Command::EventWaitList waitList;
+ amd::Memory* memory;
switch (kind) {
case hipMemcpyDeviceToHost:
+ memory = amd::SvmManager::FindSvmBuffer(src);
command = new amd::ReadMemoryCommand(*queue, CL_COMMAND_READ_BUFFER, waitList,
- *as_amd(reinterpret_cast(const_cast(src)))->asBuffer(), 0, sizeBytes, dst);
+ *memory->asBuffer(), 0, sizeBytes, dst);
break;
case hipMemcpyHostToDevice:
+ memory = amd::SvmManager::FindSvmBuffer(dst);
command = new amd::WriteMemoryCommand(*queue, CL_COMMAND_WRITE_BUFFER, waitList,
- *as_amd(reinterpret_cast(dst))->asBuffer(), 0, sizeBytes, src);
+ *memory->asBuffer(), 0, sizeBytes, src);
break;
default:
assert(!"Shouldn't reach here");
From 04decb72fcad4002caf80e6fee3236c56c5f2a44 Mon Sep 17 00:00:00 2001
From: foreman
Date: Tue, 10 Apr 2018 17:41:24 -0400
Subject: [PATCH 020/282] P4 to Git Change 1539198 by
skudchad@skudchad_test2_win_opencl on 2018/04/10 17:32:14
SWDEV-145570 - [HIP] - Add HIP API skeletons for Peer and memory
ReviewBoardURL = http://ocltc.amd.com/reviews/r/14596/diff/
Affected files ...
... //depot/stg/opencl/drivers/opencl/api/hip/hip_context.cpp#7 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_memory.cpp#9 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_peer.cpp#1 add
---
api/hip/hip_context.cpp | 16 ++++++
api/hip/hip_memory.cpp | 40 ++++++---------
api/hip/hip_peer.cpp | 109 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 139 insertions(+), 26 deletions(-)
create mode 100644 api/hip/hip_peer.cpp
diff --git a/api/hip/hip_context.cpp b/api/hip/hip_context.cpp
index 9bfe4ad45d..2e189f1351 100644
--- a/api/hip/hip_context.cpp
+++ b/api/hip/hip_context.cpp
@@ -169,6 +169,22 @@ hipError_t hipCtxPushCurrent(hipCtx_t ctx) {
return hipSuccess;
}
+hipError_t hipDriverGetVersion(int* driverVersion) {
+ HIP_INIT_API(driverVersion);
+
+ auto* deviceHandle = g_devices[0]->devices()[0];
+ const auto& info = deviceHandle->info();
+
+ if (driverVersion) {
+ *driverVersion = AMD_PLATFORM_BUILD_NUMBER * 100 +
+ AMD_PLATFORM_REVISION_NUMBER;
+ } else {
+ return hipErrorInvalidValue;
+ }
+
+ return hipSuccess;;
+}
+
hipError_t hipCtxGetDevice(hipDevice_t* device) {
HIP_INIT_API(device);
diff --git a/api/hip/hip_memory.cpp b/api/hip/hip_memory.cpp
index ef40bdbdf6..8cb51be08d 100644
--- a/api/hip/hip_memory.cpp
+++ b/api/hip/hip_memory.cpp
@@ -463,40 +463,28 @@ hipError_t hipIpcCloseMemHandle(void* devPtr) {
return hipErrorUnknown;
}
-hipError_t hipMemcpyPeer(void* dst, hipCtx_t dstCtx, const void* src, hipCtx_t srcCtx,
- size_t sizeBytes) {
- HIP_INIT_API(dst, dstCtx, src, srcCtx, sizeBytes);
+hipChannelFormatDesc hipCreateChannelDesc(int x, int y, int z, int w, hipChannelFormatKind f) {
+ hipChannelFormatDesc cd;
+ cd.x = x;
+ cd.y = y;
+ cd.z = z;
+ cd.w = w;
+ cd.f = f;
+ return cd;
+}
+
+hipError_t hipHostGetDevicePointer(void** devicePointer, void* hostPointer, unsigned flags) {
+ HIP_INIT_API(devicePointer, hostPointer, flags);
assert(0 && "Unimplemented");
return hipErrorUnknown;
}
-
-hipError_t hipMemcpyPeerAsync(void* dst, hipCtx_t dstDevice, const void* src, hipCtx_t srcDevice,
- size_t sizeBytes, hipStream_t stream) {
- HIP_INIT_API(dst, dstDevice, src, srcDevice, sizeBytes, stream);
+hipError_t hipPointerGetAttributes(hipPointerAttribute_t* attributes, const void* ptr) {
+ HIP_INIT_API(attributes, ptr);
assert(0 && "Unimplemented");
return hipErrorUnknown;
}
-
-hipError_t hipMemcpyPeer(void* dst, int dstDevice, const void* src, int srcDevice,
- size_t sizeBytes) {
- HIP_INIT_API(dst, dstDevice, src, srcDevice, sizeBytes);
-
- assert(0 && "Unimplemented");
-
- return hipErrorUnknown;
-}
-
-hipError_t hipMemcpyPeerAsync(void* dst, int dstDevice, const void* src, int srcDevice,
- size_t sizeBytes, hipStream_t stream) {
- HIP_INIT_API(dst, dstDevice, src, srcDevice, sizeBytes, stream);
-
- assert(0 && "Unimplemented");
-
- return hipErrorUnknown;
-}
-
diff --git a/api/hip/hip_peer.cpp b/api/hip/hip_peer.cpp
new file mode 100644
index 0000000000..ad552e94b4
--- /dev/null
+++ b/api/hip/hip_peer.cpp
@@ -0,0 +1,109 @@
+/*
+Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#include
+
+#include "hip_internal.hpp"
+
+hipError_t hipDeviceCanAccessPeer(int* canAccessPeer, hipCtx_t thisCtx, hipCtx_t peerCtx) {
+ HIP_INIT_API(canAccessPeer, thisCtx, peerCtx);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipMemcpyPeer(void* dst, hipCtx_t dstCtx, const void* src, hipCtx_t srcCtx,
+ size_t sizeBytes) {
+ HIP_INIT_API(dst, dstCtx, src, srcCtx, sizeBytes);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipMemcpyPeerAsync(void* dst, hipCtx_t dstDevice, const void* src, hipCtx_t srcDevice,
+ size_t sizeBytes, hipStream_t stream) {
+ HIP_INIT_API(dst, dstDevice, src, srcDevice, sizeBytes, stream);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipDeviceCanAccessPeer(int* canAccessPeer, int deviceId, int peerDeviceId) {
+ HIP_INIT_API(canAccessPeer, deviceId, peerDeviceId);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipDeviceDisablePeerAccess(int peerDeviceId) {
+ HIP_INIT_API(peerDeviceId);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipDeviceEnablePeerAccess(int peerDeviceId, unsigned int flags) {
+ HIP_INIT_API(peerDeviceId, flags);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipMemcpyPeer(void* dst, int dstDevice, const void* src, int srcDevice,
+ size_t sizeBytes) {
+ HIP_INIT_API(dst, dstDevice, src, srcDevice, sizeBytes);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipMemcpyPeerAsync(void* dst, int dstDevice, const void* src, int srcDevice,
+ size_t sizeBytes, hipStream_t stream) {
+ HIP_INIT_API(dst, dstDevice, src, srcDevice, sizeBytes, stream);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipCtxEnablePeerAccess(hipCtx_t peerCtx, unsigned int flags) {
+ HIP_INIT_API(peerCtx, flags);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipCtxDisablePeerAccess(hipCtx_t peerCtx) {
+ HIP_INIT_API(peerCtx);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
\ No newline at end of file
From e6718d9747e115f30c973c5667732018c4ca8569 Mon Sep 17 00:00:00 2001
From: foreman
Date: Fri, 13 Apr 2018 18:19:28 -0400
Subject: [PATCH 021/282] P4 to Git Change 1541197 by
skudchad@skudchad_test2_win_opencl on 2018/04/13 17:49:07
SWDEV-145570 - [HIP] - Add missing HIP APIs and fill sym table references. The HIP tests can now build if we do a symlink to libhip_hcc.so that we build with VDI in the install folder in github HIP.
ReviewBoardURL = http://ocltc.amd.com/reviews/r/14619/diff/
Affected files ...
... //depot/stg/opencl/drivers/opencl/api/hip/hip_device.cpp#10 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_hcc.def.in#3 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_hcc.map.in#3 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_internal.hpp#7 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_platform.cpp#5 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_profile.cpp#1 add
... //depot/stg/opencl/drivers/opencl/api/hip/hip_texture.cpp#3 edit
---
api/hip/hip_device.cpp | 15 ++++++++++++++
api/hip/hip_hcc.def.in | 28 +++++++++++++++++++++++++++
api/hip/hip_hcc.map.in | 32 ++++++++++++++++++++++++++++++
api/hip/hip_internal.hpp | 5 +++++
api/hip/hip_platform.cpp | 17 ++++++++++++++++
api/hip/hip_profile.cpp | 42 ++++++++++++++++++++++++++++++++++++++++
api/hip/hip_texture.cpp | 9 +++++++++
7 files changed, 148 insertions(+)
create mode 100644 api/hip/hip_profile.cpp
diff --git a/api/hip/hip_device.cpp b/api/hip/hip_device.cpp
index d067cf19a8..531beb52f4 100644
--- a/api/hip/hip_device.cpp
+++ b/api/hip/hip_device.cpp
@@ -191,3 +191,18 @@ hipError_t hipGetDeviceProperties ( hipDeviceProp_t* props, hipDevice_t device )
return hipSuccess;
}
+hipError_t hipHccGetAccelerator(int deviceId, hc::accelerator* acc) {
+ HIP_INIT_API(deviceId, acc);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+hipError_t hipHccGetAcceleratorView(hipStream_t stream, hc::accelerator_view** av) {
+ HIP_INIT_API(stream, av);
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
diff --git a/api/hip/hip_hcc.def.in b/api/hip/hip_hcc.def.in
index 10113dc2bd..e7fd04ad04 100644
--- a/api/hip/hip_hcc.def.in
+++ b/api/hip/hip_hcc.def.in
@@ -89,6 +89,7 @@ hipMemcpyHtoDAsync
hipMemcpyPeer
hipMemcpyPeerAsync
hipMemcpyToArray
+hipMemcpyFromArray
hipMemcpyToSymbol
hipMemcpyToSymbolAsync
hipMemGetAddressRange
@@ -127,3 +128,30 @@ __hipUnregisterFatBinary
hipConfigureCall
hipSetupArgument
hipLaunchByPtr
+hipCreateTextureObject
+hipDestroyTextureObject
+hipGetTextureObjectResourceDesc
+hipGetTextureObjectResourceViewDesc
+hipGetTextureObjectTextureDesc
+hipBindTexture
+hipBindTexture2D
+hipBindTextureToArray
+hipBindTextureToMipmappedArray
+hipUnbindTexture
+hipGetChannelDesc
+hipGetTextureAlignmentOffset
+hipGetTextureReference
+hipTexRefSetFormat
+hipTexRefSetFlags
+hipTexRefSetFilterMode
+hipTexRefSetAddressMode
+hipTexRefSetArray
+hipTexRefSetAddress
+hipTexRefSetAddress2D
+hipCreateChannelDesc
+hipProfilerStart
+hipProfilerStop
+hipHccGetAccelerator
+hipHccGetAcceleratorView
+hipCreateSurfaceObject
+hipDestroySurfaceObject
diff --git a/api/hip/hip_hcc.map.in b/api/hip/hip_hcc.map.in
index a4153ee56f..d0bc6b4618 100644
--- a/api/hip/hip_hcc.map.in
+++ b/api/hip/hip_hcc.map.in
@@ -90,6 +90,7 @@ global:
hipMemcpyPeer;
hipMemcpyPeerAsync;
hipMemcpyToArray;
+ hipMemcpyFromArray;
hipMemcpyToSymbol;
hipMemcpyToSymbolAsync;
hipMemGetAddressRange;
@@ -128,6 +129,37 @@ global:
hipConfigureCall;
hipSetupArgument;
hipLaunchByPtr;
+ hipProfilerStart;
+ hipProfilerStop;
+ extern "C++" {
+ hip_impl::hipLaunchKernelGGLImpl*;
+ hipCreateTextureObject*;
+ hipDestroyTextureObject*;
+ hipGetTextureObjectResourceDesc;
+ hipGetTextureObjectResourceViewDesc;
+ hipGetTextureObjectTextureDesc;
+ hipBindTexture;
+ hipBindTexture2D;
+ hipBindTextureToArray;
+ hipBindTextureToMipmappedArray;
+ hipUnbindTexture;
+ hipGetChannelDesc;
+ hipGetTextureAlignmentOffset;
+ hipGetTextureReference;
+ hipTexRefSetFormat;
+ hipTexRefSetFlags;
+ hipTexRefSetFilterMode;
+ hipTexRefSetAddressMode;
+ hipTexRefSetArray;
+ hipTexRefSetAddress;
+ hipTexRefSetAddress2D;
+ hipCreateChannelDesc*;
+ ihipBindTextureToArrayImpl*;
+ hipHccGetAccelerator*;
+ hipHccGetAcceleratorView*;
+ hipCreateSurfaceObject*;
+ hipDestroySurfaceObject*;
+ };
local:
*;
};
diff --git a/api/hip/hip_internal.hpp b/api/hip/hip_internal.hpp
index 3d334fa2ac..2512e35c98 100644
--- a/api/hip/hip_internal.hpp
+++ b/api/hip/hip_internal.hpp
@@ -40,6 +40,11 @@ THE SOFTWARE.
return hipErrorOutOfMemory; \
}
+namespace hc {
+class accelerator;
+class accelerator_view;
+};
+
extern std::once_flag g_ihipInitialized;
extern thread_local amd::Context* g_context;
extern std::vector g_devices;
diff --git a/api/hip/hip_platform.cpp b/api/hip/hip_platform.cpp
index f1c33dabde..d66bf0930c 100644
--- a/api/hip/hip_platform.cpp
+++ b/api/hip/hip_platform.cpp
@@ -260,3 +260,20 @@ extern "C" hipError_t hipLaunchByPtr(const void *hostFunction)
g_blockDim.x, g_blockDim.y, g_blockDim.z,
g_sharedMem, g_stream, nullptr, extra);
}
+
+#if defined(ATI_OS_LINUX)
+
+namespace hip_impl {
+
+void hipLaunchKernelGGLImpl(
+ uintptr_t function_address,
+ const dim3& numBlocks,
+ const dim3& dimBlocks,
+ uint32_t sharedMemBytes,
+ hipStream_t stream,
+ void** kernarg) {
+}
+
+}
+
+#endif // defined(ATI_OS_LINUX)
diff --git a/api/hip/hip_profile.cpp b/api/hip/hip_profile.cpp
new file mode 100644
index 0000000000..d53d7ffd46
--- /dev/null
+++ b/api/hip/hip_profile.cpp
@@ -0,0 +1,42 @@
+/*
+Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#include
+
+#include "hip_internal.hpp"
+
+hipError_t hipProfilerStart() {
+ HIP_INIT_API();
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
+
+hipError_t hipProfilerStop() {
+ HIP_INIT_API();
+
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
\ No newline at end of file
diff --git a/api/hip/hip_texture.cpp b/api/hip/hip_texture.cpp
index 848ec1b110..59adad761a 100644
--- a/api/hip/hip_texture.cpp
+++ b/api/hip/hip_texture.cpp
@@ -98,6 +98,15 @@ hipError_t hipBindTextureToArray(textureReference* tex, hipArray_const_t array,
return hipErrorUnknown;
}
+hipError_t ihipBindTextureToArrayImpl(int dim, enum hipTextureReadMode readMode,
+ hipArray_const_t array,
+ const struct hipChannelFormatDesc& desc,
+ textureReference* tex) {
+ assert(0 && "Unimplemented");
+
+ return hipErrorUnknown;
+}
+
hipError_t hipBindTextureToMipmappedArray(textureReference* tex,
hipMipmappedArray_const_t mipmappedArray,
const hipChannelFormatDesc* desc) {
From 250e08f31fa2f036070c9f51b486ab2675a0b8ad Mon Sep 17 00:00:00 2001
From: foreman
Date: Mon, 16 Apr 2018 18:37:17 -0400
Subject: [PATCH 022/282] P4 to Git Change 1541938 by
cpaquot@cpaquot-ocl-lc-lnx on 2018/04/16 18:27:17
SWDEV-145570 - [HIP] Set/GetDevice and Create/DestroyTextureObject
Implemented Set/GetDevice relying on g_context (current context)
Implemented create linear/2D texture object function
Implemented hipDestroyTextureObject
Affected files ...
... //depot/stg/opencl/drivers/opencl/api/hip/hip_device_runtime.cpp#5 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_texture.cpp#4 edit
---
api/hip/hip_device_runtime.cpp | 17 +++--
api/hip/hip_texture.cpp | 118 +++++++++++++++++++++++++++++++--
2 files changed, 126 insertions(+), 9 deletions(-)
diff --git a/api/hip/hip_device_runtime.cpp b/api/hip/hip_device_runtime.cpp
index 7c5c063ea6..d0d9c1145b 100644
--- a/api/hip/hip_device_runtime.cpp
+++ b/api/hip/hip_device_runtime.cpp
@@ -382,13 +382,17 @@ hipError_t hipGetDevice ( int* deviceId ) {
HIP_INIT_API(deviceId);
if (deviceId != nullptr) {
- // this needs to return default device. For now return 0 always
- *deviceId = 0;
+ for (unsigned int i = 0; i < g_devices.size(); i++) {
+ if (g_devices[i] == g_context) {
+ *deviceId = i;
+ return hipSuccess;
+ }
+ }
} else {
return hipErrorInvalidValue;
}
- return hipSuccess;
+ return hipErrorUnknown;
}
hipError_t hipGetDeviceCount ( int* count ) {
@@ -420,9 +424,12 @@ hipError_t hipIpcOpenEventHandle ( hipEvent_t* event, hipIpcEventHandle_t handle
hipError_t hipSetDevice ( int device ) {
HIP_INIT_API(device);
- assert(0 && "Unimplemented");
+ if (static_cast(device) < g_devices.size()) {
+ g_context = g_devices[device];
- return hipErrorUnknown;
+ return hipSuccess;
+ }
+ return hipErrorInvalidValue;
}
hipError_t hipSetDeviceFlags ( unsigned int flags ) {
diff --git a/api/hip/hip_texture.cpp b/api/hip/hip_texture.cpp
index 59adad761a..715c39eb97 100644
--- a/api/hip/hip_texture.cpp
+++ b/api/hip/hip_texture.cpp
@@ -24,13 +24,123 @@ THE SOFTWARE.
#include
#include "hip_internal.hpp"
+void getChannelOrderAndType(const hipChannelFormatDesc& desc, enum hipTextureReadMode readMode,
+ cl_channel_order* channelOrder, cl_channel_type* channelType) {
+ if (desc.x != 0 && desc.y != 0 && desc.z != 0 && desc.w != 0) {
+ *channelOrder = CL_RGBA;
+ } else if (desc.x != 0 && desc.y != 0 && desc.z != 0 && desc.w == 0) {
+ *channelOrder = CL_RGB;
+ } else if (desc.x != 0 && desc.y != 0 && desc.z == 0 && desc.w == 0) {
+ *channelOrder = CL_RG;
+ } else if (desc.x != 0 && desc.y == 0 && desc.z == 0 && desc.w == 0) {
+ *channelOrder = CL_R;
+ } else {
+ }
+
+ switch (desc.f) {
+ case hipChannelFormatKindUnsigned:
+ switch (desc.x) {
+ case 32:
+ *channelType = CL_UNSIGNED_INT32;
+ break;
+ case 16:
+ *channelType = readMode == hipReadModeNormalizedFloat
+ ? CL_UNORM_INT16
+ : CL_UNSIGNED_INT16;
+ break;
+ case 8:
+ *channelType = readMode == hipReadModeNormalizedFloat
+ ? CL_UNORM_INT8
+ : CL_UNSIGNED_INT8;
+ break;
+ default:
+ *channelType = CL_UNSIGNED_INT32;
+ }
+ break;
+ case hipChannelFormatKindSigned:
+ switch (desc.x) {
+ case 32:
+ *channelType = CL_SIGNED_INT32;
+ break;
+ case 16:
+ *channelType = readMode == hipReadModeNormalizedFloat
+ ? CL_SNORM_INT16
+ : CL_SIGNED_INT16;
+ break;
+ case 8:
+ *channelType = readMode == hipReadModeNormalizedFloat
+ ? CL_SNORM_INT8
+ : CL_SIGNED_INT8;
+ break;
+ default:
+ *channelType = CL_SIGNED_INT32;
+ }
+ break;
+ case hipChannelFormatKindFloat:
+ switch (desc.x) {
+ case 32:
+ *channelType = CL_FLOAT;
+ break;
+ case 16:
+ *channelType = CL_HALF_FLOAT;
+ break;
+ case 8:
+ break;
+ default:
+ *channelType = CL_FLOAT;
+ }
+ break;
+ case hipChannelFormatKindNone:
+ default:
+ break;
+ }
+}
hipError_t hipCreateTextureObject(hipTextureObject_t* pTexObject, const hipResourceDesc* pResDesc,
const hipTextureDesc* pTexDesc,
const hipResourceViewDesc* pResViewDesc) {
HIP_INIT_API(pTexObject, pResDesc, pTexDesc, pResViewDesc);
- assert(0 && "Unimplemented");
+ if (!g_context->devices()[0]->info().imageSupport_) {
+ return hipErrorInvalidValue;
+ }
+
+ amd::Image* image = nullptr;
+
+ cl_image_format image_format;
+ getChannelOrderAndType(pResDesc->res.pitch2D.desc, pTexDesc->readMode,
+ &image_format.image_channel_order, &image_format.image_channel_data_type);
+
+ const amd::Image::Format imageFormat(image_format);
+
+ amd::Memory* memory = nullptr;
+
+ switch (pResDesc->resType) {
+ case hipResourceTypeArray:
+ assert(0);
+ break;
+ case hipResourceTypeMipmappedArray:
+ assert(0);
+ break;
+ case hipResourceTypeLinear:
+ assert(pResViewDesc == nullptr);
+
+ memory = amd::SvmManager::FindSvmBuffer(pResDesc->res.linear.devPtr);
+ image = new (*g_context) amd::Image(*memory->asBuffer(), CL_MEM_OBJECT_IMAGE1D, memory->getMemFlags(), imageFormat,
+ pResDesc->res.linear.sizeInBytes / imageFormat.getElementSize(), 1, 1,
+ pResDesc->res.linear.sizeInBytes, 0);
+ break;
+ case hipResourceTypePitch2D:
+ assert(pResViewDesc == nullptr);
+
+ memory = amd::SvmManager::FindSvmBuffer(pResDesc->res.pitch2D.devPtr);
+ image = new (*g_context) amd::Image(*memory->asBuffer(), CL_MEM_OBJECT_IMAGE2D, memory->getMemFlags(), imageFormat,
+ pResDesc->res.pitch2D.width, pResDesc->res.pitch2D.height, 1,
+ pResDesc->res.pitch2D.pitchInBytes, 0);
+ break;
+ default: return hipErrorInvalidValue;
+ }
+ *pTexObject = reinterpret_cast(as_cl(image));
return hipErrorUnknown;
}
@@ -38,9 +148,9 @@ hipError_t hipCreateTextureObject(hipTextureObject_t* pTexObject, const hipResou
hipError_t hipDestroyTextureObject(hipTextureObject_t textureObject) {
HIP_INIT_API(textureObject);
- assert(0 && "Unimplemented");
+ as_amd(reinterpret_cast(textureObject))->release();
- return hipErrorUnknown;
+ return hipSuccess;
}
hipError_t hipGetTextureObjectResourceDesc(hipResourceDesc* pResDesc,
@@ -205,4 +315,4 @@ hipError_t hipTexRefSetAddress2D(textureReference* tex, const HIP_ARRAY_DESCRIPT
assert(0 && "Unimplemented");
return hipErrorUnknown;
-}
\ No newline at end of file
+}
From 63babe9e66049e7a7887196da52272ca0fb2a7df Mon Sep 17 00:00:00 2001
From: foreman
Date: Thu, 19 Apr 2018 12:27:09 -0400
Subject: [PATCH 023/282] P4 to Git Change 1543751 by
cpaquot@cpaquot-ocl-lc-lnx on 2018/04/19 11:17:02
SWDEV-145570 - [HIP] Implemented a bunch of texture APIs
Affected files ...
... //depot/stg/opencl/drivers/opencl/api/hip/hip_texture.cpp#5 edit
---
api/hip/hip_texture.cpp | 143 ++++++++++++++++++++++++++++++++++------
1 file changed, 124 insertions(+), 19 deletions(-)
diff --git a/api/hip/hip_texture.cpp b/api/hip/hip_texture.cpp
index 715c39eb97..fbc8c4b481 100644
--- a/api/hip/hip_texture.cpp
+++ b/api/hip/hip_texture.cpp
@@ -24,6 +24,47 @@ THE SOFTWARE.
#include
#include "hip_internal.hpp"
+void getDrvChannelOrderAndType(const enum hipArray_Format Format, unsigned int NumChannels,
+ cl_channel_order* channelOrder,
+ cl_channel_type* channelType) {
+ switch (Format) {
+ case HIP_AD_FORMAT_UNSIGNED_INT8:
+ *channelType = CL_UNSIGNED_INT8;
+ break;
+ case HIP_AD_FORMAT_UNSIGNED_INT16:
+ *channelType = CL_UNSIGNED_INT16;
+ break;
+ case HIP_AD_FORMAT_UNSIGNED_INT32:
+ *channelType = CL_UNSIGNED_INT32;
+ break;
+ case HIP_AD_FORMAT_SIGNED_INT8:
+ *channelType = CL_SIGNED_INT8;
+ break;
+ case HIP_AD_FORMAT_SIGNED_INT16:
+ *channelType = CL_SIGNED_INT16;
+ break;
+ case HIP_AD_FORMAT_SIGNED_INT32:
+ *channelType = CL_SIGNED_INT32;
+ break;
+ case HIP_AD_FORMAT_HALF:
+ *channelType = CL_HALF_FLOAT;
+ break;
+ case HIP_AD_FORMAT_FLOAT:
+ *channelType = CL_FLOAT;
+ break;
+ default:
+ break;
+ }
+
+ if (NumChannels == 4) {
+ *channelOrder = CL_RGBA;
+ } else if (NumChannels == 2) {
+ *channelOrder = CL_RG;
+ } else if (NumChannels == 1) {
+ *channelOrder = CL_R;
+ }
+}
+
void getChannelOrderAndType(const hipChannelFormatDesc& desc, enum hipTextureReadMode readMode,
cl_channel_order* channelOrder, cl_channel_type* channelType) {
if (desc.x != 0 && desc.y != 0 && desc.z != 0 && desc.w != 0) {
@@ -180,13 +221,52 @@ hipError_t hipGetTextureObjectTextureDesc(hipTextureDesc* pTexDesc,
return hipErrorUnknown;
}
+hipError_t ihipBindTexture(cl_mem_object_type type,
+ size_t* offset, textureReference* tex, const void* devPtr,
+ const hipChannelFormatDesc* desc, size_t width, size_t height,
+ size_t pitch) {
+ if (tex == nullptr) {
+ return hipErrorInvalidImage;
+ }
+ if (g_context) {
+ cl_image_format image_format;
+
+ if (nullptr == desc) {
+ getDrvChannelOrderAndType(tex->format, tex->numChannels,
+ &image_format.image_channel_order, &image_format.image_channel_data_type);
+ } else {
+ getChannelOrderAndType(*desc, hipReadModeElementType,
+ &image_format.image_channel_order, &image_format.image_channel_data_type);
+ }
+ const amd::Image::Format imageFormat(image_format);
+
+ amd::Memory* memory = amd::SvmManager::FindSvmBuffer(devPtr);
+ amd::Image* image = new (*g_context) amd::Image(*memory->asBuffer(), type, memory->getMemFlags(),
+ imageFormat, width, height, 1, pitch, 0);
+
+ *offset = 0;
+ if (tex->textureObject) {
+ as_amd(reinterpret_cast(tex->textureObject))->release();
+ }
+ tex->textureObject = reinterpret_cast(as_cl(image));
+ return hipSuccess;
+ }
+ return hipErrorUnknown;
+}
+
hipError_t hipBindTexture(size_t* offset, textureReference* tex, const void* devPtr,
const hipChannelFormatDesc* desc, size_t size) {
HIP_INIT_API(offset, tex, devPtr, desc, size);
- assert(0 && "Unimplemented");
+ if (desc == nullptr) {
+ return hipErrorInvalidValue;
+ }
+ cl_image_format image_format;
+ getChannelOrderAndType(*desc, hipReadModeElementType,
+ &image_format.image_channel_order, &image_format.image_channel_data_type);
+ const amd::Image::Format imageFormat(image_format);
- return hipErrorUnknown;
+ return ihipBindTexture(CL_MEM_OBJECT_IMAGE1D, offset, tex, devPtr, desc, size / imageFormat.getElementSize(), 1, size);
}
hipError_t hipBindTexture2D(size_t* offset, textureReference* tex, const void* devPtr,
@@ -194,9 +274,7 @@ hipError_t hipBindTexture2D(size_t* offset, textureReference* tex, const void* d
size_t pitch) {
HIP_INIT_API(offset, tex, devPtr, desc, width, height, pitch);
- assert(0 && "Unimplemented");
-
- return hipErrorUnknown;
+ return ihipBindTexture(CL_MEM_OBJECT_IMAGE2D, offset, tex, devPtr, desc, width, height, pitch);
}
hipError_t hipBindTextureToArray(textureReference* tex, hipArray_const_t array,
@@ -230,9 +308,9 @@ hipError_t hipBindTextureToMipmappedArray(textureReference* tex,
hipError_t hipUnbindTexture(const textureReference* tex) {
HIP_INIT_API(tex);
- assert(0 && "Unimplemented");
+ as_amd(reinterpret_cast(tex->textureObject))->release();
- return hipErrorUnknown;
+ return hipSuccess;
}
hipError_t hipGetChannelDesc(hipChannelFormatDesc* desc, hipArray_const_t array) {
@@ -262,33 +340,50 @@ hipError_t hipGetTextureReference(const textureReference** tex, const void* symb
hipError_t hipTexRefSetFormat(textureReference* tex, hipArray_Format fmt, int NumPackedComponents) {
HIP_INIT_API(tex, fmt, NumPackedComponents);
- assert(0 && "Unimplemented");
+ if (tex == nullptr) {
+ return hipErrorInvalidImage;
+ }
- return hipErrorUnknown;
+ tex->format = fmt;
+ tex->numChannels = NumPackedComponents;
+
+ return hipSuccess;
}
hipError_t hipTexRefSetFlags(textureReference* tex, unsigned int flags) {
HIP_INIT_API(tex, flags);
- assert(0 && "Unimplemented");
+ if (tex == nullptr) {
+ return hipErrorInvalidImage;
+ }
- return hipErrorUnknown;
+ tex->normalized = flags;
+
+ return hipSuccess;
}
hipError_t hipTexRefSetFilterMode(textureReference* tex, hipTextureFilterMode fm) {
HIP_INIT_API(tex, fm);
- assert(0 && "Unimplemented");
+ if (tex == nullptr) {
+ return hipErrorInvalidImage;
+ }
- return hipErrorUnknown;
+ tex->filterMode = fm;
+
+ return hipSuccess;
}
hipError_t hipTexRefSetAddressMode(textureReference* tex, int dim, hipTextureAddressMode am) {
HIP_INIT_API(tex, dim, am);
- assert(0 && "Unimplemented");
+ if (tex == nullptr) {
+ return hipErrorInvalidImage;
+ }
- return hipErrorUnknown;
+ tex->addressMode[dim] = am;
+
+ return hipSuccess;
}
hipError_t hipTexRefSetArray(textureReference* tex, hipArray_const_t array, unsigned int flags) {
@@ -303,16 +398,26 @@ hipError_t hipTexRefSetAddress(size_t* offset, textureReference* tex, hipDevicep
size_t size) {
HIP_INIT_API(offset, tex, devPtr, size);
- assert(0 && "Unimplemented");
+ if (tex == nullptr) {
+ return hipErrorInvalidImage;
+ }
- return hipErrorUnknown;
+ cl_image_format image_format;
+ getDrvChannelOrderAndType(tex->format, tex->numChannels,
+ &image_format.image_channel_order, &image_format.image_channel_data_type);
+ const amd::Image::Format imageFormat(image_format);
+
+ return ihipBindTexture(CL_MEM_OBJECT_IMAGE1D, offset, tex, devPtr, nullptr, size / imageFormat.getElementSize(), 1, size);
}
hipError_t hipTexRefSetAddress2D(textureReference* tex, const HIP_ARRAY_DESCRIPTOR* desc,
hipDeviceptr_t devPtr, size_t pitch) {
HIP_INIT_API(tex, desc, devPtr, pitch);
- assert(0 && "Unimplemented");
+ if (desc == nullptr) {
+ return hipErrorInvalidValue;
+ }
- return hipErrorUnknown;
+ size_t offset;
+ return ihipBindTexture(CL_MEM_OBJECT_IMAGE2D, &offset, tex, devPtr, nullptr, desc->width, desc->height, pitch);
}
From 3ce752065a6f4e354ee4add8b8ece9592dbbd2d1 Mon Sep 17 00:00:00 2001
From: foreman
Date: Thu, 19 Apr 2018 18:35:00 -0400
Subject: [PATCH 024/282] P4 to Git Change 1544061 by
skudchad@skudchad_test2_win_opencl on 2018/04/19 18:24:45
SWDEV-145570 - [HIP] - Add some hip_mem* APIs
ReviewBoardURL = http://ocltc.amd.com/reviews/r/14647/diff/
Affected files ...
... //depot/stg/opencl/drivers/opencl/api/hip/hip_memory.cpp#10 edit
---
api/hip/hip_memory.cpp | 125 +++++++++++++++++++++++++++++++++++------
1 file changed, 108 insertions(+), 17 deletions(-)
diff --git a/api/hip/hip_memory.cpp b/api/hip/hip_memory.cpp
index 8cb51be08d..c0cc21367a 100644
--- a/api/hip/hip_memory.cpp
+++ b/api/hip/hip_memory.cpp
@@ -21,8 +21,10 @@ THE SOFTWARE.
*/
#include
-
#include "hip_internal.hpp"
+#include "platform/context.hpp"
+#include "platform/command.hpp"
+#include "platform/memory.hpp"
hipError_t ihipMalloc(void** ptr, size_t sizeBytes, unsigned int flags)
{
@@ -119,7 +121,7 @@ hipError_t hipMemcpy(void* dst, const void* src, size_t sizeBytes, hipMemcpyKind
return hipSuccess;
}
-hipError_t hipMemsetAsync(void* dst, int value, size_t sizeBytes, hipStream_t stream) {
+hipError_t hipMemsetAsync(void* dst, int value, size_t sizeBytes, hipStream_t stream) {
HIP_INIT_API(dst, value, sizeBytes, stream);
assert(0 && "Unimplemented");
@@ -130,9 +132,36 @@ hipError_t hipMemsetAsync(void* dst, int value, size_t sizeBytes, hipStream_t s
hipError_t hipMemset(void* dst, int value, size_t sizeBytes) {
HIP_INIT_API(dst, value, sizeBytes);
- assert(0 && "Unimplemented");
+ amd::Device* device = g_context->devices()[0];
- return hipErrorUnknown;
+ amd::HostQueue* queue = new amd::HostQueue(*g_context, *device, 0,
+ amd::CommandQueue::RealTimeDisabled,
+ amd::CommandQueue::Priority::Normal);
+ if (!queue) {
+ return hipErrorOutOfMemory;
+ }
+
+ amd::Command::EventWaitList waitList;
+ amd::Memory* memory = amd::SvmManager::FindSvmBuffer(dst);
+
+
+ amd::Coord3D fillOffset(0, 0, 0);
+ amd::Coord3D fillSize(sizeBytes, 1, 1);
+ amd::FillMemoryCommand* command =
+ new amd::FillMemoryCommand(*queue, CL_COMMAND_FILL_BUFFER, waitList, *memory->asBuffer(),
+ &value, sizeof(int), fillOffset, fillSize);
+
+ if (!command) {
+ return hipErrorOutOfMemory;
+ }
+
+ command->enqueue();
+ command->awaitCompletion();
+ command->release();
+
+ queue->release();
+
+ return hipSuccess;
}
hipError_t hipMemPtrGetInfo(void *ptr, size_t *size) {
@@ -146,17 +175,21 @@ hipError_t hipMemPtrGetInfo(void *ptr, size_t *size) {
hipError_t hipHostFree(void* ptr) {
HIP_INIT_API(ptr);
- assert(0 && "Unimplemented");
-
- return hipErrorUnknown;
+ if (amd::SvmBuffer::malloced(ptr)) {
+ amd::SvmBuffer::free(*g_context, ptr);
+ return hipSuccess;
+ }
+ return hipErrorInvalidValue;
}
hipError_t hipFreeArray(hipArray* array) {
HIP_INIT_API(array);
- assert(0 && "Unimplemented");
-
- return hipErrorUnknown;
+ if (amd::SvmBuffer::malloced(array->data)) {
+ amd::SvmBuffer::free(*g_context, array->data);
+ return hipSuccess;
+ }
+ return hipErrorInvalidValue;
}
hipError_t hipMemGetAddressRange(hipDeviceptr_t* pbase, size_t* psize, hipDeviceptr_t dptr) {
@@ -170,25 +203,83 @@ hipError_t hipMemGetAddressRange(hipDeviceptr_t* pbase, size_t* psize, hipDevice
hipError_t hipMemGetInfo(size_t* free, size_t* total) {
HIP_INIT_API(free, total);
- assert(0 && "Unimplemented");
+ size_t freeMemory[2];
+ amd::Device* device = g_context->devices()[0];
+ if(!device) {
+ return hipErrorInvalidDevice;
+ }
- return hipErrorUnknown;
+ if(!device->globalFreeMemory(freeMemory)) {
+ return hipErrorInvalidValue;
+ }
+
+ *free = freeMemory[0];
+ *total = device->info().globalMemSize_;
+
+return hipSuccess;
}
+hipError_t ihipMallocPitch(void** ptr, size_t* pitch, size_t width, size_t height, size_t depth,
+ cl_mem_object_type imageType) {
+
+ amd::Device* device = g_context->devices()[0];
+
+ if ((width == 0) || (height == 0)) {
+ *ptr = nullptr;
+ return hipSuccess;
+ }
+ else if (!(device->info().image2DMaxWidth_ >= width &&
+ device->info().image2DMaxHeight_ >= height ) || (ptr == nullptr)) {
+ return hipErrorInvalidValue;
+ }
+
+ if (g_context->devices()[0]->info().maxMemAllocSize_ < (width * height)) {
+ return hipErrorOutOfMemory;
+ }
+
+ const cl_image_format image_format = { CL_R, CL_UNSIGNED_INT8 };
+ const amd::Image::Format imageFormat(image_format);
+
+ *pitch = width * imageFormat.getElementSize();
+
+ size_t sizeBytes = *pitch * height;
+ *ptr = amd::SvmBuffer::malloc(*g_context, CL_MEM_SVM_FINE_GRAIN_BUFFER, sizeBytes,
+ g_context->devices()[0]->info().memBaseAddrAlign_);
+
+ if (!*ptr) {
+ return hipErrorOutOfMemory;
+ }
+
+ return hipSuccess;
+}
+
+
hipError_t hipMallocPitch(void** ptr, size_t* pitch, size_t width, size_t height) {
HIP_INIT_API(ptr, pitch, width, height);
- assert(0 && "Unimplemented");
-
- return hipErrorUnknown;
+ return ihipMallocPitch(ptr, pitch, width, height, 1, CL_MEM_OBJECT_IMAGE2D);
}
hipError_t hipMalloc3D(hipPitchedPtr* pitchedDevPtr, hipExtent extent) {
HIP_INIT_API(pitchedDevPtr, &extent);
- assert(0 && "Unimplemented");
+ size_t pitch = 0;
- return hipErrorUnknown;
+ if (pitchedDevPtr == nullptr) {
+ return hipErrorInvalidValue;
+ }
+
+ hipError_t status = hipSuccess;
+ status = ihipMallocPitch(&pitchedDevPtr->ptr, &pitch, extent.width, extent.height, extent.depth,
+ CL_MEM_OBJECT_IMAGE3D);
+
+ if (status == hipSuccess) {
+ pitchedDevPtr->pitch = pitch;
+ pitchedDevPtr->xsize = extent.width;
+ pitchedDevPtr->ysize = extent.height;
+ }
+
+ return status;
}
hipError_t hipArrayCreate(hipArray** array, const HIP_ARRAY_DESCRIPTOR* pAllocateArray) {
From 66640b546fa1629b0c63a8ba416ee1eda75e0109 Mon Sep 17 00:00:00 2001
From: foreman
Date: Sun, 22 Apr 2018 21:17:27 -0400
Subject: [PATCH 025/282] P4 to Git Change 1544858 by skudchad@skudchad_rocm on
2018/04/22 21:07:25
SWDEV-144570 - [HIP] - Fix a few APIs and typos.
Affected files ...
... //depot/stg/opencl/drivers/opencl/api/hip/hip_device_runtime.cpp#6 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_platform.cpp#6 edit
---
api/hip/hip_device_runtime.cpp | 16 ++++++++++++----
api/hip/hip_platform.cpp | 2 ++
2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/api/hip/hip_device_runtime.cpp b/api/hip/hip_device_runtime.cpp
index d0d9c1145b..effce5974f 100644
--- a/api/hip/hip_device_runtime.cpp
+++ b/api/hip/hip_device_runtime.cpp
@@ -349,9 +349,9 @@ hipError_t hipDeviceGetStreamPriorityRange ( int* leastPriority, int* greatestPr
hipError_t hipDeviceReset ( void ) {
HIP_INIT_API();
- assert(0 && "Unimplemented");
+ /* FIXME */
- return hipErrorUnknown;
+ return hipSuccess;
}
hipError_t hipDeviceSetCacheConfig ( hipFuncCache_t cacheConfig ) {
@@ -429,13 +429,21 @@ hipError_t hipSetDevice ( int device ) {
return hipSuccess;
}
- return hipErrorInvalidValue;
+ return hipErrorInvalidDevice;
}
hipError_t hipSetDeviceFlags ( unsigned int flags ) {
HIP_INIT_API(flags);
- assert(0 && "Unimplemented");
+ /* FIXME */
+ /* Not all of Ctx may be implemented */
+
+ unsigned supportedFlags =
+ hipDeviceScheduleMask | hipDeviceMapHost | hipDeviceLmemResizeToMax;
+
+ if (flags & (~supportedFlags)) {
+ return hipErrorInvalidValue;
+ }
return hipSuccess;
}
diff --git a/api/hip/hip_platform.cpp b/api/hip/hip_platform.cpp
index d66bf0930c..a9c52bac2e 100644
--- a/api/hip/hip_platform.cpp
+++ b/api/hip/hip_platform.cpp
@@ -272,6 +272,8 @@ void hipLaunchKernelGGLImpl(
uint32_t sharedMemBytes,
hipStream_t stream,
void** kernarg) {
+
+ assert(0 && "Unimplemented");
}
}
From 13355e5de5d8cf1c440a55be1a9ce9795d26c7ed Mon Sep 17 00:00:00 2001
From: foreman
Date: Tue, 24 Apr 2018 14:05:20 -0400
Subject: [PATCH 026/282] P4 to Git Change 1545750 by
skudchad@skudchad_test2_win_opencl on 2018/04/24 13:55:57
SWDEV-145570 - [HIP] - Add some hip_mem* APIs. Part 2.
ReviewBoardURL = http://ocltc.amd.com/reviews/r/14681/diff/
Affected files ...
... //depot/stg/opencl/drivers/opencl/api/hip/hip_memory.cpp#11 edit
---
api/hip/hip_memory.cpp | 113 +++++++++++++++++++++++++++++++++++------
1 file changed, 98 insertions(+), 15 deletions(-)
diff --git a/api/hip/hip_memory.cpp b/api/hip/hip_memory.cpp
index c0cc21367a..68eb04ac70 100644
--- a/api/hip/hip_memory.cpp
+++ b/api/hip/hip_memory.cpp
@@ -26,6 +26,9 @@ THE SOFTWARE.
#include "platform/command.hpp"
#include "platform/memory.hpp"
+extern void getChannelOrderAndType(const hipChannelFormatDesc& desc, enum hipTextureReadMode readMode,
+ cl_channel_order* channelOrder, cl_channel_type* channelType);
+
hipError_t ihipMalloc(void** ptr, size_t sizeBytes, unsigned int flags)
{
if (sizeBytes == 0) {
@@ -167,9 +170,15 @@ hipError_t hipMemset(void* dst, int value, size_t sizeBytes) {
hipError_t hipMemPtrGetInfo(void *ptr, size_t *size) {
HIP_INIT_API(ptr, size);
- assert(0 && "Unimplemented");
+ amd::Memory* svmMem = amd::SvmManager::FindSvmBuffer(ptr);
- return hipErrorUnknown;
+ if (svmMem == nullptr) {
+ return hipErrorInvalidValue;
+ }
+
+ *size = svmMem->getSize();
+
+ return hipSuccess;
}
hipError_t hipHostFree(void* ptr) {
@@ -195,9 +204,18 @@ hipError_t hipFreeArray(hipArray* array) {
hipError_t hipMemGetAddressRange(hipDeviceptr_t* pbase, size_t* psize, hipDeviceptr_t dptr) {
HIP_INIT_API(pbase, psize, dptr);
- assert(0 && "Unimplemented");
+ // Since we are using SVM buffer DevicePtr and HostPtr is the same
+ void* ptr = dptr;
+ amd::Memory* svmMem = amd::SvmManager::FindSvmBuffer(ptr);
- return hipErrorUnknown;
+ if (svmMem == nullptr) {
+ return hipErrorInvalidDevicePointer;
+ }
+
+ *pbase = ptr;
+ *psize = svmMem->getSize();
+
+ return hipSuccess;
}
hipError_t hipMemGetInfo(size_t* free, size_t* total) {
@@ -220,7 +238,7 @@ return hipSuccess;
}
hipError_t ihipMallocPitch(void** ptr, size_t* pitch, size_t width, size_t height, size_t depth,
- cl_mem_object_type imageType) {
+ cl_mem_object_type imageType, const cl_image_format* image_format) {
amd::Device* device = g_context->devices()[0];
@@ -237,17 +255,16 @@ hipError_t ihipMallocPitch(void** ptr, size_t* pitch, size_t width, size_t heigh
return hipErrorOutOfMemory;
}
- const cl_image_format image_format = { CL_R, CL_UNSIGNED_INT8 };
- const amd::Image::Format imageFormat(image_format);
+ const amd::Image::Format imageFormat(*image_format);
*pitch = width * imageFormat.getElementSize();
- size_t sizeBytes = *pitch * height;
+ size_t sizeBytes = *pitch * height * depth;
*ptr = amd::SvmBuffer::malloc(*g_context, CL_MEM_SVM_FINE_GRAIN_BUFFER, sizeBytes,
g_context->devices()[0]->info().memBaseAddrAlign_);
if (!*ptr) {
- return hipErrorOutOfMemory;
+ return hipErrorMemoryAllocation;
}
return hipSuccess;
@@ -257,7 +274,8 @@ hipError_t ihipMallocPitch(void** ptr, size_t* pitch, size_t width, size_t heigh
hipError_t hipMallocPitch(void** ptr, size_t* pitch, size_t width, size_t height) {
HIP_INIT_API(ptr, pitch, width, height);
- return ihipMallocPitch(ptr, pitch, width, height, 1, CL_MEM_OBJECT_IMAGE2D);
+ const cl_image_format image_format = { CL_R, CL_UNSIGNED_INT8 };
+ return ihipMallocPitch(ptr, pitch, width, height, 1, CL_MEM_OBJECT_IMAGE2D, &image_format);
}
hipError_t hipMalloc3D(hipPitchedPtr* pitchedDevPtr, hipExtent extent) {
@@ -269,9 +287,10 @@ hipError_t hipMalloc3D(hipPitchedPtr* pitchedDevPtr, hipExtent extent) {
return hipErrorInvalidValue;
}
+ const cl_image_format image_format = { CL_R, CL_UNSIGNED_INT8 };
hipError_t status = hipSuccess;
status = ihipMallocPitch(&pitchedDevPtr->ptr, &pitch, extent.width, extent.height, extent.depth,
- CL_MEM_OBJECT_IMAGE3D);
+ CL_MEM_OBJECT_IMAGE3D, &image_format);
if (status == hipSuccess) {
pitchedDevPtr->pitch = pitch;
@@ -294,18 +313,82 @@ hipError_t hipMallocArray(hipArray** array, const hipChannelFormatDesc* desc,
size_t width, size_t height, unsigned int flags) {
HIP_INIT_API(array, desc, width, height, flags);
- assert(0 && "Unimplemented");
+ if (width == 0) {
+ return hipErrorInvalidValue;
+ }
- return hipErrorUnknown;
+ *array = (hipArray*)malloc(sizeof(hipArray));
+ array[0]->type = flags;
+ array[0]->width = width;
+ array[0]->height = height;
+ array[0]->depth = 1;
+ array[0]->desc = *desc;
+ array[0]->isDrv = false;
+ array[0]->textureType = hipTextureType2D;
+ void** ptr = &array[0]->data;
+
+ cl_channel_order channelOrder;
+ cl_channel_type channelType;
+ getChannelOrderAndType(*desc, hipReadModeElementType, &channelOrder, &channelType);
+
+ const cl_image_format image_format = { channelOrder, channelType };
+
+ // Dummy flags check
+ switch (flags) {
+ case hipArrayLayered:
+ case hipArrayCubemap:
+ case hipArraySurfaceLoadStore:
+ case hipArrayTextureGather:
+ assert(0 && "Unspported");
+ break;
+ case hipArrayDefault:
+ default:
+ break;
+ }
+ size_t pitch = 0;
+ hipError_t status = ihipMallocPitch(ptr, &pitch, width, height, 1, CL_MEM_OBJECT_IMAGE2D,
+ &image_format);
+
+ return status;
}
hipError_t hipMalloc3DArray(hipArray_t* array, const struct hipChannelFormatDesc* desc,
struct hipExtent extent, unsigned int flags) {
HIP_INIT_API(array, desc, &extent, flags);
- assert(0 && "Unimplemented");
+ *array = (hipArray*)malloc(sizeof(hipArray));
+ array[0]->type = flags;
+ array[0]->width = extent.width;
+ array[0]->height = extent.height;
+ array[0]->depth = extent.depth;
+ array[0]->desc = *desc;
+ array[0]->isDrv = false;
+ array[0]->textureType = hipTextureType3D;
+ void** ptr = &array[0]->data;
- return hipErrorUnknown;
+ cl_channel_order channelOrder;
+ cl_channel_type channelType;
+ getChannelOrderAndType(*desc, hipReadModeElementType, &channelOrder, &channelType);
+
+ const cl_image_format image_format = { channelOrder, channelType };
+
+ // Dummy flags check
+ switch (flags) {
+ case hipArrayLayered:
+ case hipArrayCubemap:
+ case hipArraySurfaceLoadStore:
+ case hipArrayTextureGather:
+ assert(0 && "Unspported");
+ break;
+ case hipArrayDefault:
+ default:
+ break;
+ }
+ size_t pitch = 0;
+ hipError_t status = ihipMallocPitch(ptr, &pitch, extent.width, extent.height, extent.depth,
+ CL_MEM_OBJECT_IMAGE3D, &image_format);
+
+ return status;
}
hipError_t hipHostGetFlags(unsigned int* flagsPtr, void* hostPtr) {
From d2fbde728c3227c586166dd91a6a664c08e2cd30 Mon Sep 17 00:00:00 2001
From: foreman
Date: Tue, 24 Apr 2018 16:49:38 -0400
Subject: [PATCH 027/282] P4 to Git Change 1545859 by
cpaquot@cpaquot-ocl-lc-lnx on 2018/04/24 16:44:17
SWDEV-145570 - [HIP] Get hipCtx_simple to pass
Implemented hipCtxGetDevice
hipCtxCreate must push the created context onto the context stack
hipCtxDestroy must check if the top of the stack is the context being destroy
and not just pop the top of the stack w/o checking.
Affected files ...
... //depot/stg/opencl/drivers/opencl/api/hip/hip_context.cpp#8 edit
---
api/hip/hip_context.cpp | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/api/hip/hip_context.cpp b/api/hip/hip_context.cpp
index 2e189f1351..e25a87bde8 100644
--- a/api/hip/hip_context.cpp
+++ b/api/hip/hip_context.cpp
@@ -71,6 +71,7 @@ hipError_t hipCtxCreate(hipCtx_t *ctx, unsigned int flags, hipDevice_t device)
// Increment ref count for device primary context
g_devices[device]->retain();
+ g_ctxtStack.push(g_devices[device]);
return hipSuccess;
}
@@ -122,7 +123,7 @@ hipError_t hipCtxDestroy(hipCtx_t ctx) {
}
// Need to remove the ctx of calling thread if its the top one
- if (g_context == amdContext) {
+ if (!g_ctxtStack.empty() && g_ctxtStack.top() == amdContext) {
g_ctxtStack.pop();
}
@@ -188,7 +189,16 @@ hipError_t hipDriverGetVersion(int* driverVersion) {
hipError_t hipCtxGetDevice(hipDevice_t* device) {
HIP_INIT_API(device);
- assert(0 && "Unimplemented");
+ if (device != nullptr) {
+ for (unsigned int i = 0; i < g_devices.size(); i++) {
+ if (g_devices[i] == g_context) {
+ *device = static_cast(i);
+ return hipSuccess;
+ }
+ }
+ } else {
+ return hipErrorInvalidValue;
+ }
return hipErrorUnknown;
}
@@ -279,4 +289,4 @@ hipError_t hipDevicePrimaryCtxSetFlags(hipDevice_t dev, unsigned int flags) {
assert(0 && "Unimplemented");
return hipErrorUnknown;
-}
\ No newline at end of file
+}
From 18c7c164c6a1182fc70a75d6b590b45bb8b80d48 Mon Sep 17 00:00:00 2001
From: foreman
Date: Wed, 25 Apr 2018 12:32:11 -0400
Subject: [PATCH 028/282] P4 to Git Change 1546224 by
skudchad@skudchad_test2_win_opencl on 2018/04/25 12:24:40
SWDEV-145570 - [HIP] - Add hipMemcpyTo/FromArray APIs.
ReviewBoardURL = http://ocltc.amd.com/reviews/r/14696/diff/
Affected files ...
... //depot/stg/opencl/drivers/opencl/api/hip/hip_memory.cpp#12 edit
---
api/hip/hip_memory.cpp | 84 +++++++++++++++++++++++++++++++++++++++---
1 file changed, 78 insertions(+), 6 deletions(-)
diff --git a/api/hip/hip_memory.cpp b/api/hip/hip_memory.cpp
index 68eb04ac70..23a631881f 100644
--- a/api/hip/hip_memory.cpp
+++ b/api/hip/hip_memory.cpp
@@ -555,22 +555,94 @@ hipError_t hipMemcpy2DToArray(hipArray* dst, size_t wOffset, size_t hOffset, con
return hipErrorUnknown;
}
-hipError_t hipMemcpyToArray(hipArray* dst, size_t wOffset, size_t hOffset, const void* src,
+hipError_t hipMemcpyToArray(hipArray* dstArray, size_t wOffset, size_t hOffset, const void* src,
size_t count, hipMemcpyKind kind) {
- HIP_INIT_API(dst, wOffset, hOffset, src, count, kind);
+ HIP_INIT_API(dstArray, wOffset, hOffset, src, count, kind);
- assert(0 && "Unimplemented");
+ amd::Device* device = g_context->devices()[0];
- return hipErrorUnknown;
+ amd::HostQueue* queue = new amd::HostQueue(*g_context, *device, 0,
+ amd::CommandQueue::RealTimeDisabled,
+ amd::CommandQueue::Priority::Normal);
+ if (!queue) {
+ return hipErrorOutOfMemory;
+ }
+
+ amd::Command* command;
+ amd::Command::EventWaitList waitList;
+ amd::Memory* memory;
+
+ amd::Coord3D dstOffset(wOffset, hOffset, 0);
+
+ switch (kind) {
+ case hipMemcpyDeviceToHost:
+ assert(!"Invalid case");
+ /* fall thru */
+ case hipMemcpyHostToDevice:
+ memory = amd::SvmManager::FindSvmBuffer(dstArray->data);
+ command = new amd::WriteMemoryCommand(*queue, CL_COMMAND_WRITE_BUFFER, waitList,
+ *memory->asBuffer(), dstOffset, count, src);
+ break;
+ default:
+ assert(!"Shouldn't reach here");
+ break;
+ }
+ if (!command) {
+ return hipErrorOutOfMemory;
+ }
+
+ command->enqueue();
+ command->awaitCompletion();
+ command->release();
+
+ queue->release();
+
+ return hipSuccess;
}
hipError_t hipMemcpyFromArray(void* dst, hipArray_const_t srcArray, size_t wOffset, size_t hOffset,
size_t count, hipMemcpyKind kind) {
HIP_INIT_API(dst, srcArray, wOffset, hOffset, count, kind);
- assert(0 && "Unimplemented");
+ amd::Device* device = g_context->devices()[0];
- return hipErrorUnknown;
+ amd::HostQueue* queue = new amd::HostQueue(*g_context, *device, 0,
+ amd::CommandQueue::RealTimeDisabled,
+ amd::CommandQueue::Priority::Normal);
+ if (!queue) {
+ return hipErrorOutOfMemory;
+ }
+
+ amd::Command* command;
+ amd::Command::EventWaitList waitList;
+ amd::Memory* memory;
+
+ amd::Coord3D srcOffset(wOffset, hOffset, 0);
+
+ switch (kind) {
+ case hipMemcpyHostToDevice:
+ assert(!"Invalid case");
+ /* fall thru */
+ case hipMemcpyDeviceToHost:
+ memory = amd::SvmManager::FindSvmBuffer(srcArray->data);
+ command = new amd::ReadMemoryCommand(*queue, CL_COMMAND_READ_BUFFER, waitList,
+ *memory->asBuffer(), srcOffset, count, dst);
+ break;
+ default:
+ assert(!"Shouldn't reach here");
+ break;
+ }
+ if (!command) {
+ return hipErrorOutOfMemory;
+ }
+
+ command->enqueue();
+ command->awaitCompletion();
+ command->release();
+
+ queue->release();
+
+ return hipSuccess;
}
hipError_t hipMemcpyHtoA(hipArray* dstArray, size_t dstOffset, const void* srcHost, size_t count) {
From 2605d50ce7d87e2fe98346ebc0ab6de1b2f3d8ad Mon Sep 17 00:00:00 2001
From: foreman
Date: Fri, 27 Apr 2018 21:21:31 -0400
Subject: [PATCH 029/282] P4 to Git Change 1547563 by
lmoriche@lmoriche_opencl_dev2 on 2018/04/27 21:10:47
SWDEV-145570 - [HIP] - Add support for HCC compiled binaries.
Affected files ...
... //depot/stg/opencl/drivers/opencl/api/hip/build/Makefile.hip#2 edit
... //depot/stg/opencl/drivers/opencl/api/hip/elfio/elf_types.hpp#1 add
... //depot/stg/opencl/drivers/opencl/api/hip/elfio/elfio.hpp#1 add
... //depot/stg/opencl/drivers/opencl/api/hip/elfio/elfio_dump.hpp#1 add
... //depot/stg/opencl/drivers/opencl/api/hip/elfio/elfio_dynamic.hpp#1 add
... //depot/stg/opencl/drivers/opencl/api/hip/elfio/elfio_header.hpp#1 add
... //depot/stg/opencl/drivers/opencl/api/hip/elfio/elfio_note.hpp#1 add
... //depot/stg/opencl/drivers/opencl/api/hip/elfio/elfio_relocation.hpp#1 add
... //depot/stg/opencl/drivers/opencl/api/hip/elfio/elfio_section.hpp#1 add
... //depot/stg/opencl/drivers/opencl/api/hip/elfio/elfio_segment.hpp#1 add
... //depot/stg/opencl/drivers/opencl/api/hip/elfio/elfio_strings.hpp#1 add
... //depot/stg/opencl/drivers/opencl/api/hip/elfio/elfio_symbols.hpp#1 add
... //depot/stg/opencl/drivers/opencl/api/hip/elfio/elfio_utils.hpp#1 add
... //depot/stg/opencl/drivers/opencl/api/hip/hip_platform.cpp#7 edit
---
api/hip/hip_platform.cpp | 305 +++++++++++++++++++++++++++++----------
1 file changed, 227 insertions(+), 78 deletions(-)
diff --git a/api/hip/hip_platform.cpp b/api/hip/hip_platform.cpp
index a9c52bac2e..9c9c3b1ecf 100644
--- a/api/hip/hip_platform.cpp
+++ b/api/hip/hip_platform.cpp
@@ -26,9 +26,10 @@ THE SOFTWARE.
#include "platform/program.hpp"
#include "platform/runtime.hpp"
-constexpr unsigned __cudaFatMAGIC = 0x1ee55a01;
+#include
+#include "elfio.hpp"
+
constexpr unsigned __cudaFatMAGIC2 = 0x466243b1;
-constexpr unsigned __cudaFatMAGIC3 = 0xba55ed50;
struct __CudaFatBinaryWrapper {
unsigned int magic;
@@ -37,53 +38,9 @@ struct __CudaFatBinaryWrapper {
void* dummy1;
};
-struct __CudaFatBinaryHeader {
- unsigned int magic;
- unsigned short version;
- unsigned short headerSize;
- unsigned long long int fatSize;
-};
-
-struct __CudaPartHeader {
- unsigned short type;
- unsigned short dummy1;
- unsigned int headerSize;
- unsigned long long int partSize;
- unsigned long long int dummy2;
- unsigned int dummy3;
- unsigned int subarch;
-};
-
-static hipModule_t registerCudaFatBinary(const __CudaFatBinaryHeader* fbheader)
-{
- const __CudaPartHeader* pheader = reinterpret_cast(
- reinterpret_cast(fbheader) + fbheader->headerSize);
- const __CudaPartHeader* end = reinterpret_cast(
- reinterpret_cast(pheader) + fbheader->fatSize);
-
- amd::Program* program = new amd::Program(*g_context);
- if (!program) return nullptr;
-
- while (pheader < end) {
- if (true/*pheader->subarch == match a device in the context*/) {
- const void *image = reinterpret_cast(
- reinterpret_cast(pheader) + pheader->headerSize);
- size_t size = pheader->partSize;
- if (CL_SUCCESS != program->addDeviceProgram(*g_context->devices()[0], image, size) ||
- CL_SUCCESS != program->build(g_context->devices(), nullptr, nullptr, nullptr)) {
- return nullptr;
- }
- break;
- }
- pheader = reinterpret_cast(
- reinterpret_cast(pheader) + pheader->headerSize + pheader->partSize);
- }
-
- return reinterpret_cast(as_cl(program));
-}
-
#define CLANG_OFFLOAD_BUNDLER_MAGIC_STR "__CLANG_OFFLOAD_BUNDLE__"
-#define AMDGCN_AMDHSA_TRIPLE "openmp-amdgcn--amdhsa"
+#define OPENMP_AMDGCN_AMDHSA_TRIPLE "openmp-amdgcn--amdhsa"
+#define HCC_AMDGCN_AMDHSA_TRIPLE "hcc-amdgcn--amdhsa"
struct __ClangOffloadBundleDesc {
uint64_t offset;
@@ -98,23 +55,35 @@ struct __ClangOffloadBundleHeader {
__ClangOffloadBundleDesc desc[1];
};
-static hipModule_t registerOffloadBundle(const __ClangOffloadBundleHeader* obheader)
+extern "C" hipModule_t __hipRegisterFatBinary(const void* data)
{
+ HIP_INIT();
+
+ const __CudaFatBinaryWrapper* fbwrapper = reinterpret_cast(data);
+ if (fbwrapper->magic != __cudaFatMAGIC2 || fbwrapper->version != 1) {
+ return nullptr;
+ }
+ std::string magic((char*)fbwrapper->binary, sizeof(CLANG_OFFLOAD_BUNDLER_MAGIC_STR) - 1);
+ if (magic.compare(CLANG_OFFLOAD_BUNDLER_MAGIC_STR)) {
+ return nullptr;
+ }
+
amd::Program* program = new amd::Program(*g_context);
if (!program)
return nullptr;
- const __ClangOffloadBundleDesc* desc = &obheader->desc[0];
+ const auto obheader = reinterpret_cast(fbwrapper->binary);
+ const auto* desc = &obheader->desc[0];
for (uint64_t i = 0; i < obheader->numBundles; ++i,
desc = reinterpret_cast(
reinterpret_cast(&desc->triple[0]) + desc->tripleSize)) {
- std::string triple(desc->triple, sizeof(AMDGCN_AMDHSA_TRIPLE) - 1);
- if (triple.compare(AMDGCN_AMDHSA_TRIPLE))
+ std::string triple(desc->triple, sizeof(OPENMP_AMDGCN_AMDHSA_TRIPLE) - 1);
+ if (triple.compare(OPENMP_AMDGCN_AMDHSA_TRIPLE))
continue;
- std::string target(desc->triple + sizeof(AMDGCN_AMDHSA_TRIPLE),
- desc->tripleSize - sizeof(AMDGCN_AMDHSA_TRIPLE));
+ std::string target(desc->triple + sizeof(OPENMP_AMDGCN_AMDHSA_TRIPLE),
+ desc->tripleSize - sizeof(OPENMP_AMDGCN_AMDHSA_TRIPLE));
if (target.compare(g_context->devices()[0]->info().name_))
continue;
@@ -130,28 +99,6 @@ static hipModule_t registerOffloadBundle(const __ClangOffloadBundleHeader* obhea
return reinterpret_cast(as_cl(program));
}
-
-extern "C" hipModule_t __hipRegisterFatBinary(const void* data)
-{
- HIP_INIT();
-
- const __CudaFatBinaryWrapper* fbwrapper = reinterpret_cast(data);
- if (fbwrapper->magic != __cudaFatMAGIC2 || fbwrapper->version != 1) {
- return nullptr;
- }
- const __CudaFatBinaryHeader* fbheader = reinterpret_cast(fbwrapper->binary);
- if (fbheader->magic == __cudaFatMAGIC3 && fbheader->version == 1) {
- return registerCudaFatBinary(fbheader);
- }
-
- std::string magic((char*)fbwrapper->binary, sizeof(CLANG_OFFLOAD_BUNDLER_MAGIC_STR) - 1);
- if (!magic.compare(CLANG_OFFLOAD_BUNDLER_MAGIC_STR)) {
- return registerOffloadBundle(reinterpret_cast(fbwrapper->binary));
- }
-
- return nullptr;
-}
-
std::map g_functions;
@@ -265,15 +212,217 @@ extern "C" hipError_t hipLaunchByPtr(const void *hostFunction)
namespace hip_impl {
+struct dl_phdr_info {
+ ELFIO::Elf64_Addr dlpi_addr;
+ const char *dlpi_name;
+ const ELFIO::Elf64_Phdr *dlpi_phdr;
+ ELFIO::Elf64_Half dlpi_phnum;
+};
+
+extern "C" int dl_iterate_phdr(
+ int (*callback) (struct dl_phdr_info *info, size_t size, void *data), void *data
+);
+
+struct Symbol {
+ std::string name;
+ ELFIO::Elf64_Addr value = 0;
+ ELFIO::Elf_Xword size = 0;
+ ELFIO::Elf_Half sect_idx = 0;
+ uint8_t bind = 0;
+ uint8_t type = 0;
+ uint8_t other = 0;
+};
+
+inline Symbol read_symbol(const ELFIO::symbol_section_accessor& section, unsigned int idx) {
+ assert(idx < section.get_symbols_num());
+
+ Symbol r;
+ section.get_symbol(idx, r.name, r.value, r.size, r.bind, r.type, r.sect_idx, r.other);
+
+ return r;
+}
+
+template
+inline ELFIO::section* find_section_if(ELFIO::elfio& reader, P p) {
+ const auto it = find_if(reader.sections.begin(), reader.sections.end(), std::move(p));
+
+ return it != reader.sections.end() ? *it : nullptr;
+}
+
+std::vector> function_names_for(const ELFIO::elfio& reader,
+ ELFIO::section* symtab) {
+ std::vector> r;
+ ELFIO::symbol_section_accessor symbols{reader, symtab};
+
+ for (auto i = 0u; i != symbols.get_symbols_num(); ++i) {
+ auto tmp = read_symbol(symbols, i);
+
+ if (tmp.type == STT_FUNC && tmp.sect_idx != SHN_UNDEF && !tmp.name.empty()) {
+ r.emplace_back(tmp.value, tmp.name);
+ }
+ }
+
+ return r;
+}
+
+const std::vector>& function_names_for_process() {
+ static constexpr const char self[] = "/proc/self/exe";
+
+ static std::vector> r;
+ static std::once_flag f;
+
+ std::call_once(f, []() {
+ ELFIO::elfio reader;
+
+ if (reader.load(self)) {
+ const auto it = find_section_if(
+ reader, [](const ELFIO::section* x) { return x->get_type() == SHT_SYMTAB; });
+
+ if (it) r = function_names_for(reader, it);
+ }
+ });
+
+ return r;
+}
+
+
+const std::unordered_map& function_names()
+{
+ static std::unordered_map r{
+ function_names_for_process().cbegin(),
+ function_names_for_process().cend()};
+ static std::once_flag f;
+
+ std::call_once(f, []() {
+ dl_iterate_phdr([](dl_phdr_info* info, size_t, void*) {
+ ELFIO::elfio reader;
+
+ if (reader.load(info->dlpi_name)) {
+ const auto it = find_section_if(
+ reader, [](const ELFIO::section* x) { return x->get_type() == SHT_SYMTAB; });
+
+ if (it) {
+ auto n = function_names_for(reader, it);
+
+ for (auto&& f : n) f.first += info->dlpi_addr;
+
+ r.insert(make_move_iterator(n.begin()), make_move_iterator(n.end()));
+ }
+ }
+ return 0;
+ },
+ nullptr);
+ });
+
+ return r;
+}
+
+std::vector bundles_for_process() {
+ static constexpr const char self[] = "/proc/self/exe";
+ static constexpr const char kernel_section[] = ".kernel";
+ std::vector r;
+
+ ELFIO::elfio reader;
+
+ if (reader.load(self)) {
+ auto it = find_section_if(
+ reader, [](const ELFIO::section* x) { return x->get_name() == kernel_section; });
+
+ if (it) r.insert(r.end(), it->get_data(), it->get_data() + it->get_size());
+ }
+
+ return r;
+}
+
+const std::vector& modules() {
+ static std::vector r;
+ static std::once_flag f;
+
+ std::call_once(f, []() {
+ static std::vector> bundles{bundles_for_process()};
+
+ dl_iterate_phdr(
+ [](dl_phdr_info* info, std::size_t, void*) {
+ ELFIO::elfio tmp;
+ if (tmp.load(info->dlpi_name)) {
+ const auto it = find_section_if(
+ tmp, [](const ELFIO::section* x) { return x->get_name() == ".kernel"; });
+
+ if (it) bundles.emplace_back(it->get_data(), it->get_data() + it->get_size());
+ }
+ return 0;
+ },
+ nullptr);
+
+ for (auto&& bundle : bundles) {
+ std::string magic(&bundle[0], sizeof(CLANG_OFFLOAD_BUNDLER_MAGIC_STR) - 1);
+ if (magic.compare(CLANG_OFFLOAD_BUNDLER_MAGIC_STR))
+ continue;
+
+ const auto obheader = reinterpret_cast(&bundle[0]);
+ const auto* desc = &obheader->desc[0];
+ for (uint64_t i = 0; i < obheader->numBundles; ++i,
+ desc = reinterpret_cast(
+ reinterpret_cast(&desc->triple[0]) + desc->tripleSize)) {
+
+ std::string triple(desc->triple, sizeof(HCC_AMDGCN_AMDHSA_TRIPLE) - 1);
+ if (triple.compare(HCC_AMDGCN_AMDHSA_TRIPLE))
+ continue;
+
+ std::string target(desc->triple + sizeof(HCC_AMDGCN_AMDHSA_TRIPLE),
+ desc->tripleSize - sizeof(HCC_AMDGCN_AMDHSA_TRIPLE));
+
+ if (!target.compare(g_context->devices()[0]->info().name_)) {
+ hipModule_t module;
+ if (hipSuccess == hipModuleLoadData(&module, reinterpret_cast(
+ reinterpret_cast(obheader) + desc->offset)))
+ r.push_back(module);
+ break;
+ }
+ }
+ }
+ });
+
+ return r;
+}
+
+const std::unordered_map& functions()
+{
+ static std::unordered_map r;
+ static std::once_flag f;
+
+ std::call_once(f, []() {
+ for (auto&& function : function_names()) {
+ for (auto&& module : modules()) {
+ hipFunction_t f;
+ if (hipSuccess == hipModuleGetFunction(&f, module, function.second.c_str()))
+ r[function.first] = f;
+ }
+ }
+ });
+
+ return r;
+}
+
+
void hipLaunchKernelGGLImpl(
uintptr_t function_address,
const dim3& numBlocks,
const dim3& dimBlocks,
uint32_t sharedMemBytes,
hipStream_t stream,
- void** kernarg) {
+ void** kernarg)
+{
+ HIP_INIT();
- assert(0 && "Unimplemented");
+ const auto it = functions().find(function_address);
+ if (it == functions().cend())
+ return;
+
+ hipModuleLaunchKernel(it->second,
+ numBlocks.x, numBlocks.y, numBlocks.z,
+ dimBlocks.x, dimBlocks.y, dimBlocks.z,
+ sharedMemBytes, stream, nullptr, kernarg);
}
}
From 1cb879968b3238d7a60e26ad260f4ccc07563fdc Mon Sep 17 00:00:00 2001
From: foreman
Date: Sun, 29 Apr 2018 15:04:45 -0400
Subject: [PATCH 030/282] P4 to Git Change 1547669 by
lmoriche@lmoriche_opencl_dev2 on 2018/04/29 14:53:31
SWDEV-145570 - [HIP] Fix kernel disptach for HCC compiled programs.
Affected files ...
... //depot/stg/opencl/drivers/opencl/api/hip/hip_module.cpp#5 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_platform.cpp#8 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rockernel.cpp#34 edit
---
api/hip/hip_module.cpp | 7 ++++---
api/hip/hip_platform.cpp | 2 +-
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/api/hip/hip_module.cpp b/api/hip/hip_module.cpp
index 0bcae3551b..268b92284b 100644
--- a/api/hip/hip_module.cpp
+++ b/api/hip/hip_module.cpp
@@ -151,7 +151,7 @@ hipError_t hipModuleLaunchKernel(hipFunction_t f,
}
size_t globalWorkOffset[3] = {0};
- size_t globalWorkSize[3] = { gridDimX, gridDimY, gridDimZ };
+ size_t globalWorkSize[3] = { gridDimX * blockDimX, gridDimY * blockDimY, gridDimZ * blockDimZ};
size_t localWorkSize[3] = { blockDimX, blockDimY, blockDimZ };
amd::NDRangeContainer ndrange(3, globalWorkOffset, globalWorkSize, localWorkSize);
amd::Command::EventWaitList waitList;
@@ -161,10 +161,11 @@ hipError_t hipModuleLaunchKernel(hipFunction_t f,
const amd::KernelParameterDescriptor& desc = signature.at(i);
if (kernelParams == nullptr) {
assert(extra);
- kernel->parameters().set(i, desc.size_, reinterpret_cast(extra[1]) + desc.offset_);
+ kernel->parameters().set(i, desc.size_, reinterpret_cast(extra[1]) + desc.offset_,
+ desc.type_ == T_POINTER/*svmBound*/);
} else {
assert(!extra);
- kernel->parameters().set(i, desc.size_, kernelParams[i]);
+ kernel->parameters().set(i, desc.size_, kernelParams[i], desc.type_ == T_POINTER/*svmBound*/);
}
}
diff --git a/api/hip/hip_platform.cpp b/api/hip/hip_platform.cpp
index 9c9c3b1ecf..7152458d38 100644
--- a/api/hip/hip_platform.cpp
+++ b/api/hip/hip_platform.cpp
@@ -417,7 +417,7 @@ void hipLaunchKernelGGLImpl(
const auto it = functions().find(function_address);
if (it == functions().cend())
- return;
+ assert(0);
hipModuleLaunchKernel(it->second,
numBlocks.x, numBlocks.y, numBlocks.z,
From 5fc5d098a95c17d1a51afbdf777da3183e16eadb Mon Sep 17 00:00:00 2001
From: foreman
Date: Mon, 30 Apr 2018 01:03:06 -0400
Subject: [PATCH 031/282] P4 to Git Change 1547686 by
cpaquot@cpaquot-ocl-lc-lnx on 2018/04/30 00:52:23
SWDEV-145570 - [HIP] CreateTexture with hipArray
Affected files ...
... //depot/stg/opencl/drivers/opencl/api/hip/hip_texture.cpp#6 edit
---
api/hip/hip_texture.cpp | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/api/hip/hip_texture.cpp b/api/hip/hip_texture.cpp
index fbc8c4b481..220332a57b 100644
--- a/api/hip/hip_texture.cpp
+++ b/api/hip/hip_texture.cpp
@@ -158,7 +158,26 @@ hipError_t hipCreateTextureObject(hipTextureObject_t* pTexObject, const hipResou
switch (pResDesc->resType) {
case hipResourceTypeArray:
- assert(0);
+ {
+ memory = amd::SvmManager::FindSvmBuffer(pResDesc->res.array.array->data);
+
+ getChannelOrderAndType(pResDesc->res.array.array->desc, pTexDesc->readMode,
+ &image_format.image_channel_order, &image_format.image_channel_data_type);
+ const amd::Image::Format imageFormat(image_format);
+ switch (pResDesc->res.array.array->type) {
+ case hipArrayLayered:
+ case hipArrayCubemap:
+ assert(0);
+ break;
+ case hipArraySurfaceLoadStore:
+ case hipArrayTextureGather:
+ case hipArrayDefault:
+ default:
+ image = new (*g_context) amd::Image(*memory->asBuffer(), CL_MEM_OBJECT_IMAGE2D, memory->getMemFlags(), imageFormat,
+ pResDesc->res.array.array->width, pResDesc->res.array.array->height, 1, 0, 0);
+ break;
+ }
+ }
break;
case hipResourceTypeMipmappedArray:
assert(0);
From 36d2d37804d5b997996415d651f340c02d3d50c5 Mon Sep 17 00:00:00 2001
From: foreman
Date: Mon, 30 Apr 2018 13:34:32 -0400
Subject: [PATCH 032/282] P4 to Git Change 1547825 by
cpaquot@cpaquot-ocl-lc-lnx on 2018/04/30 11:59:32
SWDEV-145570 - [HIP] Fixed release build
Affected files ...
... //depot/stg/opencl/drivers/opencl/api/hip/hip_memory.cpp#13 edit
---
api/hip/hip_memory.cpp | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/api/hip/hip_memory.cpp b/api/hip/hip_memory.cpp
index 23a631881f..02c5720df4 100644
--- a/api/hip/hip_memory.cpp
+++ b/api/hip/hip_memory.cpp
@@ -83,7 +83,7 @@ hipError_t hipMemcpy(void* dst, const void* src, size_t sizeBytes, hipMemcpyKind
return hipErrorOutOfMemory;
}
- amd::Command* command;
+ amd::Command* command = nullptr;
amd::Command::EventWaitList waitList;
amd::Memory* memory;
@@ -568,7 +568,7 @@ hipError_t hipMemcpyToArray(hipArray* dstArray, size_t wOffset, size_t hOffset,
return hipErrorOutOfMemory;
}
- amd::Command* command;
+ amd::Command* command = nullptr;
amd::Command::EventWaitList waitList;
amd::Memory* memory;
@@ -613,7 +613,7 @@ hipError_t hipMemcpyFromArray(void* dst, hipArray_const_t srcArray, size_t wOffs
return hipErrorOutOfMemory;
}
- amd::Command* command;
+ amd::Command* command = nullptr;
amd::Command::EventWaitList waitList;
amd::Memory* memory;
From 6f7e33cb91e43da7fa72756b9e7b7376aa99b56b Mon Sep 17 00:00:00 2001
From: foreman
Date: Mon, 30 Apr 2018 14:55:41 -0400
Subject: [PATCH 033/282] P4 to Git Change 1547830 by
skudchad@skudchad_test2_win_opencl on 2018/04/30 12:03:10
SWDEV-145570 - [HIP] - Add couple of hip_mem* APIs. Part 3.
ReviewBoardURL = http://ocltc.amd.com/reviews/r/14727/diff/
Affected files ...
... //depot/stg/opencl/drivers/opencl/api/hip/hip_memory.cpp#14 edit
---
api/hip/hip_memory.cpp | 236 +++++++++++++++++++++++++++++++++++++++--
1 file changed, 226 insertions(+), 10 deletions(-)
diff --git a/api/hip/hip_memory.cpp b/api/hip/hip_memory.cpp
index 02c5720df4..830865fb93 100644
--- a/api/hip/hip_memory.cpp
+++ b/api/hip/hip_memory.cpp
@@ -583,6 +583,8 @@ hipError_t hipMemcpyToArray(hipArray* dstArray, size_t wOffset, size_t hOffset,
command = new amd::WriteMemoryCommand(*queue, CL_COMMAND_WRITE_BUFFER, waitList,
*memory->asBuffer(), dstOffset, count, src);
break;
+ case hipMemcpyDeviceToDevice:
+ case hipMemcpyDefault:
default:
assert(!"Shouldn't reach here");
break;
@@ -628,6 +630,8 @@ hipError_t hipMemcpyFromArray(void* dst, hipArray_const_t srcArray, size_t wOffs
command = new amd::ReadMemoryCommand(*queue, CL_COMMAND_READ_BUFFER, waitList,
*memory->asBuffer(), srcOffset, count, dst);
break;
+ case hipMemcpyDeviceToDevice:
+ case hipMemcpyDefault:
default:
assert(!"Shouldn't reach here");
break;
@@ -648,41 +652,253 @@ hipError_t hipMemcpyFromArray(void* dst, hipArray_const_t srcArray, size_t wOffs
hipError_t hipMemcpyHtoA(hipArray* dstArray, size_t dstOffset, const void* srcHost, size_t count) {
HIP_INIT_API(dstArray, dstOffset, srcHost, count);
- assert(0 && "Unimplemented");
+ amd::Device* device = g_context->devices()[0];
- return hipErrorUnknown;
+ amd::HostQueue* queue = new amd::HostQueue(*g_context, *device, 0,
+ amd::CommandQueue::RealTimeDisabled,
+ amd::CommandQueue::Priority::Normal);
+ if (!queue) {
+ return hipErrorOutOfMemory;
+ }
+
+ amd::Command::EventWaitList waitList;
+ amd::Memory* memory = amd::SvmManager::FindSvmBuffer(dstArray->data);
+ amd::Command* command = new amd::WriteMemoryCommand(*queue, CL_COMMAND_WRITE_BUFFER, waitList,
+ *memory->asBuffer(), dstOffset, count, srcHost);
+
+ if (!command) {
+ return hipErrorOutOfMemory;
+ }
+
+ command->enqueue();
+ command->awaitCompletion();
+ command->release();
+
+ queue->release();
+
+ return hipSuccess;
}
hipError_t hipMemcpyAtoH(void* dst, hipArray* srcArray, size_t srcOffset, size_t count) {
HIP_INIT_API(dst, srcArray, srcOffset, count);
- assert(0 && "Unimplemented");
+ amd::Device* device = g_context->devices()[0];
- return hipErrorUnknown;
+ amd::HostQueue* queue = new amd::HostQueue(*g_context, *device, 0,
+ amd::CommandQueue::RealTimeDisabled,
+ amd::CommandQueue::Priority::Normal);
+ if (!queue) {
+ return hipErrorOutOfMemory;
+ }
+
+ amd::Command::EventWaitList waitList;
+ amd::Memory* memory = amd::SvmManager::FindSvmBuffer(srcArray->data);
+ amd::Command* command = new amd::ReadMemoryCommand(*queue, CL_COMMAND_READ_BUFFER, waitList,
+ *memory->asBuffer(), srcOffset, count, dst);
+
+ if (!command) {
+ return hipErrorOutOfMemory;
+ }
+
+ command->enqueue();
+ command->awaitCompletion();
+ command->release();
+
+ queue->release();
+
+ return hipSuccess;
}
hipError_t hipMemcpy3D(const struct hipMemcpy3DParms* p) {
HIP_INIT_API(p);
- assert(0 && "Unimplemented");
+ amd::Device* device = g_context->devices()[0];
- return hipErrorUnknown;
+ amd::HostQueue* queue = new amd::HostQueue(*g_context, *device, 0,
+ amd::CommandQueue::RealTimeDisabled,
+ amd::CommandQueue::Priority::Normal);
+ if (!queue) {
+ return hipErrorOutOfMemory;
+ }
+
+ size_t byteSize;
+ size_t srcPitchInBytes;
+ size_t dstPitchInbytes;
+ void* srcPtr;
+ void* dstPtr;
+ size_t srcOrigin[3];
+ size_t dstOrigin[3];
+ size_t region[3];
+ if (p->dstArray != nullptr) {
+ switch (p->dstArray->desc.f) {
+ case hipChannelFormatKindSigned:
+ byteSize = sizeof(int);
+ break;
+ case hipChannelFormatKindUnsigned:
+ byteSize = sizeof(unsigned int);
+ break;
+ case hipChannelFormatKindFloat:
+ byteSize = sizeof(float);
+ break;
+ case hipChannelFormatKindNone:
+ byteSize = sizeof(size_t);
+ break;
+ default:
+ byteSize = 1;
+ break;
+ }
+ region[2] = p->Depth;
+ region[1] = p->Height;
+ region[0] = p->WidthInBytes * byteSize;
+ srcOrigin[0] = p->srcXInBytes/byteSize;
+ srcOrigin[1] = p->srcY;
+ srcOrigin[2] = p->srcZ;
+ dstPitchInbytes = p->dstArray->width * byteSize;
+ srcPitchInBytes = p->srcPitch;
+ srcPtr = (void*)p->srcHost;
+ dstPtr = p->dstArray->data;
+ dstOrigin[0] = p->dstXInBytes/byteSize;
+ dstOrigin[1] = p->dstY;
+ dstOrigin[2] = p->dstZ;
+ } else {
+ region[2] = p->extent.depth;
+ region[1] = p->extent.height;
+ region[0] = p->extent.width;
+ srcOrigin[0] = p->srcXInBytes;
+ srcOrigin[1] = p->srcY;
+ srcOrigin[2] = p->srcZ;
+ srcPitchInBytes = p->srcPtr.pitch;
+ dstPitchInbytes = p->dstPtr.pitch;
+ srcPtr = p->srcPtr.ptr;
+ dstPtr = p->dstPtr.ptr;
+ dstOrigin[0] = p->dstXInBytes;
+ dstOrigin[1] = p->dstY;
+ dstOrigin[2] = p->dstZ;
+ }
+
+ // Create buffer rectangle info structure
+ amd::BufferRect srcRect;
+ amd::BufferRect dstRect;
+ amd::Memory* src = amd::SvmManager::FindSvmBuffer(srcPtr);
+ amd::Memory* dst = amd::SvmManager::FindSvmBuffer(dstPtr);
+
+ size_t src_slice_pitch = srcPitchInBytes * p->srcHeight;
+ size_t dst_slice_pitch = dstPitchInbytes * p->dstHeight;
+
+ if (!srcRect.create(srcOrigin, region, srcPitchInBytes, src_slice_pitch) ||
+ !dstRect.create(dstOrigin, region, dstPitchInbytes, dst_slice_pitch)) {
+ return hipErrorInvalidValue;
+ }
+
+ amd::Coord3D srcStart(srcRect.start_, 0, 0);
+ amd::Coord3D dstStart(dstRect.start_, 0, 0);
+ amd::Coord3D srcEnd(srcRect.end_, 1, 1);
+ amd::Coord3D dstEnd(dstRect.end_, 1, 1);
+
+ if (!src->asBuffer()->validateRegion(srcStart, srcEnd) ||
+ !dst->asBuffer()->validateRegion(dstStart, dstEnd)) {
+ return hipErrorInvalidValue;
+ }
+
+ // Check if regions overlap each other
+ if ((src->asBuffer() == dst->asBuffer()) &&
+ (std::abs(static_cast(srcOrigin[0]) - static_cast(dstOrigin[0])) <
+ static_cast(region[0])) &&
+ (std::abs(static_cast(srcOrigin[1]) - static_cast(dstOrigin[1])) <
+ static_cast(region[1])) &&
+ (std::abs(static_cast(srcOrigin[2]) - static_cast(dstOrigin[2])) <
+ static_cast(region[2]))) {
+ return hipErrorUnknown;
+ }
+
+ amd::Command::EventWaitList waitList;
+ amd::Coord3D size(region[0], region[1], region[2]);
+
+ amd::CopyMemoryCommand* command =
+ new amd::CopyMemoryCommand(*queue, CL_COMMAND_COPY_BUFFER_RECT, waitList, *src->asBuffer(),
+ *dst->asBuffer(), srcStart, dstStart, size, srcRect, dstRect);
+
+ if (!command) {
+ return hipErrorOutOfMemory;
+ }
+
+ command->enqueue();
+ command->awaitCompletion();
+ command->release();
+
+ queue->release();
+
+ return hipSuccess;
}
hipError_t hipMemset2D(void* dst, size_t pitch, int value, size_t width, size_t height) {
HIP_INIT_API(dst, pitch, value, width, height);
- assert(0 && "Unimplemented");
+ amd::Device* device = g_context->devices()[0];
- return hipErrorUnknown;
+ amd::HostQueue* queue = new amd::HostQueue(*g_context, *device, 0,
+ amd::CommandQueue::RealTimeDisabled,
+ amd::CommandQueue::Priority::Normal);
+ if (!queue) {
+ return hipErrorOutOfMemory;
+ }
+
+ amd::Command::EventWaitList waitList;
+ amd::Memory* memory = amd::SvmManager::FindSvmBuffer(dst);
+
+ amd::Coord3D fillOffset(0, 0, 0);
+
+ size_t sizeBytes = pitch * height;
+ amd::Coord3D fillSize(sizeBytes, 1, 1);
+ amd::FillMemoryCommand* command =
+ new amd::FillMemoryCommand(*queue, CL_COMMAND_FILL_BUFFER, waitList, *memory->asBuffer(),
+ &value, sizeof(int), fillOffset, fillSize);
+
+ if (!command) {
+ return hipErrorOutOfMemory;
+ }
+
+ command->enqueue();
+ command->awaitCompletion();
+ command->release();
+
+ queue->release();
+
+ return hipSuccess;
}
hipError_t hipMemsetD8(hipDeviceptr_t dst, unsigned char value, size_t sizeBytes) {
HIP_INIT_API(dst, value, sizeBytes);
- assert(0 && "Unimplemented");
+ amd::Device* device = g_context->devices()[0];
- return hipErrorUnknown;
+ amd::HostQueue* queue = new amd::HostQueue(*g_context, *device, 0,
+ amd::CommandQueue::RealTimeDisabled,
+ amd::CommandQueue::Priority::Normal);
+ if (!queue) {
+ return hipErrorOutOfMemory;
+ }
+
+ amd::Command::EventWaitList waitList;
+ amd::Memory* memory = amd::SvmManager::FindSvmBuffer(dst);
+
+ amd::Coord3D fillOffset(0, 0, 0);
+ amd::Coord3D fillSize(sizeBytes, 1, 1);
+ amd::FillMemoryCommand* command =
+ new amd::FillMemoryCommand(*queue, CL_COMMAND_FILL_BUFFER, waitList, *memory->asBuffer(),
+ &value, sizeof(char), fillOffset, fillSize);
+
+ if (!command) {
+ return hipErrorOutOfMemory;
+ }
+
+ command->enqueue();
+ command->awaitCompletion();
+ command->release();
+
+ queue->release();
+
+ return hipSuccess;
}
hipError_t hipIpcGetMemHandle(hipIpcMemHandle_t* handle, void* devPtr) {
From 213f7213187d43fffe2f9061ab762bade3257d0a Mon Sep 17 00:00:00 2001
From: foreman
Date: Mon, 30 Apr 2018 20:17:46 -0400
Subject: [PATCH 034/282] P4 to Git Change 1548038 by
lmoriche@lmoriche_opencl_dev2 on 2018/04/30 15:55:18
SWDEV-145570 - [HIP] Fix kernel disptach for HCC compiled programs.
Affected files ...
... //depot/stg/opencl/drivers/opencl/api/hip/hip_module.cpp#6 edit
---
api/hip/hip_module.cpp | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/api/hip/hip_module.cpp b/api/hip/hip_module.cpp
index 268b92284b..f17d5ae719 100644
--- a/api/hip/hip_module.cpp
+++ b/api/hip/hip_module.cpp
@@ -156,12 +156,22 @@ hipError_t hipModuleLaunchKernel(hipFunction_t f,
amd::NDRangeContainer ndrange(3, globalWorkOffset, globalWorkSize, localWorkSize);
amd::Command::EventWaitList waitList;
+ // 'extra' is a struct that contains the following info: {
+ // HIP_LAUNCH_PARAM_BUFFER_POINTER, kernargs,
+ // HIP_LAUNCH_PARAM_BUFFER_SIZE, &kernargs_size,
+ // HIP_LAUNCH_PARAM_END }
+ if (extra[0] != HIP_LAUNCH_PARAM_BUFFER_POINTER ||
+ extra[2] != HIP_LAUNCH_PARAM_BUFFER_SIZE || extra[4] != HIP_LAUNCH_PARAM_END) {
+ return hipErrorNotInitialized;
+ }
+ address kernargs = reinterpret_cast(extra[1]);
+
const amd::KernelSignature& signature = kernel->signature();
for (size_t i = 0; i < signature.numParameters(); ++i) {
const amd::KernelParameterDescriptor& desc = signature.at(i);
if (kernelParams == nullptr) {
assert(extra);
- kernel->parameters().set(i, desc.size_, reinterpret_cast(extra[1]) + desc.offset_,
+ kernel->parameters().set(i, desc.size_, kernargs + desc.offset_,
desc.type_ == T_POINTER/*svmBound*/);
} else {
assert(!extra);
From dc1497535d71f8a849a0fc9abfda710b0198f16a Mon Sep 17 00:00:00 2001
From: foreman
Date: Mon, 30 Apr 2018 21:20:26 -0400
Subject: [PATCH 035/282] P4 to Git Change 1548145 by
cpaquot@cpaquot-ocl-lc-lnx on 2018/04/30 21:15:56
SWDEV-145570 - [HIP] Handle hStream=nullptr case
Affected files ...
... //depot/stg/opencl/drivers/opencl/api/hip/hip_module.cpp#7 edit
---
api/hip/hip_module.cpp | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/api/hip/hip_module.cpp b/api/hip/hip_module.cpp
index f17d5ae719..97723d52dc 100644
--- a/api/hip/hip_module.cpp
+++ b/api/hip/hip_module.cpp
@@ -144,8 +144,14 @@ hipError_t hipModuleLaunchKernel(hipFunction_t f,
amd::Kernel* kernel = as_amd(reinterpret_cast(f));
amd::Device* device = g_context->devices()[0];
- amd::HostQueue* queue = as_amd(reinterpret_cast(hStream))->asHostQueue();
-
+ amd::HostQueue* queue;
+ if (hStream == nullptr) {
+ queue = new amd::HostQueue(*g_context, *device, 0,
+ amd::CommandQueue::RealTimeDisabled,
+ amd::CommandQueue::Priority::Normal);
+ } else {
+ queue = as_amd(reinterpret_cast(hStream))->asHostQueue();
+ }
if (!queue) {
return hipErrorOutOfMemory;
}
@@ -194,6 +200,10 @@ hipError_t hipModuleLaunchKernel(hipFunction_t f,
command->awaitCompletion();
command->release();
+ if (hStream == nullptr) {
+ queue->release();
+ }
+
return hipSuccess;
}
From 61378a359c8dcec55b853b56574cf24508357abf Mon Sep 17 00:00:00 2001
From: foreman
Date: Tue, 1 May 2018 18:10:09 -0400
Subject: [PATCH 036/282] P4 to Git Change 1548476 by
cpaquot@cpaquot-ocl-lc-lnx on 2018/05/01 15:50:51
SWDEV-145570 - [HIP]
Added support for null stream avoiding creating/destroying dummy streams.
Added basic event class for hipEvent* support.
Refactored some common functionality: No more direct access to g_context.
Support hipStreamSynchronize(0).
Affected files ...
... //depot/stg/opencl/drivers/opencl/api/hip/hip_context.cpp#9 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_device_runtime.cpp#7 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_event.cpp#3 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_event.hpp#1 add
... //depot/stg/opencl/drivers/opencl/api/hip/hip_internal.hpp#8 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_memory.cpp#15 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_module.cpp#8 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_platform.cpp#9 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_stream.cpp#4 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_texture.cpp#7 edit
---
api/hip/hip_context.cpp | 50 +++++++++++++----
api/hip/hip_device_runtime.cpp | 4 +-
api/hip/hip_event.cpp | 26 ++++++---
api/hip/hip_event.hpp | 40 ++++++++++++++
api/hip/hip_internal.hpp | 13 +++--
api/hip/hip_memory.cpp | 98 +++++++++-------------------------
api/hip/hip_module.cpp | 16 ++----
api/hip/hip_platform.cpp | 10 ++--
api/hip/hip_stream.cpp | 17 ++++--
api/hip/hip_texture.cpp | 29 +++++-----
10 files changed, 177 insertions(+), 126 deletions(-)
create mode 100644 api/hip/hip_event.hpp
diff --git a/api/hip/hip_context.cpp b/api/hip/hip_context.cpp
index e25a87bde8..46e4c864ff 100644
--- a/api/hip/hip_context.cpp
+++ b/api/hip/hip_context.cpp
@@ -27,13 +27,17 @@ THE SOFTWARE.
#include
#include
-thread_local amd::Context* g_context = nullptr;
-thread_local std::stack g_ctxtStack;
-
std::vector g_devices;
std::once_flag g_ihipInitialized;
-void ihipInit() {
+namespace hip {
+
+thread_local amd::Context* g_context = nullptr;
+thread_local std::stack g_ctxtStack;
+
+std::map g_nullStreams;
+
+void init() {
if (!amd::Runtime::initialized()) {
amd::Runtime::init();
}
@@ -54,6 +58,32 @@ void ihipInit() {
}
}
+amd::Context* getCurrentContext() {
+ return g_context;
+}
+
+void setCurrentContext(unsigned int index) {
+ assert(indexdevices()[0];
+ amd::HostQueue* queue = new amd::HostQueue(*hip::getCurrentContext(), *device, 0,
+ amd::CommandQueue::RealTimeDisabled,
+ amd::CommandQueue::Priority::Normal);
+ g_nullStreams[getCurrentContext()] = queue;
+ return queue;
+ }
+ return stream->second;
+}
+
+};
+
+using namespace hip;
+
hipError_t hipInit(unsigned int flags) {
HIP_INIT_API(flags);
@@ -84,11 +114,11 @@ hipError_t hipCtxSetCurrent(hipCtx_t ctx) {
g_ctxtStack.pop();
}
} else {
- g_context = reinterpret_cast(as_amd(ctx));
+ hip::g_context = reinterpret_cast(as_amd(ctx));
if(!g_ctxtStack.empty()) {
g_ctxtStack.pop();
}
- g_ctxtStack.push(g_context);
+ g_ctxtStack.push(hip::getCurrentContext());
}
return hipSuccess;
@@ -97,7 +127,7 @@ hipError_t hipCtxSetCurrent(hipCtx_t ctx) {
hipError_t hipCtxGetCurrent(hipCtx_t* ctx) {
HIP_INIT_API(ctx);
- *ctx = reinterpret_cast(g_context);
+ *ctx = reinterpret_cast(hip::getCurrentContext());
return hipSuccess;
}
@@ -164,8 +194,8 @@ hipError_t hipCtxPushCurrent(hipCtx_t ctx) {
return hipErrorInvalidContext;
}
- g_context = amdContext;
- g_ctxtStack.push(g_context);
+ hip::g_context = amdContext;
+ g_ctxtStack.push(hip::getCurrentContext());
return hipSuccess;
}
@@ -191,7 +221,7 @@ hipError_t hipCtxGetDevice(hipDevice_t* device) {
if (device != nullptr) {
for (unsigned int i = 0; i < g_devices.size(); i++) {
- if (g_devices[i] == g_context) {
+ if (g_devices[i] == hip::getCurrentContext()) {
*device = static_cast(i);
return hipSuccess;
}
diff --git a/api/hip/hip_device_runtime.cpp b/api/hip/hip_device_runtime.cpp
index effce5974f..77d90d2cb0 100644
--- a/api/hip/hip_device_runtime.cpp
+++ b/api/hip/hip_device_runtime.cpp
@@ -383,7 +383,7 @@ hipError_t hipGetDevice ( int* deviceId ) {
if (deviceId != nullptr) {
for (unsigned int i = 0; i < g_devices.size(); i++) {
- if (g_devices[i] == g_context) {
+ if (g_devices[i] == hip::getCurrentContext()) {
*deviceId = i;
return hipSuccess;
}
@@ -425,7 +425,7 @@ hipError_t hipSetDevice ( int device ) {
HIP_INIT_API(device);
if (static_cast(device) < g_devices.size()) {
- g_context = g_devices[device];
+ hip::setCurrentContext(device);
return hipSuccess;
}
diff --git a/api/hip/hip_event.cpp b/api/hip/hip_event.cpp
index 1fe7be9e2f..b9930636bb 100644
--- a/api/hip/hip_event.cpp
+++ b/api/hip/hip_event.cpp
@@ -22,30 +22,42 @@ THE SOFTWARE.
#include
-#include "hip_internal.hpp"
+#include "hip_event.hpp"
hipError_t hipEventCreateWithFlags(hipEvent_t* event, unsigned flags) {
HIP_INIT_API(event, flags);
- assert(0 && "Unimplemented");
+ hip::Event* e = new hip::Event(flags);
- return hipErrorUnknown;
+ if (e == nullptr) {
+ return hipErrorOutOfMemory;
+ }
+
+ *event = reinterpret_cast(e);
+
+ return hipSuccess;
}
hipError_t hipEventCreate(hipEvent_t* event) {
HIP_INIT_API(event);
- assert(0 && "Unimplemented");
+ hip::Event* e = new hip::Event(0);
- return hipErrorUnknown;
+ if (e == nullptr) {
+ return hipErrorOutOfMemory;
+ }
+
+ *event = reinterpret_cast(e);
+
+ return hipSuccess;
}
hipError_t hipEventDestroy(hipEvent_t event) {
HIP_INIT_API(event);
- assert(0 && "Unimplemented");
+ delete reinterpret_cast(event);
- return hipErrorUnknown;
+ return hipSuccess;
}
hipError_t hipEventElapsedTime(float *ms, hipEvent_t start, hipEvent_t stop) {
diff --git a/api/hip/hip_event.hpp b/api/hip/hip_event.hpp
new file mode 100644
index 0000000000..3ac1ea8bfe
--- /dev/null
+++ b/api/hip/hip_event.hpp
@@ -0,0 +1,40 @@
+/*
+Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#ifndef HIP_EVENT_H
+#define HIP_EVENT_H
+
+#include "hip_internal.hpp"
+
+namespace hip {
+
+class Event {
+public:
+ Event(unsigned int flags) : flags(flags) {}
+ ~Event() {}
+ unsigned int flags;
+private:
+};
+
+};
+
+#endif // HIP_EVEMT_H
diff --git a/api/hip/hip_internal.hpp b/api/hip/hip_internal.hpp
index 2512e35c98..489b8b620f 100644
--- a/api/hip/hip_internal.hpp
+++ b/api/hip/hip_internal.hpp
@@ -28,7 +28,7 @@ THE SOFTWARE.
#include
#define HIP_INIT() \
- std::call_once(g_ihipInitialized, ihipInit);
+ std::call_once(g_ihipInitialized, hip::init);
// This macro should be called at the beginning of every HIP API.
@@ -46,10 +46,17 @@ class accelerator_view;
};
extern std::once_flag g_ihipInitialized;
-extern thread_local amd::Context* g_context;
+
+namespace hip {
+ extern void init();
+
+ extern amd::Context* getCurrentContext();
+ extern void setCurrentContext(unsigned int index);
+
+ extern amd::HostQueue* getNullStream();
+};
extern std::vector g_devices;
extern hipError_t ihipDeviceGetCount(int* count);
-extern void ihipInit();
#endif // HIP_SRC_HIP_INTERNAL_H
diff --git a/api/hip/hip_memory.cpp b/api/hip/hip_memory.cpp
index 830865fb93..3a4af23dee 100644
--- a/api/hip/hip_memory.cpp
+++ b/api/hip/hip_memory.cpp
@@ -39,11 +39,11 @@ hipError_t ihipMalloc(void** ptr, size_t sizeBytes, unsigned int flags)
return hipErrorInvalidValue;
}
- if (g_context->devices()[0]->info().maxMemAllocSize_ < sizeBytes) {
+ if (hip::getCurrentContext()->devices()[0]->info().maxMemAllocSize_ < sizeBytes) {
return hipErrorOutOfMemory;
}
- *ptr = amd::SvmBuffer::malloc(*g_context, flags, sizeBytes, g_context->devices()[0]->info().memBaseAddrAlign_);
+ *ptr = amd::SvmBuffer::malloc(*hip::getCurrentContext(), flags, sizeBytes, hip::getCurrentContext()->devices()[0]->info().memBaseAddrAlign_);
if (!*ptr) {
return hipErrorOutOfMemory;
}
@@ -65,7 +65,7 @@ hipError_t hipHostMalloc(void** ptr, size_t sizeBytes, unsigned int flags) {
hipError_t hipFree(void* ptr) {
if (amd::SvmBuffer::malloced(ptr)) {
- amd::SvmBuffer::free(*g_context, ptr);
+ amd::SvmBuffer::free(*hip::getCurrentContext(), ptr);
return hipSuccess;
}
return hipErrorInvalidValue;
@@ -74,11 +74,8 @@ hipError_t hipFree(void* ptr) {
hipError_t hipMemcpy(void* dst, const void* src, size_t sizeBytes, hipMemcpyKind kind) {
HIP_INIT_API(dst, src, sizeBytes, kind);
- amd::Device* device = g_context->devices()[0];
+ amd::HostQueue* queue = hip::getNullStream();
- amd::HostQueue* queue = new amd::HostQueue(*g_context, *device, 0,
- amd::CommandQueue::RealTimeDisabled,
- amd::CommandQueue::Priority::Normal);
if (!queue) {
return hipErrorOutOfMemory;
}
@@ -119,8 +116,6 @@ hipError_t hipMemcpy(void* dst, const void* src, size_t sizeBytes, hipMemcpyKind
command->awaitCompletion();
command->release();
- queue->release();
-
return hipSuccess;
}
@@ -135,11 +130,8 @@ hipError_t hipMemsetAsync(void* dst, int value, size_t sizeBytes, hipStream_t st
hipError_t hipMemset(void* dst, int value, size_t sizeBytes) {
HIP_INIT_API(dst, value, sizeBytes);
- amd::Device* device = g_context->devices()[0];
+ amd::HostQueue* queue = hip::getNullStream();
- amd::HostQueue* queue = new amd::HostQueue(*g_context, *device, 0,
- amd::CommandQueue::RealTimeDisabled,
- amd::CommandQueue::Priority::Normal);
if (!queue) {
return hipErrorOutOfMemory;
}
@@ -162,8 +154,6 @@ hipError_t hipMemset(void* dst, int value, size_t sizeBytes) {
command->awaitCompletion();
command->release();
- queue->release();
-
return hipSuccess;
}
@@ -185,7 +175,7 @@ hipError_t hipHostFree(void* ptr) {
HIP_INIT_API(ptr);
if (amd::SvmBuffer::malloced(ptr)) {
- amd::SvmBuffer::free(*g_context, ptr);
+ amd::SvmBuffer::free(*hip::getCurrentContext(), ptr);
return hipSuccess;
}
return hipErrorInvalidValue;
@@ -195,7 +185,7 @@ hipError_t hipFreeArray(hipArray* array) {
HIP_INIT_API(array);
if (amd::SvmBuffer::malloced(array->data)) {
- amd::SvmBuffer::free(*g_context, array->data);
+ amd::SvmBuffer::free(*hip::getCurrentContext(), array->data);
return hipSuccess;
}
return hipErrorInvalidValue;
@@ -222,7 +212,7 @@ hipError_t hipMemGetInfo(size_t* free, size_t* total) {
HIP_INIT_API(free, total);
size_t freeMemory[2];
- amd::Device* device = g_context->devices()[0];
+ amd::Device* device = hip::getCurrentContext()->devices()[0];
if(!device) {
return hipErrorInvalidDevice;
}
@@ -240,7 +230,7 @@ return hipSuccess;
hipError_t ihipMallocPitch(void** ptr, size_t* pitch, size_t width, size_t height, size_t depth,
cl_mem_object_type imageType, const cl_image_format* image_format) {
- amd::Device* device = g_context->devices()[0];
+ amd::Device* device = hip::getCurrentContext()->devices()[0];
if ((width == 0) || (height == 0)) {
*ptr = nullptr;
@@ -251,7 +241,7 @@ hipError_t ihipMallocPitch(void** ptr, size_t* pitch, size_t width, size_t heigh
return hipErrorInvalidValue;
}
- if (g_context->devices()[0]->info().maxMemAllocSize_ < (width * height)) {
+ if (device->info().maxMemAllocSize_ < (width * height)) {
return hipErrorOutOfMemory;
}
@@ -260,8 +250,8 @@ hipError_t ihipMallocPitch(void** ptr, size_t* pitch, size_t width, size_t heigh
*pitch = width * imageFormat.getElementSize();
size_t sizeBytes = *pitch * height * depth;
- *ptr = amd::SvmBuffer::malloc(*g_context, CL_MEM_SVM_FINE_GRAIN_BUFFER, sizeBytes,
- g_context->devices()[0]->info().memBaseAddrAlign_);
+ *ptr = amd::SvmBuffer::malloc(*hip::getCurrentContext(), CL_MEM_SVM_FINE_GRAIN_BUFFER, sizeBytes,
+ device->info().memBaseAddrAlign_);
if (!*ptr) {
return hipErrorMemoryAllocation;
@@ -559,11 +549,7 @@ hipError_t hipMemcpyToArray(hipArray* dstArray, size_t wOffset, size_t hOffset,
size_t count, hipMemcpyKind kind) {
HIP_INIT_API(dstArray, wOffset, hOffset, src, count, kind);
- amd::Device* device = g_context->devices()[0];
-
- amd::HostQueue* queue = new amd::HostQueue(*g_context, *device, 0,
- amd::CommandQueue::RealTimeDisabled,
- amd::CommandQueue::Priority::Normal);
+ amd::HostQueue* queue = hip::getNullStream();
if (!queue) {
return hipErrorOutOfMemory;
}
@@ -597,8 +583,6 @@ hipError_t hipMemcpyToArray(hipArray* dstArray, size_t wOffset, size_t hOffset,
command->awaitCompletion();
command->release();
- queue->release();
-
return hipSuccess;
}
@@ -606,11 +590,7 @@ hipError_t hipMemcpyFromArray(void* dst, hipArray_const_t srcArray, size_t wOffs
size_t count, hipMemcpyKind kind) {
HIP_INIT_API(dst, srcArray, wOffset, hOffset, count, kind);
- amd::Device* device = g_context->devices()[0];
-
- amd::HostQueue* queue = new amd::HostQueue(*g_context, *device, 0,
- amd::CommandQueue::RealTimeDisabled,
- amd::CommandQueue::Priority::Normal);
+ amd::HostQueue* queue = hip::getNullStream();
if (!queue) {
return hipErrorOutOfMemory;
}
@@ -644,19 +624,13 @@ hipError_t hipMemcpyFromArray(void* dst, hipArray_const_t srcArray, size_t wOffs
command->awaitCompletion();
command->release();
- queue->release();
-
return hipSuccess;
}
hipError_t hipMemcpyHtoA(hipArray* dstArray, size_t dstOffset, const void* srcHost, size_t count) {
HIP_INIT_API(dstArray, dstOffset, srcHost, count);
- amd::Device* device = g_context->devices()[0];
-
- amd::HostQueue* queue = new amd::HostQueue(*g_context, *device, 0,
- amd::CommandQueue::RealTimeDisabled,
- amd::CommandQueue::Priority::Normal);
+ amd::HostQueue* queue = hip::getNullStream();
if (!queue) {
return hipErrorOutOfMemory;
}
@@ -674,19 +648,13 @@ hipError_t hipMemcpyHtoA(hipArray* dstArray, size_t dstOffset, const void* srcHo
command->awaitCompletion();
command->release();
- queue->release();
-
return hipSuccess;
}
hipError_t hipMemcpyAtoH(void* dst, hipArray* srcArray, size_t srcOffset, size_t count) {
HIP_INIT_API(dst, srcArray, srcOffset, count);
- amd::Device* device = g_context->devices()[0];
-
- amd::HostQueue* queue = new amd::HostQueue(*g_context, *device, 0,
- amd::CommandQueue::RealTimeDisabled,
- amd::CommandQueue::Priority::Normal);
+ amd::HostQueue* queue = hip::getNullStream();
if (!queue) {
return hipErrorOutOfMemory;
}
@@ -704,19 +672,13 @@ hipError_t hipMemcpyAtoH(void* dst, hipArray* srcArray, size_t srcOffset, size_t
command->awaitCompletion();
command->release();
- queue->release();
-
return hipSuccess;
}
hipError_t hipMemcpy3D(const struct hipMemcpy3DParms* p) {
HIP_INIT_API(p);
- amd::Device* device = g_context->devices()[0];
-
- amd::HostQueue* queue = new amd::HostQueue(*g_context, *device, 0,
- amd::CommandQueue::RealTimeDisabled,
- amd::CommandQueue::Priority::Normal);
+ amd::HostQueue* queue = hip::getNullStream();
if (!queue) {
return hipErrorOutOfMemory;
}
@@ -826,19 +788,13 @@ hipError_t hipMemcpy3D(const struct hipMemcpy3DParms* p) {
command->awaitCompletion();
command->release();
- queue->release();
-
return hipSuccess;
}
hipError_t hipMemset2D(void* dst, size_t pitch, int value, size_t width, size_t height) {
HIP_INIT_API(dst, pitch, value, width, height);
- amd::Device* device = g_context->devices()[0];
-
- amd::HostQueue* queue = new amd::HostQueue(*g_context, *device, 0,
- amd::CommandQueue::RealTimeDisabled,
- amd::CommandQueue::Priority::Normal);
+ amd::HostQueue* queue = hip::getNullStream();
if (!queue) {
return hipErrorOutOfMemory;
}
@@ -862,19 +818,13 @@ hipError_t hipMemset2D(void* dst, size_t pitch, int value, size_t width, size_t
command->awaitCompletion();
command->release();
- queue->release();
-
return hipSuccess;
}
hipError_t hipMemsetD8(hipDeviceptr_t dst, unsigned char value, size_t sizeBytes) {
HIP_INIT_API(dst, value, sizeBytes);
- amd::Device* device = g_context->devices()[0];
-
- amd::HostQueue* queue = new amd::HostQueue(*g_context, *device, 0,
- amd::CommandQueue::RealTimeDisabled,
- amd::CommandQueue::Priority::Normal);
+ amd::HostQueue* queue = hip::getNullStream();
if (!queue) {
return hipErrorOutOfMemory;
}
@@ -896,8 +846,6 @@ hipError_t hipMemsetD8(hipDeviceptr_t dst, unsigned char value, size_t sizeBytes
command->awaitCompletion();
command->release();
- queue->release();
-
return hipSuccess;
}
@@ -938,9 +886,13 @@ hipChannelFormatDesc hipCreateChannelDesc(int x, int y, int z, int w, hipChannel
hipError_t hipHostGetDevicePointer(void** devicePointer, void* hostPointer, unsigned flags) {
HIP_INIT_API(devicePointer, hostPointer, flags);
- assert(0 && "Unimplemented");
+ if (!amd::SvmBuffer::malloced(hostPointer)) {
+ return hipErrorInvalidValue;
+ }
+ // right now we have SVM
+ *devicePointer = hostPointer;
- return hipErrorUnknown;
+ return hipSuccess;
}
hipError_t hipPointerGetAttributes(hipPointerAttribute_t* attributes, const void* ptr) {
diff --git a/api/hip/hip_module.cpp b/api/hip/hip_module.cpp
index 97723d52dc..0a5675114c 100644
--- a/api/hip/hip_module.cpp
+++ b/api/hip/hip_module.cpp
@@ -94,13 +94,13 @@ hipError_t hipModuleLoadData(hipModule_t *module, const void *image)
hipError_t ihipModuleLoadData(hipModule_t *module, const void *image)
{
- amd::Program* program = new amd::Program(*g_context);
+ amd::Program* program = new amd::Program(*hip::getCurrentContext());
if (program == NULL) {
return hipErrorOutOfMemory;
}
- if (CL_SUCCESS != program->addDeviceProgram(*g_context->devices()[0], image, ElfSize(image)) ||
- CL_SUCCESS != program->build(g_context->devices(), nullptr, nullptr, nullptr)) {
+ if (CL_SUCCESS != program->addDeviceProgram(*hip::getCurrentContext()->devices()[0], image, ElfSize(image)) ||
+ CL_SUCCESS != program->build(hip::getCurrentContext()->devices(), nullptr, nullptr, nullptr)) {
return hipErrorUnknown;
}
@@ -142,13 +142,11 @@ hipError_t hipModuleLaunchKernel(hipFunction_t f,
kernelParams, extra);
amd::Kernel* kernel = as_amd(reinterpret_cast