How to dynamically allocate arrays inside a kernel?

后端 未结 5 1765
耶瑟儿~
耶瑟儿~ 2020-12-13 00:42

I need to dynamically allocate some arrays inside the kernel function. How can a I do that?

My code is something like that:

__global__ func(float *gr         


        
5条回答
  •  情歌与酒
    2020-12-13 01:31

    Maybe you should test

    cudaMalloc(&foo,sizeof(int) * ARRAY_SIZE * ITERATIONS);
    cudaFree(foo);
    

    instead

    for (int i = 0; i < ITERATIONS; ++ i) {
        if (i == 1) cuda_malloc_timer.start(); // let it warm up one cycle
        int * foo;
        cudaMalloc(&foo, sizeof(int) * ARRAY_SIZE);
        cudaFree(foo);
    }
    

提交回复
热议问题