mirror of
https://github.com/NVIDIA/cuda-samples.git
synced 2025-09-13 20:22:28 +08:00
fixed formatting
This commit is contained in:
parent
6df7127c23
commit
b4aaab387e
@ -248,8 +248,8 @@ static CUresult LOAD_LIBRARY(CUDADRIVER *pInstance)
|
|||||||
return CUDA_SUCCESS;
|
return CUDA_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
CUresult GET_DRIVER_HANDLE(CUDADRIVER* pInstance)
|
CUresult GET_DRIVER_HANDLE(CUDADRIVER *pInstance)
|
||||||
{
|
{
|
||||||
*pInstance = GetModuleHandle(__CudaLibName);
|
*pInstance = GetModuleHandle(__CudaLibName);
|
||||||
if (*pInstance) {
|
if (*pInstance) {
|
||||||
return CUDA_SUCCESS;
|
return CUDA_SUCCESS;
|
||||||
@ -280,12 +280,12 @@ CUresult GET_DRIVER_HANDLE(CUDADRIVER* pInstance)
|
|||||||
return CUDA_ERROR_UNKNOWN; \
|
return CUDA_ERROR_UNKNOWN; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define GET_PROC_ERROR_FUNCTIONS(name, alias, required) \
|
#define GET_PROC_ERROR_FUNCTIONS(name, alias, required) \
|
||||||
alias = (t##name *)GetProcAddress(CudaDrvLib, #name); \
|
alias = (t##name *)GetProcAddress(CudaDrvLib, #name); \
|
||||||
if (alias == NULL && required) { \
|
if (alias == NULL && required) { \
|
||||||
printf("Failed to find error function \"%s\" in %s\n", #name, __CudaLibName); \
|
printf("Failed to find error function \"%s\" in %s\n", #name, __CudaLibName); \
|
||||||
exit(EXIT_FAILURE); \
|
exit(EXIT_FAILURE); \
|
||||||
} \
|
}
|
||||||
|
|
||||||
#elif defined(__unix__) || defined(__QNX__) || defined(__APPLE__) || defined(__MACOSX)
|
#elif defined(__unix__) || defined(__QNX__) || defined(__APPLE__) || defined(__MACOSX)
|
||||||
|
|
||||||
@ -317,8 +317,8 @@ static CUresult LOAD_LIBRARY(CUDADRIVER *pInstance)
|
|||||||
return CUDA_SUCCESS;
|
return CUDA_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
CUresult GET_DRIVER_HANDLE(CUDADRIVER* pInstance)
|
CUresult GET_DRIVER_HANDLE(CUDADRIVER *pInstance)
|
||||||
{
|
{
|
||||||
*pInstance = dlopen(__CudaLibName, RTLD_LAZY);
|
*pInstance = dlopen(__CudaLibName, RTLD_LAZY);
|
||||||
if (*pInstance) {
|
if (*pInstance) {
|
||||||
return CUDA_SUCCESS;
|
return CUDA_SUCCESS;
|
||||||
@ -349,23 +349,23 @@ CUresult GET_DRIVER_HANDLE(CUDADRIVER* pInstance)
|
|||||||
return CUDA_ERROR_UNKNOWN; \
|
return CUDA_ERROR_UNKNOWN; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define GET_PROC_ERROR_FUNCTIONS(name, alias, required) \
|
#define GET_PROC_ERROR_FUNCTIONS(name, alias, required) \
|
||||||
alias = (t##name *)dlsym(CudaDrvLib, #name); \
|
alias = (t##name *)dlsym(CudaDrvLib, #name); \
|
||||||
if (alias == NULL && required) { \
|
if (alias == NULL && required) { \
|
||||||
printf("Failed to find error function \"%s\" in %s\n", #name, __CudaLibName); \
|
printf("Failed to find error function \"%s\" in %s\n", #name, __CudaLibName); \
|
||||||
exit(EXIT_FAILURE); \
|
exit(EXIT_FAILURE); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#error unsupported platform
|
#error unsupported platform
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define CHECKED_CALL(call) \
|
#define CHECKED_CALL(call) \
|
||||||
do { \
|
do { \
|
||||||
CUresult result = (call); \
|
CUresult result = (call); \
|
||||||
if (CUDA_SUCCESS != result) { \
|
if (CUDA_SUCCESS != result) { \
|
||||||
return result; \
|
return result; \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define GET_PROC_REQUIRED(name) GET_PROC_EX(name, name, 1)
|
#define GET_PROC_REQUIRED(name) GET_PROC_EX(name, name, 1)
|
||||||
@ -377,8 +377,8 @@ CUresult GET_DRIVER_HANDLE(CUDADRIVER* pInstance)
|
|||||||
CUresult INIT_ERROR_FUNCTIONS(void)
|
CUresult INIT_ERROR_FUNCTIONS(void)
|
||||||
{
|
{
|
||||||
CUDADRIVER CudaDrvLib;
|
CUDADRIVER CudaDrvLib;
|
||||||
CUresult result = CUDA_SUCCESS;
|
CUresult result = CUDA_SUCCESS;
|
||||||
result = GET_DRIVER_HANDLE(&CudaDrvLib);
|
result = GET_DRIVER_HANDLE(&CudaDrvLib);
|
||||||
GET_PROC_ERROR_FUNCTIONS(cuGetErrorString, cuGetErrorString, 1);
|
GET_PROC_ERROR_FUNCTIONS(cuGetErrorString, cuGetErrorString, 1);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -387,7 +387,7 @@ CUresult CUDAAPI cuInit(unsigned int Flags, int cudaVersion)
|
|||||||
{
|
{
|
||||||
CUDADRIVER CudaDrvLib;
|
CUDADRIVER CudaDrvLib;
|
||||||
int driverVer = 1000;
|
int driverVer = 1000;
|
||||||
|
|
||||||
CHECKED_CALL(LOAD_LIBRARY(&CudaDrvLib));
|
CHECKED_CALL(LOAD_LIBRARY(&CudaDrvLib));
|
||||||
|
|
||||||
// cuInit is required; alias it to _cuInit
|
// cuInit is required; alias it to _cuInit
|
||||||
@ -400,7 +400,7 @@ CUresult CUDAAPI cuInit(unsigned int Flags, int cudaVersion)
|
|||||||
if (cuDriverGetVersion) {
|
if (cuDriverGetVersion) {
|
||||||
CHECKED_CALL(cuDriverGetVersion(&driverVer));
|
CHECKED_CALL(cuDriverGetVersion(&driverVer));
|
||||||
}
|
}
|
||||||
|
|
||||||
// fetch all function pointers
|
// fetch all function pointers
|
||||||
GET_PROC(cuDeviceGet);
|
GET_PROC(cuDeviceGet);
|
||||||
GET_PROC(cuDeviceGetCount);
|
GET_PROC(cuDeviceGetCount);
|
||||||
|
@ -49,7 +49,7 @@ inline void __checkCudaErrors(CUresult err, const char *file, const int line)
|
|||||||
{
|
{
|
||||||
if (CUDA_SUCCESS != err) {
|
if (CUDA_SUCCESS != err) {
|
||||||
const char *errorStr = NULL;
|
const char *errorStr = NULL;
|
||||||
|
|
||||||
if (!cuGetErrorString) {
|
if (!cuGetErrorString) {
|
||||||
CUresult result = INIT_ERROR_FUNCTIONS();
|
CUresult result = INIT_ERROR_FUNCTIONS();
|
||||||
if (result != CUDA_SUCCESS) {
|
if (result != CUDA_SUCCESS) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user