2020-02-04 08:45:01 -08:00
|
|
|
/* Copyright (c) 2018-present Advanced Micro Devices, Inc.
|
|
|
|
|
|
|
|
|
|
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. */
|
2018-02-27 18:38:56 -05:00
|
|
|
|
|
|
|
|
#include <hip/hip_runtime.h>
|
|
|
|
|
|
|
|
|
|
#include "hip_internal.hpp"
|
|
|
|
|
|
2020-04-09 12:44:21 -07:00
|
|
|
namespace hip {
|
|
|
|
|
|
2020-05-01 09:22:31 -04:00
|
|
|
// ================================================================================================
|
|
|
|
|
amd::HostQueue* Device::NullStream(bool skip_alloc) {
|
|
|
|
|
amd::HostQueue* null_queue = null_stream_.asHostQueue(skip_alloc);
|
2020-04-23 16:54:48 -04:00
|
|
|
if (null_queue == nullptr) {
|
|
|
|
|
return nullptr;
|
2020-04-09 12:44:21 -07:00
|
|
|
}
|
2020-04-17 10:42:46 -04:00
|
|
|
// Wait for all active streams before executing commands on the default
|
2020-04-23 16:54:48 -04:00
|
|
|
iHipWaitActiveStreams(null_queue);
|
|
|
|
|
return null_queue;
|
2020-04-09 12:44:21 -07:00
|
|
|
}
|
|
|
|
|
|
2020-05-01 09:22:31 -04:00
|
|
|
}
|
2020-04-09 12:44:21 -07:00
|
|
|
|
2018-04-05 15:02:43 -04:00
|
|
|
hipError_t hipDeviceGet(hipDevice_t *device, int deviceId) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipDeviceGet, device, deviceId);
|
2018-02-27 18:38:56 -05:00
|
|
|
|
2021-02-05 05:40:41 -05:00
|
|
|
if (deviceId < 0 ||
|
|
|
|
|
static_cast<size_t>(deviceId) >= g_devices.size() ||
|
|
|
|
|
device == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidDevice);
|
2018-02-27 18:38:56 -05:00
|
|
|
}
|
2021-02-05 05:40:41 -05:00
|
|
|
*device = deviceId;
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipSuccess);
|
2018-02-27 18:38:56 -05:00
|
|
|
};
|
|
|
|
|
|
2018-03-03 21:02:59 -05:00
|
|
|
hipError_t hipDeviceTotalMem (size_t *bytes, hipDevice_t device) {
|
2018-02-27 18:38:56 -05:00
|
|
|
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipDeviceTotalMem, bytes, device);
|
2018-02-27 18:38:56 -05:00
|
|
|
|
2018-03-19 13:52:17 -04:00
|
|
|
if (device < 0 || static_cast<size_t>(device) >= g_devices.size()) {
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipErrorInvalidDevice);
|
2018-03-03 21:02:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (bytes == nullptr) {
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
2018-03-03 21:02:59 -05:00
|
|
|
}
|
|
|
|
|
|
2018-03-19 13:52:17 -04:00
|
|
|
auto* deviceHandle = g_devices[device]->devices()[0];
|
2018-03-03 21:02:59 -05:00
|
|
|
const auto& info = deviceHandle->info();
|
|
|
|
|
|
|
|
|
|
*bytes = info.globalMemSize_;
|
2018-02-27 18:38:56 -05:00
|
|
|
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipSuccess);
|
2018-02-27 18:38:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipDeviceComputeCapability(int *major, int *minor, hipDevice_t device) {
|
|
|
|
|
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipDeviceComputeCapability, major, minor, device);
|
2018-03-01 22:57:20 -05:00
|
|
|
|
2018-03-19 13:52:17 -04:00
|
|
|
if (device < 0 || static_cast<size_t>(device) >= g_devices.size()) {
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipErrorInvalidDevice);
|
2018-03-03 21:02:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (major == nullptr || minor == nullptr) {
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
2018-03-03 21:02:59 -05:00
|
|
|
}
|
|
|
|
|
|
2018-03-19 13:52:17 -04:00
|
|
|
auto* deviceHandle = g_devices[device]->devices()[0];
|
2021-01-19 03:36:22 +00:00
|
|
|
const auto& isa = deviceHandle->isa();
|
|
|
|
|
*major = isa.versionMajor();
|
|
|
|
|
*minor = isa.versionMinor();
|
2018-02-27 18:38:56 -05:00
|
|
|
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipSuccess);
|
2018-02-27 18:38:56 -05:00
|
|
|
}
|
|
|
|
|
|
2018-03-14 19:05:10 -04:00
|
|
|
hipError_t hipDeviceGetCount(int* count) {
|
2020-05-14 03:50:34 -05:00
|
|
|
HIP_INIT_API(hipDeviceGetCount, count);
|
2018-03-14 19:05:10 -04:00
|
|
|
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(ihipDeviceGetCount(count));
|
2018-03-23 00:19:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t ihipDeviceGetCount(int* count) {
|
2018-03-14 19:05:10 -04:00
|
|
|
if (count == nullptr) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get all available devices
|
2018-08-20 18:48:00 -04:00
|
|
|
*count = g_devices.size();
|
2018-03-14 19:05:10 -04:00
|
|
|
|
2019-08-07 11:44:31 -04:00
|
|
|
if (*count < 1) {
|
|
|
|
|
return hipErrorNoDevice;
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-14 19:05:10 -04:00
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-03 21:02:59 -05:00
|
|
|
hipError_t hipDeviceGetName(char *name, int len, hipDevice_t device) {
|
2018-02-27 18:38:56 -05:00
|
|
|
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipDeviceGetName, (void*)name, len, device);
|
2018-02-27 18:38:56 -05:00
|
|
|
|
2018-03-19 13:52:17 -04:00
|
|
|
if (device < 0 || static_cast<size_t>(device) >= g_devices.size()) {
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipErrorInvalidDevice);
|
2018-03-03 21:02:59 -05:00
|
|
|
}
|
|
|
|
|
|
2019-04-19 09:49:37 -04:00
|
|
|
if (name == nullptr || len <= 0) {
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
2018-03-03 21:02:59 -05:00
|
|
|
}
|
|
|
|
|
|
2018-03-19 13:52:17 -04:00
|
|
|
auto* deviceHandle = g_devices[device]->devices()[0];
|
2018-03-03 21:02:59 -05:00
|
|
|
const auto& info = deviceHandle->info();
|
2019-04-19 09:49:37 -04:00
|
|
|
const auto nameLen = ::strlen(info.boardName_);
|
2018-03-03 21:02:59 -05:00
|
|
|
|
2019-04-21 21:50:04 -04:00
|
|
|
// Make sure that the size of `dest` is big enough to hold `src` including
|
|
|
|
|
// trailing zero byte
|
|
|
|
|
if (nameLen > (cl_uint)(len - 1)) {
|
2019-04-19 09:49:37 -04:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-21 21:50:04 -04:00
|
|
|
::strncpy(name, info.boardName_, (nameLen + 1));
|
2018-02-27 18:38:56 -05:00
|
|
|
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipSuccess);
|
2018-02-27 18:38:56 -05:00
|
|
|
}
|
2018-03-14 19:05:10 -04:00
|
|
|
|
|
|
|
|
hipError_t hipGetDeviceProperties ( hipDeviceProp_t* props, hipDevice_t device ) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipGetDeviceProperties, props, device);
|
2018-03-14 19:05:10 -04:00
|
|
|
|
|
|
|
|
if (props == nullptr) {
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
2018-03-14 19:05:10 -04:00
|
|
|
}
|
|
|
|
|
|
2018-03-19 13:52:17 -04:00
|
|
|
if (unsigned(device) >= g_devices.size()) {
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipErrorInvalidDevice);
|
2018-03-14 19:05:10 -04:00
|
|
|
}
|
2018-03-19 13:52:17 -04:00
|
|
|
auto* deviceHandle = g_devices[device]->devices()[0];
|
2018-03-14 19:05:10 -04:00
|
|
|
|
|
|
|
|
hipDeviceProp_t deviceProps = {0};
|
|
|
|
|
|
|
|
|
|
const auto& info = deviceHandle->info();
|
2021-01-18 16:27:24 +00:00
|
|
|
const auto& isa = deviceHandle->isa();
|
2018-03-14 19:05:10 -04:00
|
|
|
::strncpy(deviceProps.name, info.boardName_, 128);
|
|
|
|
|
deviceProps.totalGlobalMem = info.globalMemSize_;
|
|
|
|
|
deviceProps.sharedMemPerBlock = info.localMemSizePerCU_;
|
2020-10-05 13:20:58 -04:00
|
|
|
deviceProps.regsPerBlock = info.availableRegistersPerCU_;
|
2018-03-14 19:05:10 -04:00
|
|
|
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];
|
2018-08-10 14:10:19 -04:00
|
|
|
deviceProps.maxGridSize[0] = INT32_MAX;
|
|
|
|
|
deviceProps.maxGridSize[1] = INT32_MAX;
|
|
|
|
|
deviceProps.maxGridSize[2] = INT32_MAX;
|
2018-08-10 14:04:43 -04:00
|
|
|
deviceProps.clockRate = info.maxEngineClockFrequency_ * 1000;
|
2018-08-10 14:09:04 -04:00
|
|
|
deviceProps.memoryClockRate = info.maxMemoryClockFrequency_ * 1000;
|
2020-08-06 08:46:07 -04:00
|
|
|
deviceProps.memoryBusWidth = info.globalMemChannels_;
|
2018-03-14 19:05:10 -04:00
|
|
|
deviceProps.totalConstMem = info.maxConstantBufferSize_;
|
2021-01-18 16:27:24 +00:00
|
|
|
deviceProps.major = isa.versionMajor();
|
|
|
|
|
deviceProps.minor = isa.versionMinor();
|
2018-03-14 19:05:10 -04:00
|
|
|
deviceProps.multiProcessorCount = info.maxComputeUnits_;
|
|
|
|
|
deviceProps.l2CacheSize = info.l2CacheSize_;
|
2019-01-29 17:33:39 -05:00
|
|
|
deviceProps.maxThreadsPerMultiProcessor = info.maxThreadsPerCU_;
|
2018-03-14 19:05:10 -04:00
|
|
|
deviceProps.computeMode = 0;
|
|
|
|
|
deviceProps.clockInstructionRate = info.timeStampFrequency_;
|
|
|
|
|
deviceProps.arch.hasGlobalInt32Atomics = 1;
|
|
|
|
|
deviceProps.arch.hasGlobalFloatAtomicExch = 1;
|
|
|
|
|
deviceProps.arch.hasSharedInt32Atomics = 1;
|
|
|
|
|
deviceProps.arch.hasSharedFloatAtomicExch = 1;
|
2020-05-11 16:41:35 -04:00
|
|
|
deviceProps.arch.hasFloatAtomicAdd = 1;
|
2018-03-14 19:05:10 -04:00
|
|
|
deviceProps.arch.hasGlobalInt64Atomics = 1;
|
|
|
|
|
deviceProps.arch.hasSharedInt64Atomics = 1;
|
|
|
|
|
deviceProps.arch.hasDoubles = 1;
|
2020-05-11 16:41:35 -04:00
|
|
|
deviceProps.arch.hasWarpVote = 1;
|
|
|
|
|
deviceProps.arch.hasWarpBallot = 1;
|
|
|
|
|
deviceProps.arch.hasWarpShuffle = 1;
|
2018-03-14 19:05:10 -04:00
|
|
|
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;
|
2020-10-14 18:57:04 +00:00
|
|
|
deviceProps.pciDomainID = info.pciDomainID;
|
2018-03-14 19:05:10 -04:00
|
|
|
deviceProps.pciBusID = info.deviceTopology_.pcie.bus;
|
|
|
|
|
deviceProps.pciDeviceID = info.deviceTopology_.pcie.device;
|
|
|
|
|
deviceProps.maxSharedMemoryPerMultiProcessor = info.localMemSizePerCU_;
|
|
|
|
|
deviceProps.canMapHostMemory = 1;
|
2020-12-06 07:41:35 -08:00
|
|
|
//FIXME: This should be removed, targets can have character names as well.
|
2021-01-18 16:27:24 +00:00
|
|
|
deviceProps.gcnArch = isa.versionMajor() * 100 + isa.versionMinor() * 10 + isa.versionStepping();
|
|
|
|
|
sprintf(deviceProps.gcnArchName, "%s", isa.targetId());
|
2019-06-12 10:00:38 -04:00
|
|
|
deviceProps.cooperativeLaunch = info.cooperativeGroups_;
|
|
|
|
|
deviceProps.cooperativeMultiDeviceLaunch = info.cooperativeMultiDeviceGroups_;
|
2018-03-14 19:05:10 -04:00
|
|
|
|
2020-04-06 13:54:03 -04:00
|
|
|
deviceProps.cooperativeMultiDeviceUnmatchedFunc = info.cooperativeMultiDeviceGroups_;
|
|
|
|
|
deviceProps.cooperativeMultiDeviceUnmatchedGridDim = info.cooperativeMultiDeviceGroups_;
|
|
|
|
|
deviceProps.cooperativeMultiDeviceUnmatchedBlockDim = info.cooperativeMultiDeviceGroups_;
|
|
|
|
|
deviceProps.cooperativeMultiDeviceUnmatchedSharedMem = info.cooperativeMultiDeviceGroups_;
|
|
|
|
|
|
2020-11-05 10:42:18 -05:00
|
|
|
deviceProps.maxTexture1DLinear = 16 * info.imageMaxBufferSize_; // Max pixel size is 16 bytes
|
2020-10-13 16:33:50 +00:00
|
|
|
deviceProps.maxTexture1D = info.image1DMaxWidth_;
|
2019-08-07 11:30:59 -04:00
|
|
|
deviceProps.maxTexture2D[0] = info.image2DMaxWidth_;
|
|
|
|
|
deviceProps.maxTexture2D[1] = info.image2DMaxHeight_;
|
|
|
|
|
deviceProps.maxTexture3D[0] = info.image3DMaxWidth_;
|
|
|
|
|
deviceProps.maxTexture3D[1] = info.image3DMaxHeight_;
|
|
|
|
|
deviceProps.maxTexture3D[2] = info.image3DMaxDepth_;
|
2021-02-04 19:58:43 +00:00
|
|
|
deviceProps.hdpMemFlushCntl = info.hdpMemFlushCntl;
|
|
|
|
|
deviceProps.hdpRegFlushCntl = info.hdpRegFlushCntl;
|
2019-08-07 11:30:59 -04:00
|
|
|
|
2019-09-16 17:58:06 -04:00
|
|
|
deviceProps.memPitch = info.maxMemAllocSize_;
|
2020-02-20 18:56:33 -05:00
|
|
|
deviceProps.textureAlignment = info.imageBaseAddressAlignment_;
|
|
|
|
|
deviceProps.texturePitchAlignment = info.imagePitchAlignment_;
|
2019-09-16 17:58:06 -04:00
|
|
|
deviceProps.kernelExecTimeoutEnabled = 0;
|
|
|
|
|
deviceProps.ECCEnabled = info.errorCorrectionSupport_? 1:0;
|
2020-04-30 22:19:15 -04:00
|
|
|
deviceProps.isLargeBar = info.largeBar_ ? 1 : 0;
|
2020-06-12 17:05:16 -04:00
|
|
|
deviceProps.asicRevision = info.asicRevision_;
|
2019-09-16 17:58:06 -04:00
|
|
|
|
2020-10-09 18:25:29 -04:00
|
|
|
// HMM capabilities
|
|
|
|
|
deviceProps.managedMemory = info.hmmSupported_;
|
|
|
|
|
deviceProps.concurrentManagedAccess = info.hmmSupported_;
|
|
|
|
|
deviceProps.directManagedMemAccessFromHost = info.hmmDirectHostAccess_;
|
|
|
|
|
deviceProps.pageableMemoryAccess = info.hmmCpuMemoryAccessible_;
|
|
|
|
|
deviceProps.pageableMemoryAccessUsesHostPageTables = info.hostUnifiedMemory_;
|
|
|
|
|
|
2018-03-14 19:05:10 -04:00
|
|
|
*props = deviceProps;
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipSuccess);
|
2018-03-14 19:05:10 -04:00
|
|
|
}
|