operator new in CUDA is always a __host__ __device__ function

  allocation, c++, cuda, overriding

I’m trying to use tracy (https://github.com/wolfpld/tracy) with CUDA
With tracy, to measure memory usage you override operator new and operator delete like this:

void* operator new(std::size_t count) {
    auto ptr = malloc(count);
    TracyAlloc(ptr, count);
    return ptr;
}

void operator delete(void* ptr) noexcept {
    TracyFree(ptr);
    free(ptr);
}

But when trying to use these with CUDA code (not inside a kernel but just in host code) I get these compiler warnings:

/home/protobit/primer/main.cu(12): warning: calling a __host__ function("tracy::GetThreadHandle") from a __host__ __device__ function("operator new ") is not allowed

/home/protobit/primer/main.cu(12): warning: calling a __host__ function("tracy::GetProfiler") from a __host__ __device__ function("operator new ") is not allowed

(there are quite a lot more so here’s a link to them: pastebin)

I’ve tried fixing this by defining the operator new and operator delete functions with __host__ but that didn’t help

I’m guessing that in CUDA they are defined with __host__ __device__

Is there any way to fix this?
Thanks in advance 🙂

EDIT 1:

Here’s a link to the GitHub repo: https://github.com/ProtoByter/primer

Source: Windows Questions C++

LEAVE A COMMENT