(윈도우 10, CUDA는 8.0, VS 2015 년 CMake 3.7.0CUDA는 CMake
나는 CUDA 커널과 라이브러리를 구축하는 데 문제가 있어요을 사용하여 86 빌딩을 붙어.
내 프로젝트는 최고 수준이 서브 프로젝트 CMakeLists.txt에서
cmake_minimum_required(VERSION 3.0)
project (robot)
find_package(CUDA REQUIRED)
#...some more stuff
include(${PROJECT_SOURCE_DIR}/projects/subproject/CMakeLists.txt)
이어서 :. 최상위 레벨에서 서브 CMakeLists.txt
포함 CMakeLists.txt
,536,set(SUBPROJECT_SOURCE_DIR ${PROJECT_SOURCE_DIR}/projects/subproject)
file(GLOB_RECURSE SUBPROJECT_HEADER ${SUBPROJECT_SOURCE_DIR}/*.h)
file(GLOB_RECURSE SUBPROJECT_SOURCE ${SUBPROJECT_SOURCE_DIR}/*.cpp)
file(GLOB_RECURSE SUBPROJECT_CUDA ${SUBPROJECT_SOURCE_DIR}/*.cu)
file(GLOB_RECURSE SUBPROJECT_CUDA_HEADER ${SUBPROJECT_SOURCE_DIR}/*.cuh)
cuda_add_library(subproject STATIC ${SUBPROJECT_HEADER} ${SUBPROJECT_SOURCE} ${SUBPROJECT_CUDA_HEADER} ${SUBPROJECT_CUDA})
target_include_directories(subproject PRIVATE ${SUBPROJECT_SOURCE_DIR}/include)
#some other includes and target_includes here...
target_link_libraries(subproject <some links here>)
내 원본 디렉토리에는 .cuh 및 .cu 파일이 있습니다. 이들은 간단한 VectorAdd 테스트를 기반으로하고 있습니다 :
kernel.cuh :
#include <stdio.h>
#include <cuda.h>
#include <cuda_runtime.h>
#include <device_launch_parameters.h>
__global__ void VectorAdd(int *a, int *b, int *c, int n);
int test();
그리고 kernel.cu :
#include "kernel.cuh"
#define SIZE 1024
__global__ void VectorAdd(int *a, int *b, int *c, int n) {
int i = threadIdx.x;
if (i < n){
c[i] = a[i] + b[i];
}
}
int test() {
int *a, *b, *c;
int *d_a, *d_b, *d_c;
a = (int *)malloc(SIZE * sizeof(int));
b = (int *)malloc(SIZE * sizeof(int));
c = (int *)malloc(SIZE * sizeof(int));
cudaMalloc(&d_a, SIZE * sizeof(int));
cudaMalloc(&d_b, SIZE * sizeof(int));
cudaMalloc(&d_c, SIZE * sizeof(int));
for (int i = 0; i < SIZE; ++i) {
a[i] = i;
b[i] = i;
c[i] = 0;
}
cudaMemcpy(d_a, a, SIZE * sizeof(int), cudaMemcpyHostToDevice);
cudaMemcpy(d_b, b, SIZE * sizeof(int), cudaMemcpyHostToDevice);
cudaMemcpy(d_c, c, SIZE * sizeof(int), cudaMemcpyHostToDevice);
VectorAdd<<< 1, SIZE >>>(d_a, d_b, d_c, SIZE);
cudaMemcpy(c, d_c, SIZE * sizeof(int), cudaMemcpyDeviceToHost);
for (int i = 0; i < 10; ++i) {
printf("c[%d] = %d\n", i, c[i]);
}
free(a);
free(b);
free(c);
cudaFree(d_a);
cudaFree(d_b);
cudaFree(d_c);
return 0;
}
내가 내 프로젝트에서 다른 C++ 파일에 Kernel.cuh을 포함한다. 다음 lib 디렉토리를 찾을 수 없다는 사실에 이르게
Severity Code Description Project File Line Suppression State
Error LNK1112 module machine type 'X86' conflicts with target machine type 'x64' subproject C:\path_to_proj\build\CMakeFiles\subproject.dir\projects\subproject\src\Release\subproject_generated_kernel.cu.obj 1
: 내 솔루션을 컴파일하려고, 나는 다음과 같은 오류가 발생합니다. 이 오류의 원인은 무엇입니까? CMakeLists에 추가해야 할 것이 있습니까?
감사합니다. 버그 수정 된 부분 ... 새로운 버그가 있습니다. 관련이 있는지 확실하지 않아서, 이제 내 프로그램이 .dll 파일을 찾을 수 없습니다. 두 번째 부분은이를 수정하려고 시도하는 것 같습니다. 그러나 두 번째 부분이 추가되면 갑자기 복사 할 필요가없는 특정 lib 파일을 찾습니다. 왜 이런거야? 마지막 줄에는 일치하지 않는 괄호가 있습니다 :) – user650261
(더 자세한 정보를 제공하기 위해 줄을 추가하면 오류가 발생합니다. 이제는 glut32.lib 파일을 열 수 없습니다. ? – user650261
제 대답은 비주얼 스튜디오 프로젝트에 포함 경로를 추가하는 것입니다. 마지막 줄에는 VS가 cuda.lib 파일을 찾을 수있는 위치가 표시됩니다. glut32는 OpenGL의 라이브러리입니다. 어쩌면 다른 질문이며 cuda와는 아무런 관련이 없습니다 (여러분은 cuda를 glut없이 사용할 수 있습니다).하지만 관심을 갖기 위해서는 링크 디렉토리를 지정해야합니다 (예 : link_directory (/ path/to/glut)). 그리고 관련 dll을 바이너리 경로에 복사해야합니다. – Soeren