Implementation of hipDeviceGetAttribute()

This commit is contained in:
Sam Kolton
2016-02-04 17:39:07 +03:00
committed by Nikolay Haustov
parent 1327d3e03d
commit 0a27507208
7 changed files with 243 additions and 2 deletions
+7
View File
@@ -232,6 +232,13 @@ hipError_t hipGetDevice(int *device);
*/
hipError_t hipGetDeviceCount(int *count);
/**
* @brief Query device attribute.
* @param [out] pi pointer to value to return
* @param [in] attr attribute to query
* @param [in] device which device to query for information
*/
hipError_t hipDeviceGetAttribute(int* pi, hipDeviceAttribute_t attr, int device);
/**
* @brief Returns device properties.
+25 -1
View File
@@ -125,7 +125,31 @@ typedef enum hipError_t {
,hipErrorTbd ///< Marker that more error codes are needed.
} hipError_t;
/*
* @brief hipDeviceAttribute_t
* @enum
* @ingroup Enumerations
*/
typedef enum hipDeviceAttribute_t {
hipDeviceAttributeMaxThreadsPerBlock, ///< Maximum number of threads per block.
hipDeviceAttributeMaxBlockDimX, ///< Maximum x-dimension of a block.
hipDeviceAttributeMaxBlockDimY, ///< Maximum y-dimension of a block.
hipDeviceAttributeMaxBlockDimZ, ///< Maximum z-dimension of a block.
hipDeviceAttributeMaxGridDimX, ///< Maximum x-dimension of a grid.
hipDeviceAttributeMaxGridDimY, ///< Maximum y-dimension of a grid.
hipDeviceAttributeMaxGridDimZ, ///< Maximum z-dimension of a grid.
hipDeviceAttributeMaxSharedMemoryPerBlock, ///< Maximum shared memory available per block in bytes.
hipDeviceAttributeTotalConstantMemory, ///< Constant memory size in bytes.
hipDeviceAttributeWarpSize, ///< Warp size in threads.
hipDeviceAttributeMaxRegistersPerBlock, ///< Maximum number of 32-bit registers available to a thread block. This number is shared by all thread blocks simultaneously resident on a multiprocessor.
hipDeviceAttributeClockRate, ///< Peak clock frequency in kilohertz.
hipDeviceAttributeMultiprocessorCount, ///< Number of multiprocessors on the device.
hipDeviceAttributeComputeMode, ///< Compute mode that device is currently in.
hipDeviceAttributeL2CacheSize, ///< Size of L2 cache in bytes. 0 if the device doesn't have L2 cache.
hipDeviceAttributeMaxThreadsPerMultiProcessor, ///< Maximum resident threads per multiprocessor.
hipDeviceAttributeComputeCapabilityMajor, ///< Major compute capability version number.
hipDeviceAttributeComputeCapabilityMinor, ///< Minor compute capability version number.
} hipDeviceAttribute_t;
/**
* @}
+51
View File
@@ -211,6 +211,57 @@ inline static hipError_t hipDeviceGetProperties(hipDeviceProp_t *p_prop, int dev
return hipCUDAErrorTohipError(cerror);
}
inline static hipError_t hipDeviceGetAttribute(int* pi, hipDeviceAttribute_t attr, int device)
{
cudaDeviceAttribute cdattr;
cudaError_t cerror;
switch (attr) {
case hipDeviceAttributeMaxThreadsPerBlock:
cdattr = cudaDevAttrMaxThreadsPerBlock; break;
case hipDeviceAttributeMaxBlockDimX:
cdattr = cudaDevAttrMaxBlockDimX; break;
case hipDeviceAttributeMaxBlockDimY:
cdattr = cudaDevAttrMaxBlockDimY; break;
case hipDeviceAttributeMaxBlockDimZ:
cdattr = cudaDevAttrMaxBlockDimZ; break;
case hipDeviceAttributeMaxGridDimX:
cdattr = cudaDevAttrMaxGridDimX; break;
case hipDeviceAttributeMaxGridDimY:
cdattr = cudaDevAttrMaxGridDimY; break;
case hipDeviceAttributeMaxGridDimZ:
cdattr = cudaDevAttrMaxGridDimZ; break;
case hipDeviceAttributeMaxSharedMemoryPerBlock:
cdattr = cudaDevAttrMaxSharedMemoryPerBlock; break;
case hipDeviceAttributeTotalConstantMemory:
cdattr = cudaDevAttrTotalConstantMemory; break;
case hipDeviceAttributeWarpSize:
cdattr = cudaDevAttrWarpSize; break;
case hipDeviceAttributeMaxRegistersPerBlock:
cdattr = cudaDevAttrMaxRegistersPerBlock; break;
case hipDeviceAttributeClockRate:
cdattr = cudaDevAttrClockRate; break;
case hipDeviceAttributeMultiprocessorCount:
cdattr = cudaDevAttrMultiProcessorCount; break;
case hipDeviceAttributeComputeMode:
cdattr = cudaDevAttrComputeMode; break;
case hipDeviceAttributeL2CacheSize:
cdattr = cudaDevAttrL2CacheSize; break;
case hipDeviceAttributeMaxThreadsPerMultiProcessor:
cdattr = cudaDevAttrMaxThreadsPerMultiProcessor; break;
case hipDeviceAttributeComputeCapabilityMajor:
cdattr = cudaDevAttrComputeCapabilityMajor; break;
case hipDeviceAttributeComputeCapabilityMinor:
cdattr = cudaDevAttrComputeCapabilityMinor; break;
default:
e = hipErrorInvalidValue; break;
}
cerror = cudaDeviceGetAttribute(pi, cdattr, device);
return hipCUDAErrorTohipError(cerror);
}
inline static hipError_t hipMemGetInfo( size_t* free, size_t* total)
{
return hipCUDAErrorTohipError(cudaMemGetInfo(free,total));