Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom C++ extension : torch/torch.h not found #22

Closed
adarsh-kr opened this issue Nov 13, 2018 · 8 comments
Closed

Custom C++ extension : torch/torch.h not found #22

adarsh-kr opened this issue Nov 13, 2018 · 8 comments

Comments

@adarsh-kr
Copy link

adarsh-kr commented Nov 13, 2018

I am following this tutorial to create a C++ extension for Pytorch. My C++ code is giving following error :

test.cpp:3:10: fatal error: torch/torch.h: No such file or directory
 #include <torch/torch.h>


How to get torch.h header file ? Is there some pytorch-dev version ?

@goldsborough
Copy link
Contributor

Hi, please provide more information about your environment. What version of PyTorch are you using?

@adarsh-kr
Copy link
Author

adarsh-kr commented Nov 13, 2018

I am using torch==0.4.1.
I was initially running g++ compressionLayer.cc which gave me the above mentioned error.

I located the torch.h file and added the path during compilation.
g++ -I /home/adarsh/.local/lib/python3.6/site-packages/torch/lib/include/ compressionLayer.cc, which compiled but then I am getting following error :

/tmp/ccIqciqg.o: In function `at::infer_type(at::Tensor const&)':
compressionLayer.cc:(.text+0x241): undefined reference to `at::Error::Error(at::SourceLocation, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
/tmp/ccIqciqg.o: In function `at::UndefinedTensor::singleton()':
compressionLayer.cc:(.text._ZN2at15UndefinedTensor9singletonEv[_ZN2at15UndefinedTensor9singletonEv]+0x7): undefined reference to `at::UndefinedTensor::_singleton'
collect2: error: ld returned 1 exit status
Makefile:6: recipe for target 'compressionLayer.o' failed
make: *** [compressionLayer.o] Error 1

CompressionLayer.cc is this :

#include<torch/torch.h>
#include<iostream>

at::Tensor d_sigmoid(at::Tensor z) {
        at::Tensor  s = at::sigmoid(z);
        return (1 - s) * s;
}
int main()
{}

@goldsborough
Copy link
Contributor

What commands did you run to arrive at this compiler error? Please provide as much context as possible for me to help.

@adarsh-kr
Copy link
Author

@goldsborough I have added all the info in the above comment. Please let me know if you have any questions.

@goldsborough
Copy link
Contributor

You are not supposed to compile this code manually like this. Have you seen the setup.py and torch.utils.cpp_extensions.load instructions in the tutorial? I think it is explained quite well how to build an extension using the means we provide.

@adarsh-kr
Copy link
Author

adarsh-kr commented Nov 13, 2018

Can u pls tell me how build to this ?

@goldsborough
Copy link
Contributor

It is explained in the tutorial here: https://pytorch.org/tutorials/advanced/cpp_extension.html#building-with-setuptools

@adarsh-kr
Copy link
Author

My bad. I skipped that.
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants