Code Monkey home page Code Monkey logo

nn-cuda-example's Introduction

算法码上来 👋

  • 📙 字节跳动AI Lab NLP算法工程师
  • 🔨 研究方向:模型优化、机器翻译、句法分析
  • 🐏 微信公众号:算法码上来
  • ❤️ 微信:godweiyang,长期内推,加我进技术&内推群

nn-cuda-example's People

Contributors

godweiyang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nn-cuda-example's Issues

About operating system

I want to ask a question, is these code run in the macos? If so, how can I run on windows?

tf2.3 cuda10.1 tf.load_op_libary("build/libadd2.so") error

Traceback (most recent call last):
File "tensorflow/time.py", line 57, in
cuda_module = tf.load_op_library('build/libadd2.so')
File "/home/guowei/anaconda3/envs/gy_py3.7_tf2.3/lib/python3.7/site-packages/tensorflow/python/framework/load_library.py", line 58, in load_op_library
lib_handle = py_tf.TF_LoadLibrary(library_filename)
tensorflow.python.framework.errors_impl.NotFoundError: build/libadd2.so: undefined symbol: _ZTIN10tensorflow8OpKernelE

torch.ops.load_library("build/libadd2.so") error

Traceback (most recent call last):
File "time.py", line 60, in
torch.ops.load_library("build/libadd2.so")
File "/home/gzy/anaconda3/envs/pytorch1.7/lib/python3.6/site-packages/torch/_ops.py", line 105, in load_library
ctypes.CDLL(path)
File "/home/gzy/anaconda3/envs/pytorch1.7/lib/python3.6/ctypes/init.py", line 348, in init
self._handle = _dlopen(self._name, mode)
OSError: /home/gzy/NN-CUDA-Example/pytorch/build/libadd2.so: undefined symbol: THPVariableClass

ERROR: expected constructor, destructor, or type conversion before ‘(’ token

Thanks for your sharing. When I compile pytorch project using JIT or Setuptools (e.g., python3 pytorch/setup.py install), I have a error as follows:

/home/chenxingyu/Documents/NN-CUDA-Example/pytorch/add2_ops.cpp:20:14: error: expected constructor, destructor, or type conversion before ‘(’ token
 TORCH_LIBRARY(add2, m) {

Could you help me solve it?

运行结果不对

运行结果:cuda_res 运行前后的结果是一样的,是怎么回事啊

有docker相关的环境吗?

大佬,能提供docker相关的环境吗?本地编译的时候,环境不一致出现了报错,折腾了下还是不行

A compilation problem about setup.py

This problem occurs when I compile

running install
running bdist_egg
running egg_info
writing add2.egg-info\PKG-INFO
writing dependency_links to add2.egg-info\dependency_links.txt
writing top-level names to add2.egg-info\top_level.txt
reading manifest file 'add2.egg-info\SOURCES.txt'
writing manifest file 'add2.egg-info\SOURCES.txt'
installing library code to build\bdist.win-amd64\egg
running install_lib
running build_ext
D:\miniconda3\envs\torch-gpu\lib\site-packages\torch\utils\cpp_extension.py:304: UserWarning: Error checking compiler version for cl: [WinError 2] 系统找不到指定的文件。
warnings.warn(f'Error checking compiler version for {compiler}: {error}')
building 'add2' extension
Emitting ninja build file D:\git-bash\daima\NN-CUDA-Example\build\temp.win-amd64-3.8\Release\build.ninja...
Compiling objects...
Allowing ninja to set a default number of workers... (overridable by setting the environment variable MAX_JOBS=N)
1.10.2.git.kitware.jobserver-1
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:D:\miniconda3\envs\torch-gpu\lib\site-
packages\torch\lib "/LIBPATH:C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\lib/x64" /LIBPATH:D:\miniconda3\envs\torch-gpu\libs /LIBPATH:D:\miniconda3\envs\torch-gpu\PCbuild\amd64 "/LIBPATH:C:\Program Files (x86)\Microsoft
Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\lib\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.10240.0\ucrt\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\8.1\lib\winv6.3\um\x64" c10.lib torch.lib tor
ch_cpu.lib torch_python.lib cudart.lib c10_cuda.lib torch_cuda_cu.lib torch_cuda_cpp.lib /EXPORT:PyInit_add2 D:\git-bash\daima\NN-CUDA-Example\build\temp.win-amd64-3.8\Release\pytorch/add2_ops.obj D:\git-bash\daima\NN-CUDA-Example\b
uild\temp.win-amd64-3.8\Release\kernel/add2_kernel.obj /OUT:build\lib.win-amd64-3.8\add2.cp38-win_amd64.pyd /IMPLIB:D:\git-bash\daima\NN-CUDA-Example\build\temp.win-amd64-3.8\Release\pytorch\add2.cp38-win_amd64.lib
LINK : fatal error LNK1181: 无法打开输入文件“D:\git-bash\daima\NN-CUDA-Example\build\temp.win-amd64-3.8\Release\pytorch\add2_ops.obj”
error: command 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\link.exe' failed with exit status 1181

The environment configuration is as follows:
pytorch1.8.1+cuda11.1
python3.8

How to solve this problem?

阳神能不能帮我看看为什么编译失败报错RuntimeError: Error building extension 'add2',后面这句不理解fatal error: add2.h: No such file or directory

我在Jupiter notebook里运行下面jit命令的编译报错如下
python3 time.py --compiler jit

Using /tmp/torch_extensions as PyTorch extensions root...
Detected CUDA files, patching ldflags
Emitting ninja build file /tmp/torch_extensions/add2/build.ninja...
Building extension module add2...
[1/2] c++ -MMD -MF add2_ops.o.d -DTORCH_EXTENSION_NAME=add2 -DTORCH_API_INCLUDE_EXTENSION_H -I/gby/NN-CUDA-Example-master/pytorch/include -isystem /usr/local/lib/python3.6/dist-packages/torch/include -isystem /usr/local/lib/python3.6/dist-packages/torch/include/torch/csrc/api/include -isystem /usr/local/lib/python3.6/dist-packages/torch/include/TH -isystem /usr/local/lib/python3.6/dist-packages/torch/include/THC -isystem /usr/local/cuda/include -isystem /usr/include/python3.6m -D_GLIBCXX_USE_CXX11_ABI=0 -fPIC -std=c++11 -c /gby/NN-CUDA-Example-master/pytorch/add2_ops.cpp -o add2_ops.o
FAILED: add2_ops.o
c++ -MMD -MF add2_ops.o.d -DTORCH_EXTENSION_NAME=add2 -DTORCH_API_INCLUDE_EXTENSION_H -I/gby/NN-CUDA-Example-master/pytorch/include -isystem /usr/local/lib/python3.6/dist-packages/torch/include -isystem /usr/local/lib/python3.6/dist-packages/torch/include/torch/csrc/api/include -isystem /usr/local/lib/python3.6/dist-packages/torch/include/TH -isystem /usr/local/lib/python3.6/dist-packages/torch/include/THC -isystem /usr/local/cuda/include -isystem /usr/include/python3.6m -D_GLIBCXX_USE_CXX11_ABI=0 -fPIC -std=c++11 -c /gby/NN-CUDA-Example-master/pytorch/add2_ops.cpp -o add2_ops.o
/gby/NN-CUDA-Example-master/pytorch/add2_ops.cpp:2:10: fatal error: add2.h: No such file or directory
#include "add2.h"
^~~~~~~~
compilation terminated.
ninja: build stopped: subcommand failed.
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/torch/utils/cpp_extension.py", line 960, in _build_extension_module
check=True)
File "/usr/lib/python3.6/subprocess.py", line 438, in run
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['ninja', '-v']' returned non-zero exit status 1.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "time.py", line 56, in
verbose=True)
File "/usr/local/lib/python3.6/dist-packages/torch/utils/cpp_extension.py", line 658, in load
is_python_module)
File "/usr/local/lib/python3.6/dist-packages/torch/utils/cpp_extension.py", line 827, in _jit_compile
with_cuda=with_cuda)
File "/usr/local/lib/python3.6/dist-packages/torch/utils/cpp_extension.py", line 880, in _write_ninja_file_and_build
_build_extension_module(name, build_directory, verbose)
File "/usr/local/lib/python3.6/dist-packages/torch/utils/cpp_extension.py", line 973, in _build_extension_module
raise RuntimeError(message)
RuntimeError: Error building extension 'add2'

运行下面cmake命令的编译报错如下
Traceback (most recent call last):
File "time.py", line 60, in
torch.ops.load_library("build/libadd2.so")
File "/usr/local/lib/python3.6/dist-packages/torch/_ops.py", line 106, in load_library
ctypes.CDLL(path)
File "/usr/lib/python3.6/ctypes/init.py", line 348, in init
self._handle = _dlopen(self._name, mode)
OSError: /gby/NN-CUDA-Example-master/pytorch/build/libadd2.so: cannot open shared object file: No such file or directory

Cmake error,other 2 compile methods succeeded

Checking whether the CUDA compiler is NVIDIA using "" did not match "nvcc: NVIDIA (R) Cuda compiler driver":
Checking whether the CUDA compiler is Clang using "" did not match "(clang version)":
Compiling the CUDA compiler identification source file "CMakeCUDACompilerId.cu" failed.
Compiler: /usr/local/cuda/bin/nvcc
Build flags:
Id flags: -v

The output was:
No such file or directory

Compiling the CUDA compiler identification source file "CMakeCUDACompilerId.cu" failed.
Compiler: /usr/local/cuda/bin/nvcc
Build flags:
Id flags: -v

The output was:
No such file or directory

Checking whether the CUDA compiler is NVIDIA using "" did not match "nvcc: NVIDIA (R) Cuda compiler driver":
Checking whether the CUDA compiler is Clang using "" did not match "(clang version)":
Checking whether the CUDA compiler is NVIDIA using "" did not match "nvcc: NVIDIA (R) Cuda compiler driver":
Checking whether the CUDA compiler is Clang using "" did not match "(clang version)":
Checking whether the CUDA compiler is NVIDIA using "" did not match "nvcc: NVIDIA (R) Cuda compiler driver":
Checking whether the CUDA compiler is Clang using "" did not match "(clang version)":
Compiling the CUDA compiler identification source file "CMakeCUDACompilerId.cu" failed.
Compiler: /usr/local/cuda/bin/nvcc
Build flags:
Id flags: -v

The output was:
No such file or directory

Compiling the CUDA compiler identification source file "CMakeCUDACompilerId.cu" failed.
Compiler: /usr/local/cuda/bin/nvcc
Build flags:
Id flags: -v

The output was:
No such file or directory

Checking whether the CUDA compiler is NVIDIA using "" did not match "nvcc: NVIDIA (R) Cuda compiler driver":
Checking whether the CUDA compiler is Clang using "" did not match "(clang version)":
Checking whether the CUDA compiler is NVIDIA using "" did not match "nvcc: NVIDIA (R) Cuda compiler driver":
Checking whether the CUDA compiler is Clang using "" did not match "(clang version)":
Checking whether the CUDA compiler is NVIDIA using "" did not match "nvcc: NVIDIA (R) Cuda compiler driver":
Checking whether the CUDA compiler is Clang using "" did not match "(clang version)":
Compiling the CUDA compiler identification source file "CMakeCUDACompilerId.cu" failed.
Compiler: /usr/local/cuda/bin/nvcc
Build flags:
Id flags: -v

The output was:
No such file or directory

Compiling the CUDA compiler identification source file "CMakeCUDACompilerId.cu" failed.
Compiler: /usr/local/cuda/bin/nvcc
Build flags:
Id flags: -v

The output was:
No such file or directory

Checking whether the CUDA compiler is NVIDIA using "" did not match "nvcc: NVIDIA (R) Cuda compiler driver":
Checking whether the CUDA compiler is Clang using "" did not match "(clang version)":
Checking whether the CUDA compiler is NVIDIA using "" did not match "nvcc: NVIDIA (R) Cuda compiler driver":
Checking whether the CUDA compiler is Clang using "" did not match "(clang version)":
Checking whether the CUDA compiler is NVIDIA using "" did not match "nvcc: NVIDIA (R) Cuda compiler driver":
Checking whether the CUDA compiler is Clang using "" did not match "(clang version)":
Compiling the CUDA compiler identification source file "CMakeCUDACompilerId.cu" failed.
Compiler: /usr/local/cuda/bin/nvcc
Build flags:
Id flags: -v

The output was:
No such file or directory

Compiling the CUDA compiler identification source file "CMakeCUDACompilerId.cu" failed.
Compiler: /usr/local/cuda/bin/nvcc
Build flags:
Id flags: -v

The output was:
No such file or directory

Checking whether the CUDA compiler is NVIDIA using "" did not match "nvcc: NVIDIA (R) Cuda compiler driver":
Checking whether the CUDA compiler is Clang using "" did not match "(clang version)":
Checking whether the CUDA compiler is NVIDIA using "" did not match "nvcc: NVIDIA (R) Cuda compiler driver":
Checking whether the CUDA compiler is Clang using "" did not match "(clang version)":
Performing C++ SOURCE FILE Test CMAKE_HAVE_LIBC_PTHREAD failed with the following output:
Change Dir: /data/jupyter/cuda_learn/NN-CUDA-Example/build/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/make -f Makefile cmTC_6d839/fast && /usr/bin/make -f CMakeFiles/cmTC_6d839.dir/build.make CMakeFiles/cmTC_6d839.dir/build
make[1]: Entering directory '/data/jupyter/cuda_learn/NN-CUDA-Example/build/CMakeFiles/CMakeTmp'
Building CXX object CMakeFiles/cmTC_6d839.dir/src.cxx.o
/usr/bin/c++ -DCMAKE_HAVE_LIBC_PTHREAD -o CMakeFiles/cmTC_6d839.dir/src.cxx.o -c /data/jupyter/cuda_learn/NN-CUDA-Example/build/CMakeFiles/CMakeTmp/src.cxx
Linking CXX executable cmTC_6d839
/home/huyang02/anaconda3/lib/python3.6/site-packages/cmake/data/bin/cmake -E cmake_link_script CMakeFiles/cmTC_6d839.dir/link.txt --verbose=1
/usr/bin/c++ -rdynamic CMakeFiles/cmTC_6d839.dir/src.cxx.o -o cmTC_6d839
CMakeFiles/cmTC_6d839.dir/src.cxx.o: In function main': src.cxx:(.text+0x3e): undefined reference to pthread_create'
src.cxx:(.text+0x4a): undefined reference to pthread_detach' src.cxx:(.text+0x56): undefined reference to pthread_cancel'
src.cxx:(.text+0x67): undefined reference to pthread_join' src.cxx:(.text+0x7b): undefined reference to pthread_atfork'
collect2: error: ld returned 1 exit status
CMakeFiles/cmTC_6d839.dir/build.make:98: recipe for target 'cmTC_6d839' failed
make[1]: *** [cmTC_6d839] Error 1
make[1]: Leaving directory '/data/jupyter/cuda_learn/NN-CUDA-Example/build/CMakeFiles/CMakeTmp'
Makefile:127: recipe for target 'cmTC_6d839/fast' failed
make: *** [cmTC_6d839/fast] Error 2

Source file was:
#include <pthread.h>

static void* test_func(void* data)
{
return data;
}

int main(void)
{
pthread_t thread;
pthread_create(&thread, NULL, test_func, NULL);
pthread_detach(thread);
pthread_cancel(thread);
pthread_join(thread, NULL);
pthread_atfork(NULL, NULL, NULL);
pthread_exit(NULL);

return 0;
}

Determining if the function pthread_create exists in the pthreads failed with the following output:
Change Dir: /data/jupyter/cuda_learn/NN-CUDA-Example/build/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/make -f Makefile cmTC_308c5/fast && /usr/bin/make -f CMakeFiles/cmTC_308c5.dir/build.make CMakeFiles/cmTC_308c5.dir/build
make[1]: Entering directory '/data/jupyter/cuda_learn/NN-CUDA-Example/build/CMakeFiles/CMakeTmp'
Building CXX object CMakeFiles/cmTC_308c5.dir/CheckFunctionExists.cxx.o
/usr/bin/c++ -DCHECK_FUNCTION_EXISTS=pthread_create -o CMakeFiles/cmTC_308c5.dir/CheckFunctionExists.cxx.o -c /data/jupyter/cuda_learn/NN-CUDA-Example/build/CMakeFiles/CheckLibraryExists/CheckFunctionExists.cxx
Linking CXX executable cmTC_308c5
/home/huyang02/anaconda3/lib/python3.6/site-packages/cmake/data/bin/cmake -E cmake_link_script CMakeFiles/cmTC_308c5.dir/link.txt --verbose=1
/usr/bin/c++ -DCHECK_FUNCTION_EXISTS=pthread_create -rdynamic CMakeFiles/cmTC_308c5.dir/CheckFunctionExists.cxx.o -o cmTC_308c5 -lpthreads
/usr/bin/ld: cannot find -lpthreads
collect2: error: ld returned 1 exit status
CMakeFiles/cmTC_308c5.dir/build.make:98: recipe for target 'cmTC_308c5' failed
make[1]: *** [cmTC_308c5] Error 1
make[1]: Leaving directory '/data/jupyter/cuda_learn/NN-CUDA-Example/build/CMakeFiles/CMakeTmp'
Makefile:127: recipe for target 'cmTC_308c5/fast' failed
make: *** [cmTC_308c5/fast] Error 2

博客

大佬,
你后面两篇博客文章挂了,我想在pytorch中学习一些cuda编程知识,大佬有什么资料推荐么?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.