Can we move data from global to constant memory in host function?

Hi! Previously one expert in this forum told me can not use “device function” to move data from global memory to constant memory. And now I am wondering, can we use “host function” to somehow achieve that??

Thank you!!!

I tired this guy’s idea, and failed…

It seems to work for me:

$ cat
#include <cstdio>

__constant__ float f = 0.0f;

__global__ void k(){

  printf("%f\n", f);


int main(){

  float *d_f, *h_f = new float(1.234f);
  cudaMalloc(&d_f, sizeof(float));
  cudaMemcpy(d_f, h_f, sizeof(float), cudaMemcpyHostToDevice);
  cudaMemcpyToSymbol(f, d_f, sizeof(float), 0, cudaMemcpyDeviceToDevice);
$ nvcc -o t2081
$ compute-sanitizer ./t2081
========= ERROR SUMMARY: 0 errors

CUDA 11.4, V100, CentOS7


Thank you!! It works!!!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.