NN CUDA Example
1.0.0

カスタムCUDAオペレーターを呼び出すニューラルネットワークツールキット(Pytorch、Tensorflowなど)のいくつかの簡単な例。
JIT、SetUptools、Cmakeなど、CudaカーネルとそのCPPラッパーをコンパイルするいくつかの方法を提供します。
また、カーネルの時間統計やモデルトレーニングなど、Cudaカーネルを呼び出すためのいくつかのPythonコードも提供しています。
より正確な時間統計については、コードを実行するためにNVPROFまたはNSYSを使用するのが最適です。
他の環境での実行を成功させることはできません。
├── include
│ └── add2.h # header file of add2 cuda kernel
├── kernel
│ └── add2_kernel.cu # add2 cuda kernel
├── pytorch
│ ├── add2_ops.cpp # torch wrapper of add2 cuda kernel
│ ├── time.py # time comparison of cuda kernel and torch
│ ├── train.py # training using custom cuda kernel
│ ├── setup.py
│ └── CMakeLists.txt
├── tensorflow
│ ├── add2_ops.cpp # tensorflow wrapper of add2 cuda kernel
│ ├── time.py # time comparison of cuda kernel and tensorflow
│ ├── train.py # training using custom cuda kernel
│ └── CMakeLists.txt
├── LICENSE
└── README.mdjit
Pythonコードを直接実行します。
setuptools
python3 pytorch/setup.py installcmake
mkdir build
cd build
cmake ../pytorch
makeカーネルの実行時間を比較します
python3 pytorch/time.py --compiler jit
python3 pytorch/time.py --compiler setup
python3 pytorch/time.py --compiler cmake列車モデル
python3 pytorch/train.py --compiler jit
python3 pytorch/train.py --compiler setup
python3 pytorch/train.py --compiler cmakecmake
mkdir build
cd build
cmake ../tensorflow
makeカーネルの実行時間を比較します
python3 tensorflow/time.py --compiler cmake列車モデル
python3 tensorflow/train.py --compiler cmakepytorch自定义cuda
Q. ImporterRor:LIBC10.SO:共有オブジェクトファイルを開くことができません:そのようなファイルやディレクトリはありません
A.import add2前に、import torchする必要があります。
Q. tensorflow.python.framework.errors_impl.notfounderror:build/libadd2.so:未定義のシンボル:_ztin10tensorflow8opkernele
A.CmakeLists.txtの${TF_LFLAGS}が正しいかどうかを確認します。