| 435 | |
| 436 | |
| 437 | qcomp* 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 | |
| 469 | void gpu_deallocArray(qcomp* amps) { |
no test coverage detected