かなり簡単な質問を使用して、私はそれを動作させることはできません。私の主な機能(他のファイルにあります)でCUDA関数の構造体を使用するには?それらをリンクするには?私は、この構造体を持っている...</p> <p>をVS2008
struct Rand48
{
// strided iteration constants (48-bit, distributed on 2x 24-bit)
uint2 A, C;
// CUDA array -- random numbers for all threads
uint2 *state;
// random number for a single thread (used by CUDA device functions only)
uint2 state0;
// magic constants for rand48
static const unsigned long long a = 0x5DEECE66DLL, c = 0xB;
void init(int nThreads, int seed) {
uint2* seeds = new uint2[ nThreads ];
cudaMalloc((void**) &state, sizeof(uint2)*nThreads);
// calculate strided iteration constants
unsigned long long A, C;
A = 1LL; C = 0LL;
for (unsigned int i = 0; i < (unsigned int)nThreads; ++i) {
C += A*c;
A *= a;
}
this->A.x = A & 0xFFFFFFLL;
this->A.y = (A >> 24) & 0xFFFFFFLL;
this->C.x = C & 0xFFFFFFLL;
this->C.y = (C >> 24) & 0xFFFFFFLL;
// prepare first nThreads random numbers from seed
unsigned long long x = (((unsigned long long)seed) << 16) | 0x330E;
for (unsigned int i = 0; i < (unsigned int)nThreads; ++i) {
x = a*x + c;
seeds[i].x = x & 0xFFFFFFLL;
seeds[i].y = (x >> 24) & 0xFFFFFFLL;
}
cudaMemcpy(state, seeds, sizeof(uint2)*nThreads, cudaMemcpyHostToDevice);
delete[] seeds;
}
void destroy() {
cudaFree((void*) state);
}
};
それはcudamallocのようないくつかのCUDA機能、およびいくつかの正常な宿主のCコードを持っています。
どうすればこの作品を作成できますか? Like:
このコードを.cu
ファイルに置くと、VSはnvccを使用してこのコードをコンパイルします。しかし、私はmain.cppファイル(おそらく.cu
を含む)の構造体の宣言を持っていないでしょう。 これを.h
ファイルに置くと、VSはint2
と他のすべてのCUDAのことを宣言していないと不平を言うでしょう。
この構造体はどこに置く必要がありますか?これと私のメインをどのようにリンクさせることができますか?
私のコードがうまく動作するようになった。 'http:// stackoverflow.com/questions/2090974/how-to-separate-cuda-code-into-multiple-files'を使用します。また、私はRand48が使用するすべてを宣言するヘッダーを含め、VSはそれを受け入れました。魅力のように働く。ありがとう。 – hfingler