CMake传递命令的参数我们在哪儿添加呢?
打开当前工作目录的setting界面,例如USER SETTINGS,添加我们Cmake的配置参数:
{
...
"cmake.configureArgs":["-DCMAKE_PREFIX_PATH=/home/prototype/Desktop/Cuda-project/libtorch"],
}
好,然后我们执行Cmake的confit命令,我们直接调用命令台工具(Ctrl + Shift + P),然后选择Cmake Config:
这时候输出配置信息:
[cmake] Looking for pthread.h
[cmake] Looking for pthread.h - found
[cmake] Looking for pthread_create
[cmake] Looking for pthread_create - not found
[cmake] Looking for pthread_create in pthreads
[cmake] Looking for pthread_create in pthreads - not found
[cmake] Looking for pthread_create in pthread
[cmake] Looking for pthread_create in pthread - found
[cmake] Found Threads: TRUE
[cmake] Found CUDA: /usr/local/cuda (found suitable version "9.2", minimum required is "7.0")
[cmake] Caffe2: CUDA detected: 9.2
[cmake] Caffe2: CUDA nvcc is: /usr/local/cuda/bin/nvcc
[cmake] Caffe2: CUDA toolkit directory: /usr/local/cuda
[cmake] Caffe2: Header version is: 9.2
[cmake] Found CUDNN: /usr/local/cuda/include
[cmake] Found cuDNN: v7.4.1 (include: /usr/local/cuda/include, library: /usr/local/cuda/lib64/libcudnn.so)
[cmake] Autodetected CUDA architecture(s): 6.1;6.1
[cmake] Added CUDA NVCC flags for: -gencode;arch=compute_61,code=sm_61
[cmake] Found torch: /home/prototype/Desktop/Cuda-project/libtorch/lib/libtorch.so
[cmake] Found OpenCV: /usr/local (found version "4.0.0")
[cmake] Pytorch status:
[cmake] libraries: torch;caffe2_library;caffe2_gpu_library;/usr/lib/x86_64-linux-gnu/libcuda.so;/usr/local/cuda/lib64/libnvrtc.so;/usr/local/cuda/lib64/libnvToolsExt.so;/usr/local/cuda/lib64/libcudart_static.a;-lpthread;dl;/usr/lib/x86_64-linux-gnu/librt.so
[cmake] OpenCV library status:
[cmake] version: 4.0.0
[cmake] libraries: opencv_calib3d;opencv_core;opencv_dnn;opencv_features2d;opencv_flann;opencv_gapi;opencv_highgui;opencv_imgcodecs;opencv_imgproc;opencv_ml;opencv_objdetect;opencv_photo;opencv_stitching;opencv_video;opencv_videoio
[cmake] include path: /usr/local/include/opencv4
[cmake] Configuring done
[cmake] Generating done
提示所有库都找到了。
然后我们点击下面的build按钮:
就可以进行编译了:
[build] Starting build
[proc] Executing command: /home/prototype/anaconda3/bin/cmake --build /home/prototype/test/build --config Debug --target all -- -j 14
[build] Scanning dependencies of target example-app
[build] [ 50%] Building CXX object CMakeFiles/example-app.dir/main.cpp.o
[build] [100%] Linking CXX executable example-app
[build] [100%] Built target example-app
[build] Build finished with exit code 0
这里也是提示我们编译成功,成功后我们的目录是这样的:
所有的编译后的东西自动被这个cmake插件放入了build文件夹中,这个文件夹也是cmake插件自动生成的。
我们进入build文件夹执行一下我们生成的可执行文件:
prototype@prototype-X299-UD4-Pro:~/test$ cd build/
prototype@prototype-X299-UD4-Pro:~/test/build$ ./example-app
usage: example-app <path-to-exported-script-module>
prototype@prototype-X299-UD4-Pro:~/test/build$ ./example-app /home/prototype/Desktop/Deep-Learning/Pytorch-Learn/test/mobilenetv2-trace.pt
Time used:2521.94 ms
很快便输出了执行结果。
但是现在仍然还有两个问题:
下面我们便解决这两个问题:
网站声明:如果转载,请联系本站管理员。否则一切后果自行承担。
添加我为好友,拉您入交流群!
请使用微信扫一扫!