Detectron.pytorch
Detectron.pytorch copied to clipboard
Compile the CUDA code on Win10/Win7
Has anyone successfully complied the CUDA code on Windows?
I do not know how to compile it on Windows.
I have compiled it as follows:
- Compile each cu file :
nvcc -c -o xxxx.cu.o xxxx.cu -D GOOGLE_CUDA=1 -x cu -Xcompiler -MD
- modify each xxxx_cuda.c add:
#include <ATen/ATen.h>
//extern THCState *state;
THCState *state = at::globalContext().thc_state;
extern "C" {
...
}
save it as: xxxx_cuda.cpp
- modify each xxxx.c (e.g. roi_pooling.c) add:
#include <ATen/ATen.h>
extern "C" {
...
}
save it as: xxxx.cpp
- modify build.py
- change xxx.c to xxx.cpp
- add
libraries=["ATen", '_C', 'cudart']
to the args of create_extension
- run
python build.py
(my environment: Win10 and cuda V9.0) see also: https://pytorch.org/docs/stable/notes/windows.html#cffi-extension
Hello, thank you for your instructions. I've tried on my side but I have a fatal error LNK1181: cannot open input file 'ATen.lib'. Any idea ?
@hirotomusiker hi, after following your guidance, I got some errors, mainly with status 2:
Traceback (most recent call last): File "C:\Users\ming-04\Anaconda3\lib\distutils_msvccompiler.py", line 423, in compile self.spawn(args) File "C:\Users\ming-04\Anaconda3\lib\distutils_msvccompiler.py", line 542, in spawn return super().spawn(cmd) File "C:\Users\ming-04\Anaconda3\lib\distutils\ccompiler.py", line 909, in spawn spawn(cmd, dry_run=self.dry_run) File "C:\Users\ming-04\Anaconda3\lib\distutils\spawn.py", line 38, in spawn _spawn_nt(cmd, search_path, dry_run=dry_run) File "C:\Users\ming-04\Anaconda3\lib\distutils\spawn.py", line 81, in _spawn_nt "command %r failed with exit status %d" % (cmd, rc)) distutils.errors.DistutilsExecError: command 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.10.25017\bin\HostX86\x64\cl.exe' failed with exit status 2 During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Users\ming-04\Anaconda3\lib\site-packages\cffi\ffiplatform.py", line 51, in _build dist.run_command('build_ext') File "C:\Users\ming-04\Anaconda3\lib\distutils\dist.py", line 985, in run_command cmd_obj.run() File "C:\Users\ming-04\Anaconda3\lib\site-packages\setuptools\command\build_ext.py", line 87, in run _build_ext.run(self) File "C:\Users\ming-04\Anaconda3\lib\site-packages\Cython\Distutils\old_build_ext.py", line 186, in run _build_ext.build_ext.run(self) File "C:\Users\ming-04\Anaconda3\lib\distutils\command\build_ext.py", line 339, in run self.build_extensions() File "C:\Users\ming-04\Anaconda3\lib\site-packages\Cython\Distutils\old_build_ext.py", line 194, in build_extensions self.build_extension(ext) File "C:\Users\ming-04\Anaconda3\lib\site-packages\setuptools\command\build_ext.py", line 208, in build_extension build_ext.build_extension(self, ext) File "C:\Users\ming-04\Anaconda3\lib\distutils\command\build_ext.py", line 533, in build_extension depends=ext.depends) File "C:\Users\ming-04\Anaconda3\lib\distutils_msvccompiler.py", line 425, in compile raise CompileError(msg) distutils.errors.CompileError: command 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.10.25017\bin\HostX86\x64\cl.exe' failed with exit status 2 During handling of the above exception, another exception occurred: Traceback (most recent call last): File "build.py", line 39, in
ffi.build() File "C:\Users\ming-04\Anaconda3\lib\site-packages\torch\utils\ffi_init .py", line 189, in build build_extension(ffi, cffi_wrapper_name, target_dir, verbose) File "C:\Users\ming-04\Anaconda3\lib\site-packages\torch\utils\ffi_init.py", line 111, in _build_extension outfile = ffi.compile(tmpdir=tmpdir, verbose=verbose, target=libname) File "C:\Users\ming-04\Anaconda3\lib\site-packages\cffi\api.py", line 697, in compile compiler_verbose=verbose, debug=debug, **kwds) File "C:\Users\ming-04\Anaconda3\lib\site-packages\cffi\recompiler.py", line 1520, in recompile compiler_verbose, debug) File "C:\Users\ming-04\Anaconda3\lib\site-packages\cffi\ffiplatform.py", line 22, in compile outputfilename = _build(tmpdir, ext, compiler_verbose, debug) File "C:\Users\ming-04\Anaconda3\lib\site-packages\cffi\ffiplatform.py", line 58, in _build raise VerificationError('%s: %s' % (e.class.name, e)) cffi.error.VerificationError: CompileError: command 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.10.25017\bin\HostX86\x64\cl.exe' failed with exit status 2
do you have any advice?