qtcreator配置編譯器,CUDA + QT Creator + Win7的集成

 2023-11-12 阅读 20 评论 0

摘要:最近看到brown大學一位同學做的demo簡直是牛B,里面居然實現了物體的移動軸,旋轉圈等,跟MAYA界面差不多,一直想找一個這樣的GUI,找不到,沒辦法,自己做吧,所以決心學下QT,當然這位同學的程序中用到了CUDA,為了調通他的程序,我又只好硬著頭皮去搞下CUDA,花了二天時間,終于把它帶的

最近看到brown大學一位同學做的demo簡直是牛B,里面居然實現了物體的移動軸,旋轉圈等,跟MAYA界面差不多,一直想找一個這樣的GUI,找不到,沒辦法,自己做吧,所以決心學下QT,當然這位同學的程序中用到了CUDA,為了調通他的程序,我又只好硬著頭皮去搞下CUDA,花了二天時間,終于把它帶的CUDA helloworld程序調通了


注意這里QT creator里面的調試器用的VS2010里面的, 并且這個程序又跟CUDA結合, 所以PRO的寫法我琢磨了很久,最終將近二天的時間將它搞出來了.看來要學的還是跑不掉,所以多學點吧,Linux也跑不掉的


好了,開始正題


1.下載CUDA

下載地址:https://developer.nvidia.com/cuda-downloads


自己結合需求選


我用的CUDA7.5


2.QT Creator的配置


已經配置好了的就跳過該步,沒有配置好的見我的另一篇文章

http://blog.csdn.net/seamanj/article/details/49650101


3.開搞


main.cpp文件如下:

#include <QCoreApplication>extern "C" // tell compiler that function is defined somewhere elsevoid runCudaPart();#include <stdio.h>int main(int argc, char *argv[])
{QCoreApplication a(argc, argv);runCudaPart();return a.exec();
}
kernel.cu文件如下:

#include <cuda.h>
#include <cuda_runtime.h>
#include <device_launch_parameters.h>
#include <glm/glm.hpp>
#include <stdio.h>#if defined(__CUDA_ARCH__) && (__CUDA_ARCH__ < 200)# error printf is only supported on devices of compute capability 2.0 and higher, please compile with -arch=sm_20 or higher
#endifextern "C"
void runCudaPart();__global__ void helloCUDA(glm::vec3 v)
{int tid = blockIdx.x;printf("Hello block %d thread %d, x=%f\n",tid , threadIdx.x, v.x);
}
extern "C"
void runCudaPart()
{// all your cuda code hereglm::vec3 v(0.1f, 0.2f, 0.3f);//helloCUDA<<<1, 5>>>(v); // 1 block, 5 GPU threadshelloCUDA<<<5,1>>>(v); // 5 blocks, 1 GPU thread eachcudaDeviceSynchronize();
}

重點是CUDA_helloworld.pro文件的配置

格式不對,請點plain↓

#-------------------------------------------------
#
# Project created by QtCreator 2014-04-03T18:12:01
#
#-------------------------------------------------QT       += core
QT       -= guiTARGET = CUDA_helloworld
CONFIG   += console
CONFIG   -= app_bundleTEMPLATE = appSOURCES += main.cpp# GLM
INCLUDEPATH += "D:/work_files/glm"# CUDA# Define output directories
DESTDIR = ../bin
CUDA_OBJECTS_DIR = OBJECTS_DIR/../cuda# This makes the .cu files appear in your project
OTHER_FILES += \kernel.cu \CUDA_notes.txtCUDA_SOURCES += \kernel.cu#-------------------------------------------------# MSVCRT link option (static or dynamic, it must be the same with your Qt SDK link option)
MSVCRT_LINK_FLAG_DEBUG   = "/MDd"
MSVCRT_LINK_FLAG_RELEASE = "/MD"# CUDA settings
CUDA_DIR = "D:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v7.5/"                # Path to cuda toolkit install
SYSTEM_NAME = Win32                 # Depending on your system either 'Win32', 'x64', or 'Win64'
SYSTEM_TYPE = 32                    # '32' or '64', depending on your system
CUDA_ARCH = sm_30                   # Type of CUDA architecture
NVCC_OPTIONS = --use_fast_math# include paths
INCLUDEPATH += $$CUDA_DIR/include \$$CUDA_DIR/common/inc \$$CUDA_DIR/../shared/inc# library directories
QMAKE_LIBDIR += $$CUDA_DIR/lib/$$SYSTEM_NAME \$$CUDA_DIR/common/lib/$$SYSTEM_NAME \$$CUDA_DIR/../shared/lib/$$SYSTEM_NAME# The following makes sure all path names (which often include spaces) are put between quotation marks
CUDA_INC = $$join(INCLUDEPATH,'" -I"','-I"','"')# Add the necessary libraries
CUDA_LIB_NAMES = cudart_static kernel32 user32 gdi32 winspool comdlg32 \advapi32 shell32 ole32 oleaut32 uuid odbc32 odbccp32 \#freeglut glew32for(lib, CUDA_LIB_NAMES) {CUDA_LIBS += -l$$lib
}
LIBS += $$CUDA_LIBS# Configuration of the Cuda compiler
CONFIG(debug, debug|release) {# Debug modecuda_d.input = CUDA_SOURCEScuda_d.output = $$CUDA_OBJECTS_DIR/${QMAKE_FILE_BASE}_cuda.objcuda_d.commands = $$CUDA_DIR/bin/nvcc.exe -D_DEBUG $$NVCC_OPTIONS $$CUDA_INC $$LIBS \--machine $$SYSTEM_TYPE -arch=$$CUDA_ARCH \--compile -cudart static -g -DWIN32 -D_MBCS \-Xcompiler "/wd4819,/EHsc,/W3,/nologo,/Od,/Zi,/RTC1" \-Xcompiler $$MSVCRT_LINK_FLAG_DEBUG \-c -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_NAME}cuda_d.dependency_type = TYPE_CQMAKE_EXTRA_COMPILERS += cuda_d
}
else {# Release modecuda.input = CUDA_SOURCEScuda.output = $$CUDA_OBJECTS_DIR/${QMAKE_FILE_BASE}_cuda.objcuda.commands = $$CUDA_DIR/bin/nvcc.exe $$NVCC_OPTIONS $$CUDA_INC $$LIBS \--machine $$SYSTEM_TYPE -arch=$$CUDA_ARCH \--compile -cudart static -DWIN32 -D_MBCS \-Xcompiler "/wd4819,/EHsc,/W3,/nologo,/O2,/Zi" \-Xcompiler $$MSVCRT_LINK_FLAG_RELEASE \-c -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_NAME}cuda.dependency_type = TYPE_CQMAKE_EXTRA_COMPILERS += cuda
}

具體的含義我就不多解釋了,運行結果如下:



最后,如果想學CUDA的話,推薦視頻:

https://www.udacity.com/course/viewer#!/c-cs344/l-55120467/m-65830481







版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/3/171556.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息