Comments (8)
It seems that I compiled PyTorch before the fix.
In [1]: import torch
In [2]: torch.__version__
Out[2]: '0.4.0a0+200fb22'
In [3]: from torch.utils.cpp_extension import BuildExtension
In [4]: import inspect
In [5]: print(inspect.getsource(BuildExtension._define_torch_extension_name))
def _define_torch_extension_name(self, extension):
define = '-DTORCH_EXTENSION_NAME={}'.format(extension.name)
if isinstance(extension.extra_compile_args, dict):
for args in extension.extra_compile_args.values():
args.append(define)
else:
extension.extra_compile_args.append(define)
from extension-cpp.
I actually found a workaround for now. If you want to name your module "foo.bar" you can use the top-level module name foo as the extension name and put the submodule names in the module def(), as shown here:
PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
m.def("bar.myfunction", &myfunction_cuda, "MY_FUNCTION");
}
from extension-cpp.
cc: @goldsborough
from extension-cpp.
Hi @nkolot, this is a known issue with PYBIND11_MODULE
. I thought this was fixed by @fmassa in pytorch/pytorch#6986, where we fixed/hacked it by only making the last part of the dotted extension the actual extension name. I believe setuptools creates the directory structure to still make the extension importable with the full path. Maybe change TORCH_EXTENSION_NAME
to just bar
? Could you try that? @fmassa do you know why this doesn't work after your fix?
from extension-cpp.
@nkolot are you sure you installed PyTorch from source? The fix @goldsborough mentioned is not present in pytorch 0.4 (which is what we have for the binaries)
Also, can you check that your installation has the fix that @goldsborough mentioned?
from extension-cpp.
Yes, PyTorch is compiled from source.
I can confirm that the fix @goldsborough is working.
So in my setup.py file I have
ext_modules = [CUDAExtension('foo.bar', ['bar_cuda.cpp', 'bar_cuda_kernel.cu']),]
and in bar_cuda.cpp
PYBIND11_MODULE(bar, m) {
m.def("myfunc", &my_func, "MY_FUNC");
}
It even works with deeper nesting, i.e. foo.bar.foobar, as long as I put the last part in PYBIND.
from extension-cpp.
Great, thanks for confirming. Think we can close this then.
from extension-cpp.
@nkolot I still didn't quite understand... is pytorch/pytorch#6986 present in your installation? That patch is supposed to be doing what @goldsborough mentioned.
from extension-cpp.
Related Issues (20)
- www.facebook.com/rozi.khatun.961
- This repo can not compile using Pytorch 1.6.0 HOT 1
- This repo can not compile using Pytorch 1.6.0 HOT 1
- A question about backward propagation speed in cpp extension in tutorial
- Error when building cpp extension HOT 1
- AttributeError: module 'depthwise' has no attribute 'forward'
- cuda does not install HOT 17
- How does the layer of C++ extensions translate to TorchScript or onnx? HOT 1
- Cannot Unpack, Too Many Items
- How to debug in cuda-pytorch env?
- Writing a custom C++ extension with variants for both CPU and GPU? HOT 2
- Custom CUDA operator only work well on cuda:0 HOT 3
- How can I access data in cuda kernel like in pytorch?
- error LNK2001 undefined reference to `__cudaRegisterLinkedBinary
- Relation between at::Half and __half
- Deprecation warning
- Scikit-build-core / scikit-build support for binding
- `TORCH_LIBRARY` and `m.def` Not Working as Documented
- [feature request] Instruction on how to setup compile-env for Windows
- JIT-compiling the extension results in non-functional Python module.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from extension-cpp.