構造体をパラメータとベクトルのintの数が多いCUDAカーネルに渡す必要があるという大きなコードがあります。私は構造体をCUDAカーネルに渡す方法を理解できません。私は、デバイスにコピーしますが、コンパイルしようとすると、次のエラーを取得しました:ベクトルを含む構造体をCUDAカーネルに渡す
添付test_gpu.cpp:63:17: error: invalid operands to binary expression ('void (*)(Test)' and 'dim3')
computeTotal<<dimGrid, dimBlock>>(test_Device);
test_gpu.cpp:63:36: error: invalid operands to binary expression ('dim3' and 'Test *')
computeTotal<<dimGrid, dimBlock>>(test_Device);
は、コードの小さなほとんど実施例である、任意のアイデア?
#include <stdio.h>
#include <stdlib.h>
#include <cuda_runtime_api.h>
#include <cuda.h>
#include <cuda_runtime.h>
#include <device_functions.h>
#include <device_launch_parameters.h>
#include <vector>
#include <string>
typedef struct Test{
int x;
int y;
int z;
std::vector<int> vector;
std::string string;
}Test;
Test test;
__device__ void addvector(Test test, int i){
test.x += test.vector[i];
test.y += test.vector[i+1];
test.z += test.vector[i+2];
}
__global__ void computeTotal(Test test){
for (int tID = threadIdx.x; tID < threadIdx.x; ++tID)
addvector(test, tID);
}
int main()
{
Test test_Host;
int vector_size = 512;
test_Host.x = test_Host.y = test_Host.z = 0;
for (int i=0; i < vector_size; ++i)
{
test_Host.vector.push_back(rand());
}
Test* test_Device;
int size = sizeof(test_Host);
cudaMalloc((void**)&test_Device, size);
cudaMemcpy(test_Device, &test_Host, size, cudaMemcpyHostToDevice);
dim3 dimBlock(16);
dim3 dimGrid(1);
computeTotal<<dimGrid, dimBlock>>(test_Device);
return 0;
}
'std :: vector'はデバイスコードでは使用できません。このコードを '.cpp'ファイルでコンパイルしていますか? CUDAデバイスコードは通常、 '.cu'ファイルに属します。 –
はい、CPU上でOpenMPとMPIを使用する大規模なC++コードです。私は、構造体からベクトルを引き出し、それをポインタとして別々に渡さなければならないかもしれないと思っています。 – mll36