2016-03-24 07:04:01 -05:00
|
|
|
/*
|
2017-03-31 12:11:34 -05:00
|
|
|
Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved.
|
2016-10-15 22:55:22 +05:30
|
|
|
|
2016-03-24 07:04:01 -05:00
|
|
|
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:
|
2016-10-15 22:55:22 +05:30
|
|
|
|
2016-03-24 07:04:01 -05:00
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
|
all copies or substantial portions of the Software.
|
2016-10-15 22:55:22 +05:30
|
|
|
|
|
|
|
|
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
|
2016-03-24 07:04:01 -05:00
|
|
|
THE SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
2016-10-04 22:17:18 +05:30
|
|
|
#include "hip/hip_runtime.h"
|
2017-03-31 12:11:34 -05:00
|
|
|
#include "hip_hcc_internal.h"
|
2016-10-15 20:25:20 -05:00
|
|
|
#include "trace_helper.h"
|
2016-12-05 11:03:45 +05:30
|
|
|
#include "device_util.h"
|
2016-03-24 09:28:46 -05:00
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------------------
|
|
|
|
|
//Devices
|
|
|
|
|
//-------------------------------------------------------------------------------------------------
|
2016-08-09 15:37:19 -05:00
|
|
|
// TODO - does this initialize HIP runtime?
|
2016-08-08 17:49:02 -05:00
|
|
|
hipError_t hipGetDevice(int *deviceId)
|
2016-03-24 09:28:46 -05:00
|
|
|
{
|
2016-08-08 17:49:02 -05:00
|
|
|
HIP_INIT_API(deviceId);
|
2016-03-24 09:28:46 -05:00
|
|
|
|
2016-08-09 15:37:19 -05:00
|
|
|
hipError_t e = hipSuccess;
|
|
|
|
|
|
|
|
|
|
auto ctx = ihipGetTlsDefaultCtx();
|
|
|
|
|
|
2016-09-27 11:47:58 -05:00
|
|
|
if(deviceId != nullptr){
|
|
|
|
|
if (ctx == nullptr) {
|
|
|
|
|
e = hipErrorInvalidDevice; // TODO, check error code.
|
|
|
|
|
*deviceId = -1;
|
|
|
|
|
} else {
|
|
|
|
|
*deviceId = ctx->getDevice()->_deviceId;
|
|
|
|
|
}
|
|
|
|
|
}else{
|
2016-11-22 10:20:09 -06:00
|
|
|
e = hipErrorInvalidValue;
|
2016-08-09 15:37:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ihipLogStatus(e);
|
2016-03-24 09:28:46 -05:00
|
|
|
}
|
|
|
|
|
|
2016-08-09 15:37:19 -05:00
|
|
|
// TODO - does this initialize HIP runtime?
|
2016-11-23 18:37:06 +05:30
|
|
|
hipError_t ihipGetDeviceCount(int *count)
|
2016-03-24 09:28:46 -05:00
|
|
|
{
|
2016-09-27 13:04:35 -05:00
|
|
|
hipError_t e = hipSuccess;
|
2016-03-24 09:28:46 -05:00
|
|
|
|
2016-09-27 13:04:35 -05:00
|
|
|
if(count != nullptr) {
|
|
|
|
|
*count = g_deviceCnt;
|
|
|
|
|
|
|
|
|
|
if (*count > 0) {
|
|
|
|
|
e = ihipLogStatus(hipSuccess);
|
|
|
|
|
} else {
|
|
|
|
|
e = ihipLogStatus(hipErrorNoDevice);
|
|
|
|
|
}
|
2016-03-24 09:28:46 -05:00
|
|
|
} else {
|
2016-11-22 10:20:09 -06:00
|
|
|
e = ihipLogStatus(hipErrorInvalidValue);
|
2016-03-24 09:28:46 -05:00
|
|
|
}
|
2016-09-27 13:04:35 -05:00
|
|
|
return e;
|
2016-03-24 09:28:46 -05:00
|
|
|
}
|
|
|
|
|
|
2016-11-23 18:37:06 +05:30
|
|
|
hipError_t hipGetDeviceCount(int *count)
|
|
|
|
|
{
|
|
|
|
|
HIP_INIT_API(count);
|
|
|
|
|
return ihipGetDeviceCount(count);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-20 12:18:08 -06:00
|
|
|
hipError_t hipDeviceSetCacheConfig(hipFuncCache_t cacheConfig)
|
2016-03-24 09:28:46 -05:00
|
|
|
{
|
2016-07-22 15:46:55 +05:30
|
|
|
HIP_INIT_API(cacheConfig);
|
2016-03-24 09:28:46 -05:00
|
|
|
|
|
|
|
|
// Nop, AMD does not support variable cache configs.
|
|
|
|
|
|
|
|
|
|
return ihipLogStatus(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 08:56:30 -06:00
|
|
|
hipError_t hipDeviceGetCacheConfig(hipFuncCache_t *cacheConfig)
|
2016-03-24 09:28:46 -05:00
|
|
|
{
|
2016-07-22 15:46:55 +05:30
|
|
|
HIP_INIT_API(cacheConfig);
|
2016-03-24 09:28:46 -05:00
|
|
|
|
2016-11-22 10:20:09 -06:00
|
|
|
if(cacheConfig == nullptr) {
|
|
|
|
|
return ihipLogStatus(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-24 09:28:46 -05:00
|
|
|
*cacheConfig = hipFuncCachePreferNone;
|
|
|
|
|
|
|
|
|
|
return ihipLogStatus(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-13 15:13:11 -05:00
|
|
|
hipError_t hipDeviceGetLimit (size_t *pValue, hipLimit_t limit)
|
2016-10-12 19:58:48 -05:00
|
|
|
{
|
|
|
|
|
HIP_INIT_API(pValue, limit);
|
|
|
|
|
if(pValue == nullptr) {
|
|
|
|
|
return ihipLogStatus(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
if(limit == hipLimitMallocHeapSize) {
|
2016-12-05 11:03:45 +05:30
|
|
|
*pValue = (size_t)SIZE_OF_HEAP;
|
2016-10-12 19:58:48 -05:00
|
|
|
return ihipLogStatus(hipSuccess);
|
|
|
|
|
}else{
|
|
|
|
|
return ihipLogStatus(hipErrorUnsupportedLimit);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-28 11:53:11 -05:00
|
|
|
hipError_t hipFuncSetCacheConfig (const void* func, hipFuncCache_t cacheConfig)
|
2016-03-24 09:28:46 -05:00
|
|
|
{
|
2016-07-22 15:46:55 +05:30
|
|
|
HIP_INIT_API(cacheConfig);
|
2016-03-24 09:28:46 -05:00
|
|
|
|
|
|
|
|
// Nop, AMD does not support variable cache configs.
|
|
|
|
|
|
|
|
|
|
return ihipLogStatus(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-12 19:58:48 -05:00
|
|
|
hipError_t hipDeviceSetSharedMemConfig (hipSharedMemConfig config)
|
2016-03-24 09:28:46 -05:00
|
|
|
{
|
2016-07-22 15:46:55 +05:30
|
|
|
HIP_INIT_API(config);
|
2016-03-24 09:28:46 -05:00
|
|
|
|
|
|
|
|
// Nop, AMD does not support variable shared mem configs.
|
|
|
|
|
|
|
|
|
|
return ihipLogStatus(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-12 19:58:48 -05:00
|
|
|
hipError_t hipDeviceGetSharedMemConfig (hipSharedMemConfig *pConfig)
|
2016-03-24 09:28:46 -05:00
|
|
|
{
|
2016-07-22 15:46:55 +05:30
|
|
|
HIP_INIT_API(pConfig);
|
2016-03-24 09:28:46 -05:00
|
|
|
|
|
|
|
|
*pConfig = hipSharedMemBankSizeFourByte;
|
|
|
|
|
|
|
|
|
|
return ihipLogStatus(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-08 17:49:02 -05:00
|
|
|
hipError_t hipSetDevice(int deviceId)
|
2016-03-24 09:28:46 -05:00
|
|
|
{
|
2016-08-08 17:49:02 -05:00
|
|
|
HIP_INIT_API(deviceId);
|
|
|
|
|
if ((deviceId < 0) || (deviceId >= g_deviceCnt)) {
|
2016-03-24 09:28:46 -05:00
|
|
|
return ihipLogStatus(hipErrorInvalidDevice);
|
|
|
|
|
} else {
|
2016-08-09 15:37:19 -05:00
|
|
|
ihipSetTlsDefaultCtx(ihipGetPrimaryCtx(deviceId));
|
2016-03-24 09:28:46 -05:00
|
|
|
return ihipLogStatus(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipDeviceSynchronize(void)
|
|
|
|
|
{
|
2016-09-01 17:58:24 -05:00
|
|
|
HIP_INIT_API();
|
2016-09-02 15:49:22 -05:00
|
|
|
return ihipLogStatus(ihipSynchronize());
|
2016-03-24 09:28:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipDeviceReset(void)
|
|
|
|
|
{
|
|
|
|
|
HIP_INIT_API();
|
|
|
|
|
|
2016-08-07 21:46:51 -05:00
|
|
|
auto *ctx = ihipGetTlsDefaultCtx();
|
2016-03-24 09:28:46 -05:00
|
|
|
|
|
|
|
|
// TODO-HCC
|
|
|
|
|
// This function currently does a user-level cleanup of known resources.
|
|
|
|
|
// It could benefit from KFD support to perform a more "nuclear" clean that would include any associated kernel resources and page table entries.
|
|
|
|
|
|
2017-02-27 15:17:11 +05:30
|
|
|
#if 0
|
2016-08-07 21:46:51 -05:00
|
|
|
if (ctx) {
|
|
|
|
|
// Release ctx resources (streams and memory):
|
2016-09-02 15:49:22 -05:00
|
|
|
ctx->locked_reset();
|
2016-03-24 09:28:46 -05:00
|
|
|
}
|
2017-02-27 15:17:11 +05:30
|
|
|
#endif
|
|
|
|
|
if (ctx) {
|
|
|
|
|
ihipDevice_t *deviceHandle = ctx->getWriteableDevice();
|
|
|
|
|
deviceHandle->locked_reset();
|
|
|
|
|
}
|
2016-03-24 09:28:46 -05:00
|
|
|
|
|
|
|
|
return ihipLogStatus(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-26 18:40:37 -05:00
|
|
|
|
2017-01-09 23:54:01 +05:30
|
|
|
hipError_t ihipDeviceSetState(void)
|
|
|
|
|
{
|
|
|
|
|
hipError_t e = hipErrorInvalidContext;
|
|
|
|
|
auto *ctx = ihipGetTlsDefaultCtx();
|
|
|
|
|
|
|
|
|
|
if (ctx) {
|
|
|
|
|
ihipDevice_t *deviceHandle = ctx->getWriteableDevice();
|
|
|
|
|
if(deviceHandle->_state == 0)
|
|
|
|
|
{
|
|
|
|
|
deviceHandle->_state = 1;
|
|
|
|
|
}
|
|
|
|
|
e = hipSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-19 21:26:36 -06:00
|
|
|
return e;
|
2017-01-09 23:54:01 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-11-23 18:37:06 +05:30
|
|
|
hipError_t ihipDeviceGetAttribute(int* pi, hipDeviceAttribute_t attr, int device)
|
2016-03-24 09:28:46 -05:00
|
|
|
{
|
|
|
|
|
hipError_t e = hipSuccess;
|
|
|
|
|
|
2016-11-21 18:07:01 -06:00
|
|
|
if(pi == nullptr) {
|
|
|
|
|
return ihipLogStatus(hipErrorInvalidValue);
|
|
|
|
|
}
|
2016-09-27 13:33:42 -05:00
|
|
|
|
2016-08-07 21:46:51 -05:00
|
|
|
auto * hipDevice = ihipGetDevice(device);
|
2016-03-24 09:28:46 -05:00
|
|
|
hipDeviceProp_t *prop = &hipDevice->_props;
|
|
|
|
|
if (hipDevice) {
|
|
|
|
|
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:
|
|
|
|
|
e = hipErrorInvalidValue; break;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
e = hipErrorInvalidDevice;
|
|
|
|
|
}
|
2017-01-19 21:26:36 -06:00
|
|
|
return e;
|
2016-03-24 09:28:46 -05:00
|
|
|
}
|
|
|
|
|
|
2016-11-23 18:37:06 +05:30
|
|
|
hipError_t hipDeviceGetAttribute(int* pi, hipDeviceAttribute_t attr, int device)
|
2016-03-24 09:28:46 -05:00
|
|
|
{
|
2016-11-23 18:37:06 +05:30
|
|
|
HIP_INIT_API(pi, attr, device);
|
2017-01-20 14:38:35 -06:00
|
|
|
return ihipLogStatus(ihipDeviceGetAttribute(pi,attr,device));
|
2016-11-23 18:37:06 +05:30
|
|
|
}
|
2016-03-24 09:28:46 -05:00
|
|
|
|
2016-11-23 18:37:06 +05:30
|
|
|
hipError_t ihipGetDeviceProperties(hipDeviceProp_t* props, int device)
|
|
|
|
|
{
|
2016-03-24 09:28:46 -05:00
|
|
|
hipError_t e;
|
|
|
|
|
|
2016-09-27 13:04:35 -05:00
|
|
|
if(props != nullptr){
|
|
|
|
|
auto * hipDevice = ihipGetDevice(device);
|
|
|
|
|
if (hipDevice) {
|
2016-03-24 09:28:46 -05:00
|
|
|
// copy saved props
|
2016-09-27 13:04:35 -05:00
|
|
|
*props = hipDevice->_props;
|
|
|
|
|
e = hipSuccess;
|
|
|
|
|
} else {
|
|
|
|
|
e = hipErrorInvalidDevice;
|
|
|
|
|
}
|
|
|
|
|
}else{
|
2016-03-24 09:28:46 -05:00
|
|
|
e = hipErrorInvalidDevice;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-19 21:26:36 -06:00
|
|
|
return e;
|
2016-03-24 09:28:46 -05:00
|
|
|
}
|
2016-03-24 04:57:30 -05:00
|
|
|
|
2016-11-23 18:37:06 +05:30
|
|
|
hipError_t hipGetDeviceProperties(hipDeviceProp_t* props, int device)
|
|
|
|
|
{
|
|
|
|
|
HIP_INIT_API(props, device);
|
2017-05-12 17:04:23 -05:00
|
|
|
return ihipLogStatus(ihipGetDeviceProperties(props, device));
|
2016-11-23 18:37:06 +05:30
|
|
|
}
|
|
|
|
|
|
2016-03-24 07:04:01 -05:00
|
|
|
hipError_t hipSetDeviceFlags( unsigned int flags)
|
|
|
|
|
{
|
|
|
|
|
HIP_INIT_API(flags);
|
|
|
|
|
|
2016-10-17 19:59:36 -05:00
|
|
|
hipError_t e = hipSuccess;
|
2016-03-24 07:04:01 -05:00
|
|
|
|
2016-08-08 11:55:57 -05:00
|
|
|
auto * ctx = ihipGetTlsDefaultCtx();
|
|
|
|
|
|
|
|
|
|
// TODO : does this really OR in the flags or replaces previous flags:
|
|
|
|
|
// TODO : Review error handling behavior for this function, it often returns ErrorSetOnActiveProcess
|
|
|
|
|
if (ctx) {
|
2017-01-09 23:54:01 +05:30
|
|
|
auto *deviceHandle = ctx->getDevice();
|
|
|
|
|
if(deviceHandle->_state == 0)
|
|
|
|
|
{
|
|
|
|
|
ctx->_ctxFlags = ctx->_ctxFlags | flags;
|
|
|
|
|
if (flags & hipDeviceScheduleMask) {
|
|
|
|
|
switch (hipDeviceScheduleMask) {
|
|
|
|
|
case hipDeviceScheduleAuto:
|
|
|
|
|
case hipDeviceScheduleSpin:
|
|
|
|
|
case hipDeviceScheduleYield:
|
|
|
|
|
case hipDeviceScheduleBlockingSync:
|
|
|
|
|
e = hipSuccess;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
e = hipSuccess; // TODO - should this be error? Map to Auto?
|
|
|
|
|
//e = hipErrorInvalidValue;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2016-10-17 19:59:36 -05:00
|
|
|
}
|
|
|
|
|
|
2017-01-09 23:54:01 +05:30
|
|
|
unsigned supportedFlags = hipDeviceScheduleMask | hipDeviceMapHost | hipDeviceLmemResizeToMax;
|
2016-10-17 19:59:36 -05:00
|
|
|
|
2017-01-09 23:54:01 +05:30
|
|
|
if (flags & (~supportedFlags)) {
|
|
|
|
|
e = hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
e = hipErrorSetOnActiveProcess;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
e = hipErrorInvalidDevice;
|
2016-03-24 07:04:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ihipLogStatus(e);
|
2016-08-08 11:55:57 -05:00
|
|
|
};
|
2016-03-24 07:04:01 -05:00
|
|
|
|
2016-09-02 14:45:53 +05:30
|
|
|
hipError_t hipDeviceComputeCapability(int *major, int *minor, hipDevice_t device)
|
|
|
|
|
{
|
|
|
|
|
HIP_INIT_API(major,minor, device);
|
|
|
|
|
hipError_t e = hipSuccess;
|
2016-12-17 16:53:03 +05:30
|
|
|
e = ihipDeviceGetAttribute(major, hipDeviceAttributeComputeCapabilityMajor, device);
|
|
|
|
|
e = ihipDeviceGetAttribute(minor, hipDeviceAttributeComputeCapabilityMinor, device);
|
2016-09-02 14:45:53 +05:30
|
|
|
return ihipLogStatus(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipDeviceGetName(char *name,int len,hipDevice_t device)
|
|
|
|
|
{
|
|
|
|
|
HIP_INIT_API(name,len, device);
|
|
|
|
|
hipError_t e = hipSuccess;
|
2016-12-17 16:53:03 +05:30
|
|
|
auto deviceHandle = ihipGetDevice(device);
|
|
|
|
|
int nameLen = strlen(deviceHandle->_props.name);
|
2016-09-02 14:45:53 +05:30
|
|
|
if(nameLen <= len)
|
2016-12-17 16:53:03 +05:30
|
|
|
memcpy(name,deviceHandle->_props.name,nameLen);
|
2016-09-02 14:45:53 +05:30
|
|
|
return ihipLogStatus(e);
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-06 14:21:03 -06:00
|
|
|
hipError_t hipDeviceGetPCIBusId (char *pciBusId,int len, int device)
|
2016-09-02 14:45:53 +05:30
|
|
|
{
|
2016-11-28 10:47:18 -06:00
|
|
|
HIP_INIT_API(pciBusId, len, device);
|
2017-06-15 00:21:47 +05:30
|
|
|
hipError_t e = hipErrorInvalidValue;
|
|
|
|
|
int deviceCount = 0;
|
|
|
|
|
ihipGetDeviceCount( &deviceCount );
|
|
|
|
|
if((device > deviceCount) || (device < 0)) {
|
|
|
|
|
e = hipErrorInvalidDevice;
|
|
|
|
|
} else {
|
|
|
|
|
if((pciBusId != nullptr) && (len > 0)) {
|
2017-06-28 23:48:27 +05:30
|
|
|
auto deviceHandle = ihipGetDevice(device);
|
|
|
|
|
int retVal = snprintf(pciBusId,len, "%04x:%02x:%02x.0",deviceHandle->_props.pciDomainID,deviceHandle->_props.pciBusID,deviceHandle->_props.pciDeviceID);
|
|
|
|
|
if( retVal > 0 && retVal < len) {
|
|
|
|
|
e = hipSuccess;
|
2017-06-15 00:21:47 +05:30
|
|
|
}
|
|
|
|
|
}
|
2016-12-06 16:55:17 +05:30
|
|
|
}
|
2016-09-02 14:45:53 +05:30
|
|
|
return ihipLogStatus(e);
|
|
|
|
|
}
|
2016-12-17 16:53:03 +05:30
|
|
|
|
2016-09-02 15:11:36 +05:30
|
|
|
hipError_t hipDeviceTotalMem (size_t *bytes,hipDevice_t device)
|
|
|
|
|
{
|
|
|
|
|
HIP_INIT_API(bytes, device);
|
|
|
|
|
hipError_t e = hipSuccess;
|
2016-12-17 16:53:03 +05:30
|
|
|
auto deviceHandle = ihipGetDevice(device);
|
|
|
|
|
*bytes= deviceHandle->_props.totalGlobalMem;
|
2016-09-02 15:11:36 +05:30
|
|
|
return ihipLogStatus(e);
|
|
|
|
|
}
|
2016-09-08 22:37:24 +05:30
|
|
|
|
2017-07-01 07:56:30 +05:30
|
|
|
hipError_t hipDeviceGetByPCIBusId (int* device, const char* pciBusId )
|
2016-11-01 10:57:48 +05:30
|
|
|
{
|
|
|
|
|
HIP_INIT_API(device,pciBusId);
|
|
|
|
|
hipDeviceProp_t tempProp;
|
2017-06-30 10:11:41 +05:30
|
|
|
int deviceCount = 0 ;
|
2016-11-01 10:57:48 +05:30
|
|
|
hipError_t e = hipErrorInvalidValue;
|
2017-06-30 10:11:41 +05:30
|
|
|
if((device != nullptr) && (pciBusId != nullptr)) {
|
|
|
|
|
int pciBusID = -1;
|
|
|
|
|
int pciDeviceID = -1;
|
|
|
|
|
int pciDomainID = -1;
|
|
|
|
|
int len = 0;
|
|
|
|
|
len = sscanf (pciBusId,"%04x:%02x:%02x",&pciDomainID,&pciBusID,&pciDeviceID);
|
|
|
|
|
if(len == 3) {
|
|
|
|
|
ihipGetDeviceCount( &deviceCount );
|
|
|
|
|
for (int i = 0; i< deviceCount; i++) {
|
|
|
|
|
ihipGetDeviceProperties( &tempProp, i );
|
|
|
|
|
if(tempProp.pciBusID == pciBusID) {
|
|
|
|
|
*device = i;
|
|
|
|
|
e = hipSuccess;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-11-01 10:57:48 +05:30
|
|
|
}
|
|
|
|
|
return ihipLogStatus(e);
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-08 22:37:24 +05:30
|
|
|
hipError_t hipChooseDevice( int* device, const hipDeviceProp_t* prop )
|
|
|
|
|
{
|
2016-11-01 10:57:48 +05:30
|
|
|
HIP_INIT_API(device,prop);
|
2016-09-08 22:37:24 +05:30
|
|
|
hipDeviceProp_t tempProp;
|
|
|
|
|
int deviceCount;
|
2016-11-23 18:37:06 +05:30
|
|
|
int inPropCount = 0;
|
|
|
|
|
int matchedPropCount = 0;
|
2016-09-08 22:37:24 +05:30
|
|
|
hipError_t e = hipSuccess;
|
2017-06-13 13:35:50 +05:30
|
|
|
if((device == NULL) || (prop == NULL)) {
|
|
|
|
|
e = hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
if(e == hipSuccess) {
|
|
|
|
|
ihipGetDeviceCount( &deviceCount );
|
|
|
|
|
*device = 0;
|
|
|
|
|
for (int i = 0; i < deviceCount; i++) {
|
|
|
|
|
ihipGetDeviceProperties( &tempProp, i );
|
|
|
|
|
if(prop->major != 0) {
|
|
|
|
|
inPropCount++;
|
|
|
|
|
if(tempProp.major >= prop->major) {
|
|
|
|
|
matchedPropCount++;
|
|
|
|
|
}
|
|
|
|
|
if(prop->minor != 0) {
|
|
|
|
|
inPropCount++;
|
|
|
|
|
if(tempProp.minor >= prop->minor) {
|
|
|
|
|
matchedPropCount++;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-09-08 22:37:24 +05:30
|
|
|
}
|
2017-06-13 13:35:50 +05:30
|
|
|
if(prop->totalGlobalMem != 0) {
|
2016-09-08 22:37:24 +05:30
|
|
|
inPropCount++;
|
2017-06-13 13:35:50 +05:30
|
|
|
if(tempProp.totalGlobalMem >= prop->totalGlobalMem) {
|
|
|
|
|
matchedPropCount++;
|
|
|
|
|
}
|
2016-09-08 22:37:24 +05:30
|
|
|
}
|
2017-06-13 13:35:50 +05:30
|
|
|
if(prop->sharedMemPerBlock != 0) {
|
|
|
|
|
inPropCount++;
|
|
|
|
|
if(tempProp.sharedMemPerBlock >= prop->sharedMemPerBlock) {
|
|
|
|
|
matchedPropCount++;
|
|
|
|
|
}
|
2016-09-16 11:18:34 +05:30
|
|
|
}
|
2017-06-13 13:35:50 +05:30
|
|
|
if(prop->maxThreadsPerBlock != 0) {
|
|
|
|
|
inPropCount++;
|
|
|
|
|
if(tempProp.maxThreadsPerBlock >= prop->maxThreadsPerBlock ) {
|
|
|
|
|
matchedPropCount++;
|
|
|
|
|
}
|
2016-09-16 11:18:34 +05:30
|
|
|
}
|
2017-06-13 13:35:50 +05:30
|
|
|
if(prop->totalConstMem != 0) {
|
|
|
|
|
inPropCount++;
|
|
|
|
|
if(tempProp.totalConstMem >= prop->totalConstMem ) {
|
|
|
|
|
matchedPropCount++;
|
|
|
|
|
}
|
2016-09-16 11:18:34 +05:30
|
|
|
}
|
2017-06-13 13:35:50 +05:30
|
|
|
if(prop->multiProcessorCount != 0) {
|
|
|
|
|
inPropCount++;
|
|
|
|
|
if(tempProp.multiProcessorCount >= prop->multiProcessorCount ) {
|
|
|
|
|
matchedPropCount++;
|
|
|
|
|
}
|
2016-09-16 11:18:34 +05:30
|
|
|
}
|
2017-06-13 13:35:50 +05:30
|
|
|
if(prop->maxThreadsPerMultiProcessor != 0) {
|
|
|
|
|
inPropCount++;
|
|
|
|
|
if(tempProp.maxThreadsPerMultiProcessor >= prop->maxThreadsPerMultiProcessor ) {
|
|
|
|
|
matchedPropCount++;
|
|
|
|
|
}
|
2016-09-16 11:18:34 +05:30
|
|
|
}
|
2017-06-13 13:35:50 +05:30
|
|
|
if(prop->memoryClockRate != 0) {
|
|
|
|
|
inPropCount++;
|
|
|
|
|
if(tempProp.memoryClockRate >= prop->memoryClockRate ) {
|
|
|
|
|
matchedPropCount++;
|
|
|
|
|
}
|
2016-09-16 11:18:34 +05:30
|
|
|
}
|
2017-06-13 13:35:50 +05:30
|
|
|
if(inPropCount == matchedPropCount) {
|
|
|
|
|
*device = i;
|
2016-09-16 11:18:34 +05:30
|
|
|
}
|
2016-09-08 22:37:24 +05:30
|
|
|
#if 0
|
|
|
|
|
else{
|
|
|
|
|
e= hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2017-06-13 13:35:50 +05:30
|
|
|
}
|
2016-09-08 22:37:24 +05:30
|
|
|
}
|
|
|
|
|
return ihipLogStatus(e);
|
|
|
|
|
}
|
2017-06-13 13:35:50 +05:30
|
|
|
|