necromancer
necromancer

Reputation: 24641

Please explain cudaMemcpyToSymbol example code from CUDA Programming Guide

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

Upvotes: 9

Views: 7043

Answers (1)

kyohiro
kyohiro

Reputation: 322

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.

Upvotes: 7

Related Questions