Search code examples
cudaconstantsnvidia

Why I am getting "dynamic initialization is not supported for a __constant__ variable"?


I have the following structs:

enum BoundSide { right, left, top, bottom, back, front };

template<typename T, size_t D>
using vec = array<T,D>;

//fpr short and static Vector Fields like c_i
template<typename T, size_t D, size_t Q>
using vec_set = vec<vec<T, D>, Q>;

template<typename T, size_t D>
struct VELOCITY_BOUND_DEV;

template<typename T>
struct VELOCITY_BOUND_DEV<T, 2>
{
  BoundSide side;
  int center{};
  int width{};
  T u_w;        //velocity
};


template<typename T, int D, int Q>
struct SimDomain_dev 
{
  vec_set<T, D, Q> c;       //discrete velocity-set
  vec<T, Q> w;          //discrete weights
  vec<grid_size_t, D> gridDim_L;

  VELOCITY_BOUND_DEV<T, D> bound;
}

I declared a __constant__ variable like this:

template<typename T, int D, int Q>
__constant__ SimDomain_dev<T, D, Q> sd_dev;

and I copy the data form a temporal host variable to the device variable like this:

 cudaMemcpyToSymbol(sd_dev<T, D, SimDomain<T, D>::Q>, &sd_temp,0, sizeof(SimDomain_dev<T,D, SimDomain<T, D>::Q>))

The Class array in vec and vec_set is a container-class which works on the device side (that works).

So, why I'm getting the error "dynamic initialization is not supported for a __constant__ variable"?


Solution

  • int center{};
    int width{};
    

    Initialize center and width, also, depending on how vec and vec_set are defined, they may have constructors of their own.