Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Please explain cudaMemcpyToSymbol example code from CUDA Programming Guide

Tags:

cuda

Is there a problem in this example code from the CUDA C Programming Guide?

__device__ float devData;
float value = 3.14f;
cudaMemcpyToSymbol(devData, &value, sizeof(float));

I can't understand how it could write to devData without having the address of devData

like image 649
necromancer Avatar asked Nov 21 '11 07:11

necromancer


People also ask

What is the correct order of CUDA program processing?

In a typical CUDA program, data are first send from main memory to the GPU memory, then the CPU sends instructions to the GPU, then the GPU schedules and executes the kernel on the available parallel hardware, and finally results are copied back from the GPU memory to the CPU memory. ...

What is CUDA in programming?

CUDA (or Compute Unified Device Architecture) is a parallel computing platform and application programming interface (API) that allows software to use certain types of graphics processing units (GPUs) for general purpose processing, an approach called general-purpose computing on GPUs (GPGPU).

Is CUDA same as C?

CUDA C is essentially C/C++ with a few extensions that allow one to execute functions on the GPU using many threads in parallel.


1 Answers

Actually it seems that cudaMemcpyToSymbol has another signature.

http://cudpp.googlecode.com/svn-history/r152/trunk/common/inc/dynlink/cuda_runtime_dynlink.h

template<class T>
__inline__ __host__ cudaError_t cudaMemcpyToSymbol(
  const T                   &symbol,
  const void                *src,
        size_t               count,
        size_t               offset = 0,
        enum cudaMemcpyKind  kind   = cudaMemcpyHostToDevice
)
{
  return cudaMemcpyToSymbol((const char*)&symbol, src, count, offset, kind);
}

This one would match your case.

like image 75
kyohiro Avatar answered Sep 18 '22 15:09

kyohiro