Apply .clangformat to all repo source files
Change-Id: I7e79c6058f0303f9a98911e3b7dd2e8596079344
This commit is contained in:
+208
-205
@@ -26,25 +26,24 @@ THE SOFTWARE.
|
||||
#include "device_util.h"
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//Devices
|
||||
// Devices
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// TODO - does this initialize HIP runtime?
|
||||
hipError_t hipGetDevice(int *deviceId)
|
||||
{
|
||||
hipError_t hipGetDevice(int* deviceId) {
|
||||
HIP_INIT_API(deviceId);
|
||||
|
||||
hipError_t e = hipSuccess;
|
||||
|
||||
auto ctx = ihipGetTlsDefaultCtx();
|
||||
|
||||
if(deviceId != nullptr){
|
||||
if (deviceId != nullptr) {
|
||||
if (ctx == nullptr) {
|
||||
e = hipErrorInvalidDevice; // TODO, check error code.
|
||||
e = hipErrorInvalidDevice; // TODO, check error code.
|
||||
*deviceId = -1;
|
||||
} else {
|
||||
*deviceId = ctx->getDevice()->_deviceId;
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
e = hipErrorInvalidValue;
|
||||
}
|
||||
|
||||
@@ -52,11 +51,10 @@ hipError_t hipGetDevice(int *deviceId)
|
||||
}
|
||||
|
||||
// TODO - does this initialize HIP runtime?
|
||||
hipError_t ihipGetDeviceCount(int *count)
|
||||
{
|
||||
hipError_t ihipGetDeviceCount(int* count) {
|
||||
hipError_t e = hipSuccess;
|
||||
|
||||
if(count != nullptr) {
|
||||
if (count != nullptr) {
|
||||
*count = g_deviceCnt;
|
||||
|
||||
if (*count > 0) {
|
||||
@@ -70,14 +68,12 @@ hipError_t ihipGetDeviceCount(int *count)
|
||||
return e;
|
||||
}
|
||||
|
||||
hipError_t hipGetDeviceCount(int *count)
|
||||
{
|
||||
hipError_t hipGetDeviceCount(int* count) {
|
||||
HIP_INIT_API(count);
|
||||
return ihipLogStatus(ihipGetDeviceCount(count));
|
||||
}
|
||||
|
||||
hipError_t hipDeviceSetCacheConfig(hipFuncCache_t cacheConfig)
|
||||
{
|
||||
hipError_t hipDeviceSetCacheConfig(hipFuncCache_t cacheConfig) {
|
||||
HIP_INIT_API(cacheConfig);
|
||||
|
||||
// Nop, AMD does not support variable cache configs.
|
||||
@@ -85,11 +81,10 @@ hipError_t hipDeviceSetCacheConfig(hipFuncCache_t cacheConfig)
|
||||
return ihipLogStatus(hipSuccess);
|
||||
}
|
||||
|
||||
hipError_t hipDeviceGetCacheConfig(hipFuncCache_t *cacheConfig)
|
||||
{
|
||||
hipError_t hipDeviceGetCacheConfig(hipFuncCache_t* cacheConfig) {
|
||||
HIP_INIT_API(cacheConfig);
|
||||
|
||||
if(cacheConfig == nullptr) {
|
||||
if (cacheConfig == nullptr) {
|
||||
return ihipLogStatus(hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
@@ -98,22 +93,20 @@ hipError_t hipDeviceGetCacheConfig(hipFuncCache_t *cacheConfig)
|
||||
return ihipLogStatus(hipSuccess);
|
||||
}
|
||||
|
||||
hipError_t hipDeviceGetLimit (size_t *pValue, hipLimit_t limit)
|
||||
{
|
||||
hipError_t hipDeviceGetLimit(size_t* pValue, hipLimit_t limit) {
|
||||
HIP_INIT_API(pValue, limit);
|
||||
if(pValue == nullptr) {
|
||||
if (pValue == nullptr) {
|
||||
return ihipLogStatus(hipErrorInvalidValue);
|
||||
}
|
||||
if(limit == hipLimitMallocHeapSize) {
|
||||
if (limit == hipLimitMallocHeapSize) {
|
||||
*pValue = (size_t)SIZE_OF_HEAP;
|
||||
return ihipLogStatus(hipSuccess);
|
||||
}else{
|
||||
} else {
|
||||
return ihipLogStatus(hipErrorUnsupportedLimit);
|
||||
}
|
||||
}
|
||||
|
||||
hipError_t hipFuncSetCacheConfig (const void* func, hipFuncCache_t cacheConfig)
|
||||
{
|
||||
hipError_t hipFuncSetCacheConfig(const void* func, hipFuncCache_t cacheConfig) {
|
||||
HIP_INIT_API(cacheConfig);
|
||||
|
||||
// Nop, AMD does not support variable cache configs.
|
||||
@@ -121,8 +114,7 @@ hipError_t hipFuncSetCacheConfig (const void* func, hipFuncCache_t cacheConfig)
|
||||
return ihipLogStatus(hipSuccess);
|
||||
}
|
||||
|
||||
hipError_t hipDeviceSetSharedMemConfig (hipSharedMemConfig config)
|
||||
{
|
||||
hipError_t hipDeviceSetSharedMemConfig(hipSharedMemConfig config) {
|
||||
HIP_INIT_API(config);
|
||||
|
||||
// Nop, AMD does not support variable shared mem configs.
|
||||
@@ -130,8 +122,7 @@ hipError_t hipDeviceSetSharedMemConfig (hipSharedMemConfig config)
|
||||
return ihipLogStatus(hipSuccess);
|
||||
}
|
||||
|
||||
hipError_t hipDeviceGetSharedMemConfig (hipSharedMemConfig *pConfig)
|
||||
{
|
||||
hipError_t hipDeviceGetSharedMemConfig(hipSharedMemConfig* pConfig) {
|
||||
HIP_INIT_API(pConfig);
|
||||
|
||||
*pConfig = hipSharedMemBankSizeFourByte;
|
||||
@@ -139,8 +130,7 @@ hipError_t hipDeviceGetSharedMemConfig (hipSharedMemConfig *pConfig)
|
||||
return ihipLogStatus(hipSuccess);
|
||||
}
|
||||
|
||||
hipError_t hipSetDevice(int deviceId)
|
||||
{
|
||||
hipError_t hipSetDevice(int deviceId) {
|
||||
HIP_INIT_API(deviceId);
|
||||
if ((deviceId < 0) || (deviceId >= g_deviceCnt)) {
|
||||
return ihipLogStatus(hipErrorInvalidDevice);
|
||||
@@ -151,21 +141,20 @@ hipError_t hipSetDevice(int deviceId)
|
||||
}
|
||||
}
|
||||
|
||||
hipError_t hipDeviceSynchronize(void)
|
||||
{
|
||||
hipError_t hipDeviceSynchronize(void) {
|
||||
HIP_INIT_SPECIAL_API(TRACE_SYNC);
|
||||
return ihipLogStatus(ihipSynchronize());
|
||||
}
|
||||
|
||||
hipError_t hipDeviceReset(void)
|
||||
{
|
||||
hipError_t hipDeviceReset(void) {
|
||||
HIP_INIT_API();
|
||||
|
||||
auto *ctx = ihipGetTlsDefaultCtx();
|
||||
auto* ctx = ihipGetTlsDefaultCtx();
|
||||
|
||||
// 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.
|
||||
// It could benefit from KFD support to perform a more "nuclear" clean that would include any
|
||||
// associated kernel resources and page table entries.
|
||||
|
||||
#if 0
|
||||
if (ctx) {
|
||||
@@ -173,24 +162,22 @@ hipError_t hipDeviceReset(void)
|
||||
ctx->locked_reset();
|
||||
}
|
||||
#endif
|
||||
if (ctx) {
|
||||
ihipDevice_t *deviceHandle = ctx->getWriteableDevice();
|
||||
deviceHandle->locked_reset();
|
||||
}
|
||||
if (ctx) {
|
||||
ihipDevice_t* deviceHandle = ctx->getWriteableDevice();
|
||||
deviceHandle->locked_reset();
|
||||
}
|
||||
|
||||
return ihipLogStatus(hipSuccess);
|
||||
}
|
||||
|
||||
|
||||
hipError_t ihipDeviceSetState(void)
|
||||
{
|
||||
hipError_t ihipDeviceSetState(void) {
|
||||
hipError_t e = hipErrorInvalidContext;
|
||||
auto *ctx = ihipGetTlsDefaultCtx();
|
||||
auto* ctx = ihipGetTlsDefaultCtx();
|
||||
|
||||
if (ctx) {
|
||||
ihipDevice_t *deviceHandle = ctx->getWriteableDevice();
|
||||
if(deviceHandle->_state == 0)
|
||||
{
|
||||
ihipDevice_t* deviceHandle = ctx->getWriteableDevice();
|
||||
if (deviceHandle->_state == 0) {
|
||||
deviceHandle->_state = 1;
|
||||
}
|
||||
e = hipSuccess;
|
||||
@@ -200,70 +187,95 @@ hipError_t ihipDeviceSetState(void)
|
||||
}
|
||||
|
||||
|
||||
hipError_t ihipDeviceGetAttribute(int* pi, hipDeviceAttribute_t attr, int device)
|
||||
{
|
||||
hipError_t ihipDeviceGetAttribute(int* pi, hipDeviceAttribute_t attr, int device) {
|
||||
hipError_t e = hipSuccess;
|
||||
|
||||
if(pi == nullptr) {
|
||||
if (pi == nullptr) {
|
||||
return hipErrorInvalidValue;
|
||||
}
|
||||
|
||||
auto * hipDevice = ihipGetDevice(device);
|
||||
hipDeviceProp_t *prop = &hipDevice->_props;
|
||||
auto* hipDevice = ihipGetDevice(device);
|
||||
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;
|
||||
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;
|
||||
@@ -271,37 +283,34 @@ hipError_t ihipDeviceGetAttribute(int* pi, hipDeviceAttribute_t attr, int device
|
||||
return e;
|
||||
}
|
||||
|
||||
hipError_t hipDeviceGetAttribute(int* pi, hipDeviceAttribute_t attr, int device)
|
||||
{
|
||||
hipError_t hipDeviceGetAttribute(int* pi, hipDeviceAttribute_t attr, int device) {
|
||||
HIP_INIT_API(pi, attr, device);
|
||||
if ((device < 0) || (device >= g_deviceCnt)) {
|
||||
return ihipLogStatus(hipErrorInvalidDevice);
|
||||
}
|
||||
return ihipLogStatus(ihipDeviceGetAttribute(pi,attr,device));
|
||||
}
|
||||
return ihipLogStatus(ihipDeviceGetAttribute(pi, attr, device));
|
||||
}
|
||||
|
||||
hipError_t ihipGetDeviceProperties(hipDeviceProp_t* props, int device)
|
||||
{
|
||||
hipError_t ihipGetDeviceProperties(hipDeviceProp_t* props, int device) {
|
||||
hipError_t e;
|
||||
|
||||
if(props != nullptr){
|
||||
auto * hipDevice = ihipGetDevice(device);
|
||||
if (props != nullptr) {
|
||||
auto* hipDevice = ihipGetDevice(device);
|
||||
if (hipDevice) {
|
||||
// copy saved props
|
||||
// copy saved props
|
||||
*props = hipDevice->_props;
|
||||
e = hipSuccess;
|
||||
} else {
|
||||
e = hipErrorInvalidDevice;
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
e = hipErrorInvalidDevice;
|
||||
}
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
hipError_t hipGetDeviceProperties(hipDeviceProp_t* props, int device)
|
||||
{
|
||||
hipError_t hipGetDeviceProperties(hipDeviceProp_t* props, int device) {
|
||||
HIP_INIT_API(props, device);
|
||||
if ((device < 0) || (device >= g_deviceCnt)) {
|
||||
return ihipLogStatus(hipErrorInvalidDevice);
|
||||
@@ -309,54 +318,53 @@ hipError_t hipGetDeviceProperties(hipDeviceProp_t* props, int device)
|
||||
return ihipLogStatus(ihipGetDeviceProperties(props, device));
|
||||
}
|
||||
|
||||
hipError_t hipSetDeviceFlags( unsigned int flags)
|
||||
{
|
||||
hipError_t hipSetDeviceFlags(unsigned int flags) {
|
||||
HIP_INIT_API(flags);
|
||||
|
||||
hipError_t e = hipSuccess;
|
||||
|
||||
auto * ctx = ihipGetTlsDefaultCtx();
|
||||
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
|
||||
// TODO : Review error handling behavior for this function, it often returns
|
||||
// ErrorSetOnActiveProcess
|
||||
if (ctx) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned supportedFlags = hipDeviceScheduleMask | hipDeviceMapHost | hipDeviceLmemResizeToMax;
|
||||
unsigned supportedFlags =
|
||||
hipDeviceScheduleMask | hipDeviceMapHost | hipDeviceLmemResizeToMax;
|
||||
|
||||
if (flags & (~supportedFlags)) {
|
||||
e = hipErrorInvalidValue;
|
||||
}
|
||||
if (flags & (~supportedFlags)) {
|
||||
e = hipErrorInvalidValue;
|
||||
}
|
||||
} else {
|
||||
e = hipErrorSetOnActiveProcess;
|
||||
e = hipErrorSetOnActiveProcess;
|
||||
}
|
||||
} else {
|
||||
e = hipErrorInvalidDevice;
|
||||
} else {
|
||||
e = hipErrorInvalidDevice;
|
||||
}
|
||||
|
||||
return ihipLogStatus(e);
|
||||
};
|
||||
|
||||
hipError_t hipDeviceComputeCapability(int *major, int *minor, hipDevice_t device)
|
||||
{
|
||||
HIP_INIT_API(major,minor, device);
|
||||
hipError_t hipDeviceComputeCapability(int* major, int* minor, hipDevice_t device) {
|
||||
HIP_INIT_API(major, minor, device);
|
||||
hipError_t e = hipSuccess;
|
||||
if ((device < 0) || (device >= g_deviceCnt)) {
|
||||
e = hipErrorInvalidDevice;
|
||||
@@ -367,34 +375,33 @@ hipError_t hipDeviceComputeCapability(int *major, int *minor, hipDevice_t device
|
||||
return ihipLogStatus(e);
|
||||
}
|
||||
|
||||
hipError_t hipDeviceGetName(char *name,int len,hipDevice_t device)
|
||||
{
|
||||
hipError_t hipDeviceGetName(char* name, int len, hipDevice_t device) {
|
||||
// Cast to void* here to avoid printing garbage in debug modes.
|
||||
HIP_INIT_API((void*)name,len, device);
|
||||
HIP_INIT_API((void*)name, len, device);
|
||||
hipError_t e = hipSuccess;
|
||||
if ((device < 0) || (device >= g_deviceCnt)) {
|
||||
e = hipErrorInvalidDevice;
|
||||
} else {
|
||||
auto deviceHandle = ihipGetDevice(device);
|
||||
int nameLen = strlen(deviceHandle->_props.name);
|
||||
if(nameLen <= len)
|
||||
memcpy(name,deviceHandle->_props.name,nameLen);
|
||||
if (nameLen <= len) memcpy(name, deviceHandle->_props.name, nameLen);
|
||||
}
|
||||
return ihipLogStatus(e);
|
||||
}
|
||||
|
||||
hipError_t hipDeviceGetPCIBusId (char *pciBusId,int len, int device)
|
||||
{
|
||||
hipError_t hipDeviceGetPCIBusId(char* pciBusId, int len, int device) {
|
||||
// Cast to void* here to avoid printing garbage in debug modes.
|
||||
HIP_INIT_API((void*)pciBusId, len, device);
|
||||
hipError_t e = hipErrorInvalidValue;
|
||||
if ((device < 0) || (device >= g_deviceCnt)) {
|
||||
e = hipErrorInvalidDevice;
|
||||
} else {
|
||||
if((pciBusId != nullptr) && (len > 0)) {
|
||||
if ((pciBusId != nullptr) && (len > 0)) {
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -402,117 +409,114 @@ hipError_t hipDeviceGetPCIBusId (char *pciBusId,int len, int device)
|
||||
return ihipLogStatus(e);
|
||||
}
|
||||
|
||||
hipError_t hipDeviceTotalMem (size_t *bytes,hipDevice_t device)
|
||||
{
|
||||
hipError_t hipDeviceTotalMem(size_t* bytes, hipDevice_t device) {
|
||||
HIP_INIT_API(bytes, device);
|
||||
hipError_t e = hipSuccess;
|
||||
if ((device < 0) || (device >= g_deviceCnt)) {
|
||||
e = hipErrorInvalidDevice;
|
||||
} else {
|
||||
auto deviceHandle = ihipGetDevice(device);
|
||||
*bytes= deviceHandle->_props.totalGlobalMem;
|
||||
*bytes = deviceHandle->_props.totalGlobalMem;
|
||||
}
|
||||
return ihipLogStatus(e);
|
||||
}
|
||||
|
||||
hipError_t hipDeviceGetByPCIBusId (int* device, const char* pciBusId )
|
||||
{
|
||||
HIP_INIT_API(device,pciBusId);
|
||||
hipDeviceProp_t tempProp;
|
||||
int deviceCount = 0 ;
|
||||
hipError_t hipDeviceGetByPCIBusId(int* device, const char* pciBusId) {
|
||||
HIP_INIT_API(device, pciBusId);
|
||||
hipDeviceProp_t tempProp;
|
||||
int deviceCount = 0;
|
||||
hipError_t e = hipErrorInvalidValue;
|
||||
if((device != nullptr) && (pciBusId != nullptr)) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ihipLogStatus(e);
|
||||
}
|
||||
|
||||
hipError_t hipChooseDevice( int* device, const hipDeviceProp_t* prop )
|
||||
{
|
||||
HIP_INIT_API(device,prop);
|
||||
hipDeviceProp_t tempProp;
|
||||
hipError_t hipChooseDevice(int* device, const hipDeviceProp_t* prop) {
|
||||
HIP_INIT_API(device, prop);
|
||||
hipDeviceProp_t tempProp;
|
||||
hipError_t e = hipSuccess;
|
||||
if((device == NULL) || (prop == NULL)) {
|
||||
if ((device == NULL) || (prop == NULL)) {
|
||||
e = hipErrorInvalidValue;
|
||||
}
|
||||
if(e == hipSuccess) {
|
||||
if (e == hipSuccess) {
|
||||
int deviceCount;
|
||||
int inPropCount = 0;
|
||||
int matchedPropCount = 0;
|
||||
ihipGetDeviceCount( &deviceCount );
|
||||
ihipGetDeviceCount(&deviceCount);
|
||||
*device = 0;
|
||||
for (int i = 0; i < deviceCount; i++) {
|
||||
ihipGetDeviceProperties( &tempProp, i );
|
||||
if(prop->major != 0) {
|
||||
ihipGetDeviceProperties(&tempProp, i);
|
||||
if (prop->major != 0) {
|
||||
inPropCount++;
|
||||
if(tempProp.major >= prop->major) {
|
||||
if (tempProp.major >= prop->major) {
|
||||
matchedPropCount++;
|
||||
}
|
||||
if(prop->minor != 0) {
|
||||
if (prop->minor != 0) {
|
||||
inPropCount++;
|
||||
if(tempProp.minor >= prop->minor) {
|
||||
if (tempProp.minor >= prop->minor) {
|
||||
matchedPropCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(prop->totalGlobalMem != 0) {
|
||||
if (prop->totalGlobalMem != 0) {
|
||||
inPropCount++;
|
||||
if(tempProp.totalGlobalMem >= prop->totalGlobalMem) {
|
||||
if (tempProp.totalGlobalMem >= prop->totalGlobalMem) {
|
||||
matchedPropCount++;
|
||||
}
|
||||
}
|
||||
if(prop->sharedMemPerBlock != 0) {
|
||||
if (prop->sharedMemPerBlock != 0) {
|
||||
inPropCount++;
|
||||
if(tempProp.sharedMemPerBlock >= prop->sharedMemPerBlock) {
|
||||
if (tempProp.sharedMemPerBlock >= prop->sharedMemPerBlock) {
|
||||
matchedPropCount++;
|
||||
}
|
||||
}
|
||||
if(prop->maxThreadsPerBlock != 0) {
|
||||
if (prop->maxThreadsPerBlock != 0) {
|
||||
inPropCount++;
|
||||
if(tempProp.maxThreadsPerBlock >= prop->maxThreadsPerBlock ) {
|
||||
if (tempProp.maxThreadsPerBlock >= prop->maxThreadsPerBlock) {
|
||||
matchedPropCount++;
|
||||
}
|
||||
}
|
||||
if(prop->totalConstMem != 0) {
|
||||
if (prop->totalConstMem != 0) {
|
||||
inPropCount++;
|
||||
if(tempProp.totalConstMem >= prop->totalConstMem ) {
|
||||
if (tempProp.totalConstMem >= prop->totalConstMem) {
|
||||
matchedPropCount++;
|
||||
}
|
||||
}
|
||||
if(prop->multiProcessorCount != 0) {
|
||||
if (prop->multiProcessorCount != 0) {
|
||||
inPropCount++;
|
||||
if(tempProp.multiProcessorCount >= prop->multiProcessorCount ) {
|
||||
if (tempProp.multiProcessorCount >= prop->multiProcessorCount) {
|
||||
matchedPropCount++;
|
||||
}
|
||||
}
|
||||
if(prop->maxThreadsPerMultiProcessor != 0) {
|
||||
if (prop->maxThreadsPerMultiProcessor != 0) {
|
||||
inPropCount++;
|
||||
if(tempProp.maxThreadsPerMultiProcessor >= prop->maxThreadsPerMultiProcessor ) {
|
||||
if (tempProp.maxThreadsPerMultiProcessor >= prop->maxThreadsPerMultiProcessor) {
|
||||
matchedPropCount++;
|
||||
}
|
||||
}
|
||||
if(prop->memoryClockRate != 0) {
|
||||
if (prop->memoryClockRate != 0) {
|
||||
inPropCount++;
|
||||
if(tempProp.memoryClockRate >= prop->memoryClockRate ) {
|
||||
if (tempProp.memoryClockRate >= prop->memoryClockRate) {
|
||||
matchedPropCount++;
|
||||
}
|
||||
}
|
||||
if(inPropCount == matchedPropCount) {
|
||||
if (inPropCount == matchedPropCount) {
|
||||
*device = i;
|
||||
}
|
||||
#if 0
|
||||
@@ -524,4 +528,3 @@ hipError_t hipChooseDevice( int* device, const hipDeviceProp_t* prop )
|
||||
}
|
||||
return ihipLogStatus(e);
|
||||
}
|
||||
|
||||
|
||||
Fai riferimento in un nuovo problema
Block a user