I am attempting to create a static class that has some constant members. I have created a class that declares a large constant memory pool, and allocates portions of the pool on request. The problem is that my static constant data members are creating the compile-time error, “error C2065: ‘_ZN8RainLoss9jArrayDevE’ : undeclared identifier”. I am wondering why I am getting this error, and how I can go about fixing it. The relavant portion of my code is copied below. Thanks,
-Jeff
typedef unsigned __int8 __uint8;
__constant__ __uint8 memBlock[0xC000]; // Allocate 75% of the constant memory to the heap
// Class that allocates memory off of the heap
class ConstMemory {
private:
static size_t bytesAlloced;
public:
// Allocates memory that is alligned on the specified number of bytes (must be a power of 2)
template<typename T>
static T* Alloc(const size_t bytes, const size_t align = 8) {
ConstMemory::bytesAlloced += align - 1;
ConstMemory::bytesAlloced &= ~(align - 1);
T* rval = reinterpret_cast<T*>(static_cast<__uint8*>(memBlock) + ConstMemory::bytesAlloced);
return ((ConstMemory::bytesAlloced += bytes) > CONST_MEM_POOL_SIZE ? 0 : rval);
}
};
size_t ConstMemory::bytesAlloced(0);
// Class that performs some computations
class RainLoss {
private:
static const __uint8 iCnt = 5, jCnt = 4;
static const float iArrayHost[2][3][RainLoss::iCnt];
static const float jArrayHost[2][3][RainLoss::jCnt];
static float (*iArrayDev)[2][3][RainLoss::iCnt];
static float (*jArrayDev)[2][3][RainLoss::jCnt];
static inline __inline__ __device__ void kappa_alpha(
const float frequency, float &alpha, float &kappa) {
float log10freq = log10f(frequency);
float alphaHV[] = { 0.67849f * log10freq - 1.95537f, -0.053739f * log10freq + 0.83433f};
float kappaHV[] = {-0.18961f * log10freq + 0.71147f, -0.16398f * log10freq + 0.63297f};
kappa = 0;
alpha = 0;
for (__uint8 k = 0; k < 2; ++k) {
for (__uint8 i = 0; i < RainLoss::iCnt; ++i) {
// This line throws the specified error for each instance of RainLoss::iArrayDev
alphaHV[k] += (*RainLoss::iArrayDev)[k][0][i] * expf(-pow2((log10freq -
(*RainLoss::iArrayDev)[k][1][i]) / (*RainLoss::iArrayDev)[k][2][i]));
}
for (__uint8 j = 0; j < RainLoss::jCnt; ++j) {
// This line throws the specified error for each instance of RainLoss::jArrayDev
kappaHV[k] += (*RainLoss::jArrayDev)[k][0][j] * expf(-pow2((log10freq -
(*RainLoss::jArrayDev)[k][1][j]) / (*RainLoss::jArrayDev)[k][2][j]));
}
kappaHV[k] = powf(10, kappaHV[k]);
kappa += kappaHV[k];
alpha += kappaHV[k] * alphaHV[k];
}
alpha /= kappa;
kappa *= 0.5;
}
public:
static inline void InitializeCUDA() {
// I realize that the number of bytes passed into the Alloc and cudaMemcpy methods may be wrong...
// I was going to look at it in debug mode to see what size I actually need to pass in
RainLoss::iArrayDev = ConstMemory::Alloc<float[2][3][RainLoss::iCnt]>(sizeof(RainLoss::iArrayHost));
RainLoss::jArrayDev = ConstMemory::Alloc<float[2][3][RainLoss::jCnt]>(sizeof(RainLoss::jArrayHost));
cutilSafeCall(cudaMemcpy(RainLoss::iArrayDev, RainLoss::iArrayHost,
sizeof(RainLoss::iArrayHost), cudaMemcpyHostToDevice));
cutilSafeCall(cudaMemcpy(RainLoss::jArrayDev, RainLoss::jArrayHost,
sizeof(RainLoss::jArrayHost), cudaMemcpyHostToDevice));
}
};
const float RainLoss::iArrayHost[][3][RainLoss::iCnt] =
{{{-0.14318f, 0.29591f, 0.32177f, -5.3761f , 16.1721f } ,
{ 1.82442f, 0.77564f, 0.63773f, -0.9623f , -3.2998f } ,
{-0.55187f, 0.19822f, 0.13164f, 1.47828f , 3.4399f }} ,
{{-0.07771f, 0.56727f, -0.20238f, -48.2991f , 48.5833f } ,
{ 2.3384f , 0.95545f, 1.1452f , 0.791669f, 0.791459f} ,
{-0.76284f, 0.54039f, 0.26809f, 0.116226f, 0.116479f}}};
// Similar definition for jArrayHost