MCPcopy Create free account
hub / github.com/NVIDIA/cuda-samples / initCUDA

Function initCUDA

cpp/0_Introduction/simpleTextureDrv/simpleTextureDrv.cpp:311–352  ·  view source on GitHub ↗

/////////////////////////////////////////////////////////////////////////// This initializes CUDA, and loads the *.ptx CUDA module containing the kernel function. After the module is loaded, cuModuleGetFunction retrieves the CUDA function pointer "cuFunction" ///////////////////////////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

309//! retrieves the CUDA function pointer "cuFunction"
310////////////////////////////////////////////////////////////////////////////////
311static CUresult initCUDA(int argc, char **argv, CUfunction *transform)
312{
313 CUfunction cuFunction = 0;
314 int major = 0, minor = 0, devID = 0;
315 char deviceName[100];
316 string module_path;
317 CUctxCreateParams ctxCreateParams = {};
318
319 cuDevice = findCudaDeviceDRV(argc, (const char **)argv);
320
321 // get compute capabilities and the devicename
322 checkCudaErrors(cuDeviceGetAttribute(&major, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, cuDevice));
323 checkCudaErrors(cuDeviceGetAttribute(&minor, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR, cuDevice));
324 checkCudaErrors(cuDeviceGetName(deviceName, sizeof(deviceName), cuDevice));
325 printf("> GPU Device has SM %d.%d compute capability\n", major, minor);
326
327 checkCudaErrors(cuCtxCreate(&cuContext, &ctxCreateParams, 0, cuDevice));
328
329 // first search for the module_path before we try to load the results
330 std::ostringstream fatbin;
331
332 if (!findFatbinPath(FATBIN_FILE, module_path, argv, fatbin)) {
333 exit(EXIT_FAILURE);
334 }
335 else {
336 printf("> initCUDA loading module: <%s>\n", module_path.c_str());
337 }
338
339 if (!fatbin.str().size()) {
340 printf("fatbin file empty. exiting..\n");
341 exit(EXIT_FAILURE);
342 }
343
344 // Create module from binary file (FATBIN)
345 checkCudaErrors(cuModuleLoadData(&cuModule, fatbin.str().c_str()));
346
347 checkCudaErrors(cuModuleGetFunction(&cuFunction, cuModule, "transformKernel"));
348
349 *transform = cuFunction;
350
351 return CUDA_SUCCESS;
352}

Callers 1

runTestFunction · 0.70

Calls 3

findFatbinPathFunction · 0.85
findCudaDeviceDRVFunction · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected