2016-03-24 07:04:01 -05:00
|
|
|
/*
|
|
|
|
|
Copyright (c) 2015-2016 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 WARRANNTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
IMPLIED, INNCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
FITNNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANNY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
LIABILITY, WHETHER INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
|
THE SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
2016-03-24 04:57:30 -05:00
|
|
|
#include "hip_runtime.h"
|
|
|
|
|
#include "hcc_detail/hip_hcc.h"
|
|
|
|
|
#include "hcc_detail/trace_helper.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();
|
|
|
|
|
|
|
|
|
|
if (ctx == nullptr) {
|
|
|
|
|
e = hipErrorInvalidDevice; // TODO, check error code.
|
|
|
|
|
*deviceId = -1;
|
|
|
|
|
} else {
|
|
|
|
|
*deviceId = ctx->getDevice()->_deviceId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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-03-24 09:28:46 -05:00
|
|
|
hipError_t hipGetDeviceCount(int *count)
|
|
|
|
|
{
|
|
|
|
|
HIP_INIT_API(count);
|
|
|
|
|
|
|
|
|
|
*count = g_deviceCnt;
|
|
|
|
|
|
|
|
|
|
if (*count > 0) {
|
|
|
|
|
return ihipLogStatus(hipSuccess);
|
|
|
|
|
} else {
|
|
|
|
|
return ihipLogStatus(hipErrorNoDevice);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipDeviceSetCacheConfig ( hipFuncCache cacheConfig )
|
|
|
|
|
{
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipDeviceGetCacheConfig ( hipFuncCache *cacheConfig )
|
|
|
|
|
{
|
2016-07-22 15:46:55 +05:30
|
|
|
HIP_INIT_API(cacheConfig);
|
2016-03-24 09:28:46 -05:00
|
|
|
|
|
|
|
|
*cacheConfig = hipFuncCachePreferNone;
|
|
|
|
|
|
|
|
|
|
return ihipLogStatus(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipFuncSetCacheConfig ( hipFuncCache cacheConfig )
|
|
|
|
|
{
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipDeviceSetSharedMemConfig ( hipSharedMemConfig config )
|
|
|
|
|
{
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipDeviceGetSharedMemConfig ( hipSharedMemConfig * pConfig )
|
|
|
|
|
{
|
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.
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ihipLogStatus(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipDeviceGetAttribute(int* pi, hipDeviceAttribute_t attr, int device)
|
|
|
|
|
{
|
2016-07-27 16:18:14 -05:00
|
|
|
HIP_INIT_API(pi, attr, device);
|
2016-03-24 09:28:46 -05:00
|
|
|
|
|
|
|
|
hipError_t e = hipSuccess;
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
return ihipLogStatus(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipGetDeviceProperties(hipDeviceProp_t* props, int device)
|
|
|
|
|
{
|
|
|
|
|
HIP_INIT_API(props, device);
|
|
|
|
|
|
|
|
|
|
hipError_t e;
|
|
|
|
|
|
2016-08-07 21:46:51 -05:00
|
|
|
auto * hipDevice = ihipGetDevice(device);
|
2016-03-24 09:28:46 -05:00
|
|
|
if (hipDevice) {
|
|
|
|
|
// copy saved props
|
|
|
|
|
*props = hipDevice->_props;
|
|
|
|
|
e = hipSuccess;
|
|
|
|
|
} else {
|
|
|
|
|
e = hipErrorInvalidDevice;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ihipLogStatus(e);
|
|
|
|
|
}
|
2016-03-24 04:57:30 -05:00
|
|
|
|
2016-03-24 07:04:01 -05:00
|
|
|
hipError_t hipSetDeviceFlags( unsigned int flags)
|
|
|
|
|
{
|
|
|
|
|
HIP_INIT_API(flags);
|
|
|
|
|
|
|
|
|
|
hipError_t e;
|
|
|
|
|
|
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) {
|
|
|
|
|
ctx->_ctxFlags = ctx->_ctxFlags | flags;
|
2016-03-24 07:04:01 -05:00
|
|
|
e = hipSuccess;
|
2016-08-08 11:55:57 -05:00
|
|
|
} else {
|
2016-03-24 07:04:01 -05:00
|
|
|
e = hipErrorInvalidDevice;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ihipLogStatus(e);
|
2016-08-08 11:55:57 -05:00
|
|
|
};
|
2016-03-24 07:04:01 -05:00
|
|
|
|
2016-08-09 15:37:19 -05:00
|
|
|
hipError_t hipDeviceGetFromId(hipDevice_t *device, int deviceId)
|
|
|
|
|
{
|
|
|
|
|
HIP_INIT_API(device, deviceId);
|
|
|
|
|
|
|
|
|
|
hipError_t e = hipSuccess;
|
|
|
|
|
|
|
|
|
|
*device = ihipGetDevice(deviceId);
|
|
|
|
|
|
|
|
|
|
if (device == nullptr) {
|
|
|
|
|
e = hipErrorInvalidDevice;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ihipLogStatus(e);
|
|
|
|
|
}
|
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;
|
|
|
|
|
int deviceId= device->_deviceId;
|
|
|
|
|
e = hipDeviceGetAttribute(major, hipDeviceAttributeComputeCapabilityMajor, deviceId);
|
|
|
|
|
e = hipDeviceGetAttribute(minor, hipDeviceAttributeComputeCapabilityMinor, deviceId);
|
|
|
|
|
return ihipLogStatus(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipDeviceGetName(char *name,int len,hipDevice_t device)
|
|
|
|
|
{
|
|
|
|
|
HIP_INIT_API(name,len, device);
|
|
|
|
|
hipError_t e = hipSuccess;
|
|
|
|
|
int nameLen = strlen(device->_props.name);
|
|
|
|
|
if(nameLen <= len)
|
|
|
|
|
memcpy(name,device->_props.name,nameLen);
|
|
|
|
|
return ihipLogStatus(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipDeviceGetPCIBusId (int *pciBusId,int len,hipDevice_t device)
|
|
|
|
|
{
|
|
|
|
|
HIP_INIT_API(pciBusId,len, device);
|
|
|
|
|
hipError_t e = hipSuccess;
|
|
|
|
|
int deviceId= device->_deviceId;
|
|
|
|
|
e = hipDeviceGetAttribute(pciBusId, hipDeviceAttributePciBusId, deviceId);
|
|
|
|
|
return ihipLogStatus(e);
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
*bytes= device->_props.totalGlobalMem;
|
|
|
|
|
return ihipLogStatus(e);
|
|
|
|
|
}
|
2016-09-08 22:37:24 +05:30
|
|
|
|
|
|
|
|
hipError_t hipChooseDevice( int* device, const hipDeviceProp_t* prop )
|
|
|
|
|
{
|
|
|
|
|
hipDeviceProp_t tempProp;
|
|
|
|
|
int deviceCount;
|
|
|
|
|
int inPropCount=0;
|
|
|
|
|
int matchedPropCount=0;
|
|
|
|
|
hipError_t e = hipSuccess;
|
|
|
|
|
hipGetDeviceCount( &deviceCount );
|
|
|
|
|
*device = 0;
|
|
|
|
|
for (int i=0; i< deviceCount; i++) {
|
|
|
|
|
hipGetDeviceProperties( &tempProp, i );
|
|
|
|
|
if(prop->major !=0) {
|
|
|
|
|
inPropCount++;
|
|
|
|
|
if(tempProp.major >= prop->major) {
|
|
|
|
|
matchedPropCount++;
|
|
|
|
|
}
|
|
|
|
|
if(prop->minor !=0) {
|
|
|
|
|
inPropCount++;
|
|
|
|
|
if(tempProp.minor >= prop->minor) {
|
|
|
|
|
matchedPropCount++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(inPropCount == matchedPropCount) {
|
|
|
|
|
*device = i;
|
|
|
|
|
}
|
|
|
|
|
#if 0
|
|
|
|
|
else{
|
|
|
|
|
e= hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
return ihipLogStatus(e);
|
|
|
|
|
}
|
|
|
|
|
|