CUDAとVisual Studioに問題があります。CUDAデバッガを実行すると、最後に正常にビルドされたコードが実行されますが、プロジェクトを再度ビルドしようとすると、出力されます。"...\main.cu" exited with code 255
エラーリストと出力タブには、基本的にこのエラーがあります。ptxas fatal : Unresolved extern function '_ZN7Vector4plERKS_'
CUDA終了コード255、ptxasが致命的
他の質問をもう一度チェックして、グーグルで試してみて、別のサイトを検索して、リロケータブルデバイスをオンにしようとしましたが、同じエラーが発生しましたメッセージはptxas
を除き、
Undefined reference to '_ZN7Vector4plERKS_' in 'x64/Debug/main.cu.obj'
また、VS2015とjを使用しています確かに:まずプロジェクトをビルドし、CUDAデバッガで実行する必要がありますか? 「ローカルWindowsデバッガ」ボタンは使用しないでください。
とにかく、ここに私のコードは次のとおりです。
Vector.cuh
#pragma once
#ifdef __CUDACC__
#define CUDA_CALLABLE_MEMBER __host__ __device__
#else
#define CUDA_CALLABLE_MEMBER
#endif
#include <iostream>
class Vector4
{
public:
float x, y, z, w;
CUDA_CALLABLE_MEMBER Vector4();
CUDA_CALLABLE_MEMBER Vector4(float x, float y, float z, float w);
CUDA_CALLABLE_MEMBER virtual ~Vector4();
CUDA_CALLABLE_MEMBER void print();
CUDA_CALLABLE_MEMBER Vector4 operator+(const Vector4& other);
CUDA_CALLABLE_MEMBER void add(Vector4* other);
};
Vector.cu
Vector4::Vector4(float x, float y, float z, float w)
{
this->x = x;
this->y = y;
this->z = z;
this->w = w;
}
Vector4 Vector4::operator+(const Vector4 & other)
{
return Vector4(
this->x + other.x,
this->y + other.y,
this->z + other.z,
this->w + other.w
);
}
の一部main.cu
#include <iostream>
#include <cuda.h>
#include "cuda_runtime.h"
#include "Vector.cuh"
#include <SFML/Graphics.hpp>
__global__ void addVector(Vector4* a, Vector4* b)
{
(*a) = (*a) + (*b);
//a->x += 1;
}
int main()
{
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Green);
int size = sizeof(Vector4);
Vector4 v(1, 0, 0, 0);
Vector4 b(1, 1, 0, 0);
Vector4* d_v;
Vector4* d_b;
//cudaMalloc the device pointers
//cudaMalloc(&pointer, bytes)
cudaMalloc(&d_v, size);
cudaMalloc(&d_b, size);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
//cudaMemcpy the pointers to actual host data
//cudaMemcpy(to, from, bytes, cudaMemcpyHostToDevice)
cudaMemcpy(d_v, &v, size, cudaMemcpyHostToDevice);
cudaMemcpy(d_b, &b, size, cudaMemcpyHostToDevice);
cudaError_t err = cudaGetLastError();
HANDLE_ERROR(err);
//call kernel with the new device data
addVector << <1, 1 >> >(d_v, d_b);
//cudaMemcpy back to the old host variables
//cudaMemcpy(to, from, bytes, cudaMemcpyDeviceToHost)
cudaMemcpy(&v, d_v, size, cudaMemcpyDeviceToHost);
cudaMemcpy(&b, d_b, size, cudaMemcpyDeviceToHost);
v.print();
b.print();
printf("\n\n");
window.clear();
window.draw(shape);
window.display();
}
//cudaFree
cudaFree(d_v);
cudaFree(d_b);
getchar();
return 0;
}
もここですCUDA C++ iのコマンドラインコードnプロジェクト設定:
set CUDAFE_FLAGS=--sdk_dir "C:\Program Files (x86)\Windows Kits\8.1\"
"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\bin\nvcc.exe" --use-local-env --cl-version 2015 -ccbin "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\x86_amd64" -G --keep-dir x64\Debug -maxrregcount=0 --machine 64 --compile -cudart static -g -Xcompiler "/EHsc /nologo /FS /Zi " -o x64\Debug\%(Filename)%(Extension).obj "%(FullPath)"
ありがとうございました!
EDIT: 私はこれをコンパイルべきではありませんCUDA 8.0
また、downvotedした人のために、私はなぜ知っているかもしれませんか? – Henke