@@ -25,23 +25,22 @@ extern "C" {
2525void *RTDEF (CUFMemAlloc)(
2626 std::size_t bytes, unsigned type, const char *sourceFile, int sourceLine) {
2727 void *ptr = nullptr ;
28- if (bytes != 0 ) {
29- if (type == kMemTypeDevice ) {
30- if (Fortran::runtime::executionEnvironment.cudaDeviceIsManaged ) {
31- CUDA_REPORT_IF_ERROR (
32- cudaMallocManaged ((void **)&ptr, bytes, cudaMemAttachGlobal));
33- } else {
34- CUDA_REPORT_IF_ERROR (cudaMalloc ((void **)&ptr, bytes));
35- }
36- } else if (type == kMemTypeManaged || type == kMemTypeUnified ) {
28+ bytes = bytes ? bytes : 1 ;
29+ if (type == kMemTypeDevice ) {
30+ if (Fortran::runtime::executionEnvironment.cudaDeviceIsManaged ) {
3731 CUDA_REPORT_IF_ERROR (
3832 cudaMallocManaged ((void **)&ptr, bytes, cudaMemAttachGlobal));
39- } else if (type == kMemTypePinned ) {
40- CUDA_REPORT_IF_ERROR (cudaMallocHost ((void **)&ptr, bytes));
4133 } else {
42- Terminator terminator{sourceFile, sourceLine};
43- terminator.Crash (" unsupported memory type" );
34+ CUDA_REPORT_IF_ERROR (cudaMalloc ((void **)&ptr, bytes));
4435 }
36+ } else if (type == kMemTypeManaged || type == kMemTypeUnified ) {
37+ CUDA_REPORT_IF_ERROR (
38+ cudaMallocManaged ((void **)&ptr, bytes, cudaMemAttachGlobal));
39+ } else if (type == kMemTypePinned ) {
40+ CUDA_REPORT_IF_ERROR (cudaMallocHost ((void **)&ptr, bytes));
41+ } else {
42+ Terminator terminator{sourceFile, sourceLine};
43+ terminator.Crash (" unsupported memory type" );
4544 }
4645 return ptr;
4746}
0 commit comments