cudaMemset fails on __device__ variable

后端 未结 2 568
北荒
北荒 2021-01-25 04:51

I am having trouble using cudaMemset on a device variable. Is it possible to use the reference to the device variable for cudaMemset, or is it just a m

2条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-25 05:12

    I believe you can also use cudaMemcpyFromSymbol: A function, such as the following kernel, can change the value of the variable declared in global memory (outside of the main function)

    __global__ void kernel1() { d_test = 1.0; }
    

    Inside your main, you can obtain the value using cudaMemcpyFromSymbol

    cudaMemcpyFromSymbol(&h_test,"d_test",sizeof(float),0,cudaMemcpyDeviceToHost);
    

    Of course, there is also cudaMemcpyToSymbol to change the value of the global variable.

    The idea came from here: Having problem assigning a device variable in CUDA

提交回复
热议问题