Actually I want to use CudaMemPool on host to use pinned memory of host like cudaHostAlloc but somehow cudaMemPool is not supported for hostMemPool in 12.3. Is There any way to support of cudaMemPool on host in later cuda Version.
The following code works with cuda 12.4. Create a custom pool which allocates on the host and allows access from both host and device.
#include <iostream>
__global__
void kernel(int* ptr){
*ptr = 42;
}
int main(){
cudaMemPool_t memPool;
cudaMemPoolProps poolProps; memset(&poolProps, 0, sizeof(cudaMemPoolProps));
poolProps.allocType = cudaMemAllocationTypePinned; //cannot migrate between locations
poolProps.handleTypes = cudaMemHandleTypeNone; //does not support IPC
poolProps.location.id = 0;
poolProps.location.type = cudaMemLocationTypeHostNuma; //memory will be allocated on NUMA node 0
cudaMemPoolCreate(&memPool, &poolProps);
cudaMemAccessDesc descList[2];
//allow access from NUMA node 0
descList[0].flags = cudaMemAccessFlagsProtReadWrite;
descList[0].location.id = 0;
descList[0].location.type = cudaMemLocationTypeHostNuma;
//allow access from device 0
descList[1].flags = cudaMemAccessFlagsProtReadWrite;
descList[1].location.id = 0;
descList[1].location.type = cudaMemLocationTypeDevice;
cudaMemPoolSetAccess(memPool, &descList[0], 2);
cudaStream_t stream = cudaStreamLegacy;
int* ptr;
cudaMallocFromPoolAsync(&ptr, sizeof(int), memPool, stream);
kernel<<<1,1,0,stream>>>(ptr);
cudaStreamSynchronize(stream);
std::cout << *ptr << "\n";
cudaMemPoolDestroy(memPool);
}
1 Like
Hi Actually i’m getting issue
freeMmemory: 23368695808, Total Memory: 23570219008
cudaMemPoolCreate True: out of memory.
Can you please help me to find out the issue and fix to this issue