使用 QtCreator 构建 CUDA/C++ 测试程序时出现错误 2
Error 2 when building CUDA/C++ test program with QtCreator
我在尝试运行一个简单的测试程序来开始学习 CUDA 时遇到了一些麻烦。我正在尝试让一个标准的C++主文件调用另一个文件中的内核函数。
编译步骤似乎运行良好,但看起来链接器不知道如何处理 .o 文件以及如何创建.exe我从这里尝试了一些修改/选项:https://devblogs.nvidia.com/separate-compilation-linking-cuda-device-code/
我正在尝试在编译后使用 mingw 作为链接。我会错过一些额外的图书馆吗?所有.o文件都在正确的位置正确创建。
但我仍然无法让我的程序运行。
以下是错误日志:
19:00:03: Exécution des étapes pour le projet test01...
19:00:03: Configuration inchangée, étape qmake sautée.
19:00:03: Débute : "C:QtQt5.10.0Toolsmingw530_32binmingw32-make.exe"
C:QtQt5.10.05.10.0mingw53_32binqmake.exe -o Makefile ..test01test01.pro -spec win32-g++ "CONFIG+=debug" "CONFIG+=qml_debug"
C:/Qt/Qt5.10.0/Tools/mingw530_32/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory 'D:/lab_stuff/programmation/C++/test01/build-test01-Desktop_Qt_5_10_0_MinGW_32bit-Debug'
mingw32_make.exe -Wl,-subsystem,console -mthreads -o debugtest01.exe debug/cuda/vectoradd_cuda.o debug/obj/main.o -L"C:Program FilesNVIDIA GPU Computing ToolkitCUDAv9.1libx64" -lcuda -lcudart -lcudadevrt -LC:QtQt5.10.05.10.0mingw53_32lib C:QtQt5.10.05.10.0mingw53_32liblibQt5Cored.a
Makefile.Debug:64: recipe for target 'debugtest01.exe' failed
mingw32-make[1]: Leaving directory 'D:/lab_stuff/programmation/C++/test01/build-test01-Desktop_Qt_5_10_0_MinGW_32bit-Debug'
process_begin: CreateProcess(NULL, mingw32_make.exe -Wl,-subsystem,console -mthreads -o debugtest01.exe debug/cuda/vectoradd_cuda.o debug/obj/main.o "-LC:Program FilesNVIDIA GPU Computing ToolkitCUDAv9.1libx64" -lcuda -lcudart -lcudadevrt -LC:QtQt5.10.05.10.0mingw53_32lib C:QtQt5.10.05.10.0mingw53_32liblibQt5Cored.a, ...) failed.
make (e=2): Le fichier spécifié est introuvable.
mingw32-make[1]: *** [debugtest01.exe] Error 2
Makefile:36: recipe for target 'debug' failed
mingw32-make: *** [debug] Error 2
19:00:05: Le processus "C:QtQt5.10.0Toolsmingw530_32binmingw32-make.exe" s'est terminé avec le code 2.
Erreur lors de la compilation/déploiement du projet test01 (kit : Desktop Qt 5.10.0 MinGW 32bit)
When executing step "Make"
19:00:05: Temps écoulé : 00:02.
.pro 文件: QT -= GUI
CONFIG += console
CONFIG -= app_bundle
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# Source files
SOURCES += main.cpp
# This makes the .cu files appear in your project
# OTHER_FILES += vectoradd.cu
# CUDA settings <-- may change depending on your system
CUDA_SOURCES += vectoradd.cu
CUDA_DIR = "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v9.1" # Path to cuda toolkit install
SYSTEM_NAME = x64
NVCC_OPTIONS = --use_fast_math -dlink
# include paths
INCLUDEPATH += $$CUDA_DIRinclude
# library directories
QMAKE_LIBDIR += $$CUDA_DIR/lib/$$SYSTEM_NAME
# Add the necessary libraries
LIBS += -lcuda -lcudart
QMAKE_LINK = mingw32_make.exe
# The following makes sure all path names (which often include spaces) are put between quotation marks
CUDA_INC = $$join(INCLUDEPATH,'" -I"','-I"','"')
# Configuration of the Cuda compiler
CONFIG(debug, debug|release) {
# Debug mode
DESTDIR = debug
OBJECTS_DIR = debug/obj
CUDA_OBJECTS_DIR = debug/cuda
cuda_d.input = CUDA_SOURCES
cuda_d.output = $$CUDA_OBJECTS_DIR/${QMAKE_FILE_BASE}_cuda.o
cuda_d.commands = $$CUDA_DIR/bin/nvcc.exe -D_DEBUG $$NVCC_OPTIONS $$CUDA_INC $$LIBS -c -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_NAME}
cuda_d.dependency_type = TYPE_C
QMAKE_EXTRA_COMPILERS += cuda_d
}
else {
# Release mode
DESTDIR = release
OBJECTS_DIR = release/obj
CUDA_OBJECTS_DIR = release/cuda
cuda.input = CUDA_SOURCES
cuda.output = $$CUDA_OBJECTS_DIR/${QMAKE_FILE_BASE}_cuda.o
cuda.commands = $$CUDA_DIR/bin/nvcc.exe $$NVCC_OPTIONS $$CUDA_INC $$LIBS -c -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_NAME}
cuda.dependency_type = TYPE_C
QMAKE_EXTRA_COMPILERS += cuda
}
主.cpp文件:
#include <cmath>
#include <chrono>
#include <iostream>
#include <cuda.h>
typedef std::chrono::high_resolution_clock timer;
typedef std::chrono::duration<float, std::ratio<1, 1000> > chrono;
void add_wrapper(int n, float *x, float *y);
int main()
{
std::chrono::time_point<timer> start = timer::now();
int N = 1<<20;
float *x = new float[N];
float *y = new float[N];
for(int i=0; i < N; ++i)
{
x[i] = 1.0f;
y[i] = 2.0f;
}
add_wrapper(N, x, y);
float maxError = 0.0f;
for(int i=0; i < N; ++i)
maxError = fmax(maxError, fabs(y[i] - 3.0f));
std::cout << "Max error: " << maxError << " obtained in ";
std::cout << std::chrono::duration_cast<chrono>(timer::now() - start).count() << " ms n";
delete[] x;
delete[] y;
return 0;
}
和 vectoradd.cu 文件:
#include <cuda.h>
#include <cuda_runtime.h>
__global__
void addVectors(int n, float *x, float *y)
{
for(int i=0; i < n; ++i)
y[i] = x[i] + y[i];
}
void add_wrapper(int n, float *x, float *y)
{
float *d_x = new float[n];
float *d_y = new float[n];
cudaMallocManaged(&x, sizeof(float));
cudaMallocManaged(&y, sizeof(float));
cudaMemcpy(d_x, x, sizeof(float), cudaMemcpyHostToDevice);
cudaMemcpy(d_y, y, sizeof(float), cudaMemcpyHostToDevice);
addVectors<<<1, 1>>>(n, d_x, d_y);
cudaDeviceSynchronize();
cudaMemcpy(x, d_x, sizeof(float), cudaMemcpyDeviceToHost);
cudaMemcpy(y, d_y, sizeof(float), cudaMemcpyDeviceToHost);
cudaFree(d_x);
cudaFree(d_y);
}
提前感谢您的帮助。
您尝试执行的操作不受支持。
根据文档,Windows平台上唯一支持的工具链是Visual Studio。你可以使用 QT Creator 和 Qmake 来构建项目,但你必须使用 Microsoft 工具链来编译和链接代码。不支持 MinGW 和 gcc。另请注意,最新版本的 CUDA 也不支持 32 位工具链。您可以使用工具链交叉编译为 32 位目标,但 Windows 上的本机 32 位工具链支持几年前就被删除了。
相关文章:
- 系统错误:程序无法启动,因为您的计算机中缺少MSVCP140D.DLL。尝试重新安装该程序以解决此问题
- 如何将参数传递给Google基准测试程序
- 提升精神 x3 错误处理程序与期望
- Cmake无法在qt-creater/collect2上编译简单的测试程序:错误:ld
- 由于值返回函数中的错误,程序无法编译.它说未声明的标识符
- C++字数统计程序使用C字符串错误在程序运行后
- CMake 和 Visual Studio 2015 - C 编译器 cl.exe 无法编译简单的测试程序
- C++编译器 g++.exe 无法编译简单的测试程序 - 确定 CXX 编译器是否工作失败
- 如何编译和运行 vmmlib 测试程序?
- C++测试程序中的非法系统调用(对角矩阵元素程序的总和)
- 在我的测试程序中,为什么 cv::resize 不能执行,而 cvtColor 可以?
- 未知的错误导致程序返回怪异的符号
- 使用 QtCreator 构建 CUDA/C++ 测试程序时出现错误 2
- SDL 测试程序 - "No such file or directory"
- 软件定义无线电 USRP X310 的测试程序
- CMake 在尝试编译简单测试程序时失败
- 如何调试正常运行但在 ide 中返回分段错误的程序?
- 无法运行简单的 std::async 和 std::future 测试程序。错误:"has initializer but incomplete type."发生了什么?
- C 编译器无法编译简单的测试程序
- 试图链接一个测试程序到一个库,得到错误:iostream:没有这样的文件或目录