A minor bug in the acc_malloc() implementation in NVHPC V23.11

OpenACC V2.7 Section 3.2.18 acc_malloc says the following:
(OpenACC V3.3 also contains similar texts.)

In case of an error, acc_malloc returns a NULL pointer.

In the following example, however, acc_malloc() crashes instead of returning a NULL pointer.

#include <openacc.h>
#include <stdio.h>
#include <limits>

int main() {
    void *ptr = nullptr;
    auto alloc_size = std::numeric_limits<size_t>::max() - 42; 
    printf("==> alloc_size = %zu\n", alloc_size);
    ptr = nullptr;
    ptr = acc_malloc(alloc_size);
    if(!ptr) {
        printf("==> acc_malloc(alloc_size) failed!\n");
    } else {
        printf("==> acc_malloc(alloc_size) returns a valid pointer (%zu)\n", ptr);
    }   
    return 0;
}

Thanks Seyong, I’ve reported the issue as TPR #35056.

The error printed is coming from the CUDA runtime. I personally much prefer having the error since it will tell me the issue. If we ignore the error and simply return a NULL, then the user will be missing valuable information about the failure. Though I’ll let engineering decide what’s best.

Hi Seyong,

It turned out that the reason why this was occurring was because the CUDA runtime is returning an ‘invalid value’ error, not ‘out of memory’. We adjusted our error handling to account for this and “acc_malloc” will return NULL in this test case starting with our 24.3 release.

-Mat

1 Like