我试图使用Google复制这个github回购的结果,因为我不想在本地机器上安装所有的需求,并利用Google上的GPU
然而,我需要做的事情之一(如回购的自述)是首先编译一个cpp makefile。makefile的指令包括在下面。显然,我不能遵循这条指令,因为我不知道Google Colab的ncvv、cudalib和tensorflow库目录
cd latent_3d_points/external
with your editor modify the first three lines of the makefile to point to
your nvcc, cudalib and tensorflow library.
make是否有一种方法可以编译makefile中包含的文件(因为运行模型需要这些函数),或者直接使用makefile,或者单独编译每个cpp文件?我在下面包含了makefile的内容,以避免您在回购程序中点击寻找它。
nvcc = /usr/local/cuda-8.0/bin/nvcc
cudalib = /usr/local/cuda-8.0/lib64
tensorflow = /orions4-zfs/projects/optas/Virt_Env/tf_1.3/lib/python2.7/site-packages/tensorflow/include
all: tf_approxmatch_so.so tf_approxmatch_g.cu.o tf_nndistance_so.so tf_nndistance_g.cu.o
tf_approxmatch_so.so: tf_approxmatch_g.cu.o tf_approxmatch.cpp
g++ -std=c++11 tf_approxmatch.cpp tf_approxmatch_g.cu.o -o tf_approxmatch_so.so -shared -fPIC -I $(tensorflow) -lcudart -L $(cudalib) -O2 -D_GLIBCXX_USE_CXX11_ABI=0
tf_approxmatch_g.cu.o: tf_approxmatch_g.cu
$(nvcc) -D_GLIBCXX_USE_CXX11_ABI=0 -std=c++11 -c -o tf_approxmatch_g.cu.o tf_approxmatch_g.cu -I $(tensorflow) -DGOOGLE_CUDA=1 -x cu -Xcompiler -fPIC -O2
tf_nndistance_so.so: tf_nndistance_g.cu.o tf_nndistance.cpp
g++ -std=c++11 tf_nndistance.cpp tf_nndistance_g.cu.o -o tf_nndistance_so.so -shared -fPIC -I $(tensorflow) -lcudart -L $(cudalib) -O2 -D_GLIBCXX_USE_CXX11_ABI=0
tf_nndistance_g.cu.o: tf_nndistance_g.cu
$(nvcc) -D_GLIBCXX_USE_CXX11_ABI=0 -std=c++11 -c -o tf_nndistance_g.cu.o tf_nndistance_g.cu -I $(tensorflow) -DGOOGLE_CUDA=1 -x cu -Xcompiler -fPIC -O2
clean:
rm tf_approxmatch_so.so
rm tf_nndistance_so.so
rm *.cu.o 发布于 2021-01-07 10:22:16
您可以在google中安装所需的Cuda版本。就像。
对于Cuda 9.2,您可以尝试
!apt-get --purge remove cuda nvidia* libnvidia-*
!dpkg -l | grep cuda- | awk '{print $2}' | xargs -n1 dpkg --purge
!apt-get remove cuda-*
!apt autoremove
!apt-get update
!wget https://developer.nvidia.com/compute/cuda/9.2/Prod/local_installers/cuda-repo-ubuntu1604-9-2-local_9.2.88-1_amd64 -O cuda-repo-ubuntu1604-9-2-local_9.2.88-1_amd64.deb
!dpkg -i cuda-repo-ubuntu1604-9-2-local_9.2.88-1_amd64.deb
!apt-key add /var/cuda-repo-9-2-local/7fa2af80.pub
!apt-get update
!apt-get install cuda-9.2类似地,您可以找到一种安装Cuda 8.2的方法。
gcc
!apt-get install -qq gcc-5 g++-5 -y
!ln -s /usr/bin/gcc-5
!ln -s /usr/bin/g++-5
!sudo apt-get update
!sudo apt-get upgrade然后,如果安装有自定义make文件,则可以编译它或通过运行make使它。
!make
发布于 2021-11-16 02:18:31
您可以通过在colab的单元中添加%%bash来使用bash,就像在您的pc上一样。示例:
单元格一:编写cpp文件
%%writefile welcome.cpp
#include <iostream>
int main()
{
std::cout << "Welcome To AI with Ashok's Blog\n";
return 0;
}单元格二:编译和运行
%%bash
g++ welcome.cpp -o welcome
./welcome您还可以在colab的内置文本编辑器中打开cpp文件,以享受正确的高光效果。当您从左边的"Files“选项卡打开文本文件时,它会打开,并且可以使用"ctr+s”快捷方式保存。
https://stackoverflow.com/questions/65603808
复制相似问题