MCPcopy Create free account
hub / github.com/QuEST-Kit/QuEST / gpu_allocArray

Function gpu_allocArray

quest/src/gpu/gpu_config.cpp:437–466  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

435
436
437qcomp* gpu_allocArray(qindex length) {
438#if COMPILE_CUDA
439
440 size_t numBytes = mem_getLocalQuregMemoryRequired(length);
441
442 // attempt to malloc
443 qcomp* ptr;
444 cudaError_t errCode = cudaMalloc(&ptr, numBytes);
445
446 // intercept memory-alloc error (handled by caller's validation)
447 if (errCode == cudaErrorMemoryAllocation) {
448
449 // malloc failure can break CUDA API state, so recover it in
450 // case execution is continuing (e.g. by unit tests)
451 clearPossibleCudaError();
452
453 // indicate alloc failure
454 return nullptr;
455 }
456
457 // pass all other unexpected errors to internal error handling
458 CUDA_CHECK(errCode);
459
460 return ptr;
461
462#else
463 error_gpuAllocButGpuNotCompiled();
464 return nullptr;
465#endif
466}
467
468
469void gpu_deallocArray(qcomp* amps) {

Tested by

no test coverage detected