博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
QT+CUDA7.5+UBUNTU14.04
阅读量:4040 次
发布时间:2019-05-24

本文共 3327 字,大约阅读时间需要 11 分钟。

接着前面有篇文章介绍在windows上面对他们进行合成,这篇文章我们介绍下在ubuntu上面对其合成。

程序用的是brown大学里面snow-master,该project包括了几个项目,其中有个CUDA_helloworld刚好可以拿来练手

CUDA在ubuntu上面的安装我就不多介绍,攻略帖一大堆

下面开始介绍下这个项目

main.cpp内容如下:

#include 
extern "C" // tell compiler that function is defined somewhere elsevoid runCudaPart();#include
int main(int argc, char *argv[]){ QCoreApplication a(argc, argv); runCudaPart(); return a.exec();}

kernel.cu内容如下:

#include 
#include
#include
#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);}void runCudaPart(){ // all your cuda code here glm::vec3 v(0.1f, 0.2f, 0.3f);// helloCUDA<<<1, 5>>>(v); // 1 block, 5 GPU threads helloCUDA<<<5,1>>>(v); // 5 blocks, 1 GPU thread each cudaDeviceSynchronize();}

其中项目的pro文件如下:

#-------------------------------------------------## Project created by QtCreator 2014-04-03T18:12:01##-------------------------------------------------QT       += coreQT       -= guiTARGET = CUDA_helloworldCONFIG   += consoleCONFIG   -= app_bundleTEMPLATE = appSOURCES += main.cpp# GLMINCLUDEPATH += /usr/local/glm# C++ flagQMAKE_CXXFLAGS_RELEASE=-O3# CUDA stuffCUDA_SOURCES += kernel.cu# uncomment below to also import include CUDA SDK#CUDA_SDK = /contrib/projects/cuda-sdk/C#INCLUDEPATH += $$CUDA_SDK/common/inc/#INCLUDEPATH += $$CUDA_SDK/../shared/inc/#QMAKE_LIBDIR += $$CUDA_SDK/lib#QMAKE_LIBDIR += $$CUDA_SDK/common/libCUDA_DIR = /usr/local/cuda-7.5INCLUDEPATH += $$CUDA_DIR/includeQMAKE_LIBDIR += $$CUDA_DIR/lib64#LD_LIBRARY_PATH=$${LD_LIBRARY_PATH}:$$CUDA_DIR/lib64#message($${LD_LIBRARY_PATH})#$$(PATH) = $$(PATH):$$CUDA_DIR/bin#message($$(PATH))LIBS += -lcudart -lcudaOTHER_FILES += \    CUDA_notes.txt \    kernel.cu# GPU ARCH# this gets passed as the gpu-architecture flag to nvcc compiler# specifying particular architectures enable certain features, limited to the compute capability# of the GPU. compute capabilities listed here http://en.wikipedia.org/wiki/CUDA# MSLAB GeForce 460 seems to have compute capability 2.1CUDA_ARCH = sm_21# custom NVCC flagsNVCCFLAGS     = --compiler-options -fno-strict-aliasing -use_fast_math --ptxas-options=-v# Prepare the extra compiler configuration (taken from the nvidia forum - i'm not an expert in this part)CUDA_INC = $$join(INCLUDEPATH,' -I','-I',' ')# compile CUDA kernels using nvcccuda.commands = $$CUDA_DIR/bin/nvcc -m64 -g -G -arch=$$CUDA_ARCH -c $$NVCCFLAGS $$CUDA_INC $$LIBS  ${QMAKE_FILE_NAME} -o ${QMAKE_FILE_OUT} \    2>&1 | sed -r \"s/\\(([0-9]+)\\)/:\\1/g\" 1>&2# Prepare the extra compiler configuration (taken from the nvidia forum - i'm not an expert in this part)cuda.input = CUDA_SOURCEScuda.output = ${OBJECTS_DIR}${QMAKE_FILE_BASE}_cuda.o # suffix needed for this to work?# Tell Qt that we want add more stuff to the MakefileQMAKE_EXTRA_UNIX_COMPILERS += cuda

配置好后运行,会出现

libcudart.so.7.5: cannot open shared object file: No such file or directory

网上搜了下,解决方法如下

在shell中输入:

32-bit: sudo ldconfig /usr/local/cuda-7.5/lib

64-bit: sudo ldconfig /usr/local/cuda-7.5/lib64

cheers!

你可能感兴趣的文章
[leetcode BY python]1两数之和
查看>>
微信小程序开发全线记录
查看>>
PTA:一元多项式的加乘运算
查看>>
CCF 分蛋糕
查看>>
解决python2.7中UnicodeEncodeError
查看>>
小谈python 输出
查看>>
Django objects.all()、objects.get()与objects.filter()之间的区别介绍
查看>>
python:如何将excel文件转化成CSV格式
查看>>
机器学习实战之决策树(一)
查看>>
机器学习实战之决策树二
查看>>
[LeetCode By Python]7 Reverse Integer
查看>>
[leetCode By Python] 14. Longest Common Prefix
查看>>
[LeetCode By Python]118. Pascal's Triangle
查看>>
[LeetCode By Python]121. Best Time to Buy and Sell Stock
查看>>
[LeetCode By Python]122. Best Time to Buy and Sell Stock II
查看>>
[LeetCode By Python]125. Valid Palindrome
查看>>
[LeetCode By Python]136. Single Number
查看>>
[LeetCode By MYSQL] Combine Two Tables
查看>>
Android下调用收发短信邮件等(转载)
查看>>
Android中电池信息(Battery information)的取得
查看>>