Introduce libtorch to setup.py build#8792
Introduce libtorch to setup.py build#8792anderspapitto wants to merge 2 commits intopytorch:masterfrom
Conversation
1f7bcc0 to
88b0f78
Compare
torch/CMakeLists.txt
Outdated
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
setup.py
Outdated
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
28de5e5 to
98c6a0a
Compare
98c6a0a to
d4c7bb3
Compare
.jenkins/pytorch/build.sh
Outdated
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
aten/CMakeLists.txt
Outdated
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
torch/CMakeLists.txt
Outdated
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
torch/CMakeLists.txt
Outdated
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
78b6a9f to
3933272
Compare
6965cde to
8b1d5cb
Compare
274f619 to
07c01b9
Compare
facebook-github-bot
left a comment
There was a problem hiding this comment.
@ezyang has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
|
build failures look legit |
|
This diff is ready for another round of review. I highlight two points of potential concern.
This is particularly annoying because I did fix legit ROCM issues along the way, so I would like to get a clear signal that everything is now correct. However, my initial feeling is that fixing these infra-level resource issues is outside the scope of this diff.
In this diff, I've addressed this issue by moving all the relevant thread_local global variables out of the header files, and instead exposing accessor methods across the shared-object boundary. I'm concerned that this may be a perf problem, if function call overhead is too high a cost to pay to access these profiling-related variables. So, is this a problem, and if so is there a suggested alternative approach? @ezyang @goldsborough as existing reviewers (also please bring in anyone else with relevant knowledge. E.g. I'm not sure who is most familiar with the profiling code.) edit: also @Jorghi12 regarding the ROCM tests |
facebook-github-bot
left a comment
There was a problem hiding this comment.
@anderspapitto has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
goldsborough
left a comment
There was a problem hiding this comment.
Curious about some things, especially the newly disabled warnings
|
|
||
| #include <ATen/ATen.h> | ||
|
|
||
| #include "torch/csrc/WindowsTorchApiMacro.h" |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| thread_local uint64_t Function::next_sequence_nr_ = 0; | ||
| /// Monotonically incrementing (thread local!) counter to supply sequence | ||
| /// numbers. | ||
| thread_local uint64_t Function_next_sequence_nr_ = 0; |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| getEventList().record(EventKind::PopRange, std::string(), thread_id, state == ProfilerState::CUDA); | ||
| } | ||
| } | ||
| RangeEventList& getEventList(); |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
|
|
||
| py::class_<torch::autograd::profiler::Event>(m,"ProfilerEvent") | ||
| .def("kind",&torch::autograd::profiler::Event::kind) | ||
| .def("name",&torch::autograd::profiler::Event::name) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| namespace torch { namespace autograd { | ||
|
|
||
| struct GradMode { | ||
| static bool is_enabled() { |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
torch/CMakeLists.txt
Outdated
| # This is required for Python 2 declarations that are deprecated | ||
| # in 3. | ||
| -Wno-deprecated-declarations | ||
| # Python 2.6 requires -fno-strict-aliasing see |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
torch/CMakeLists.txt
Outdated
| -Wno-unused-parameter | ||
| -Wno-missing-field-initializers | ||
| -Wno-write-strings | ||
| # -Wno-zero-length-array |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
torch/CMakeLists.txt
Outdated
|
|
||
| if (APPLE) | ||
| target_compile_options(test_api PRIVATE | ||
| -Wno-error=unknown-warning-option |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
aten/src/ATen/ATenGeneral.h
Outdated
|
|
||
| #ifdef _WIN32 | ||
| # if defined(ATen_cpu_EXPORTS) || defined(caffe2_EXPORTS) | ||
| # if defined(torch_EXPORTS) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
setup.py
Outdated
|
|
||
| # we specify exact lib names to avoid conflict with lua-torch installs | ||
| CAFFE2_LIBS = [os.path.join(lib_path, 'libcaffe2.so')] | ||
| CAFFE2_LIBS = [os.path.join(lib_path, 'libcaffe2.so'), os.path.join(lib_path, 'libtorch.so')] |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| virtual at::Tensor unsafeTensorFromTH(void * th_pointer, bool retain) const override; | ||
|
|
||
| static at::Type* getType(const at::Type& baseType); | ||
| TORCH_API static at::Type* getType(const at::Type& baseType); |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| -DBUILD_CAFFE2=OFF ^ | ||
| -DBUILD_TORCH="%BUILD_TORCH%" ^ | ||
| -DNVTOOLEXT_HOME="%NVTOOLEXT_HOME%" ^ | ||
| -DNO_API=ON ^ |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| target_compile_options(torch PRIVATE -Werror) | ||
| endif() | ||
|
|
||
| if (MSVC) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
|
Would it be possible to get a detailed break down of the semantic changes that were made in plain English? E.g., something similar to the comment at #9358 ; it will help us reviewers out a lot. |
| endif() | ||
|
|
||
| if(MSVC OR APPLE) | ||
| target_link_libraries(torch caffe2_gpu_library ${TORCH_CUDA_LIBRARIES}) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| if (TORCH_BUILD_TEST) | ||
| # JIT Tests. TODO: Put into test/cpp/jit folder | ||
|
|
||
| # JIT Tests. TODO: Put into test/cpp/jit folder |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
torch/CMakeLists.txt
Outdated
| endif() | ||
|
|
||
| target_link_libraries(test_api torch) | ||
| if (NOT NO_API AND NOT USE_ROCM) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
facebook-github-bot
left a comment
There was a problem hiding this comment.
@anderspapitto has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
facebook-github-bot
left a comment
There was a problem hiding this comment.
@anderspapitto has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
facebook-github-bot
left a comment
There was a problem hiding this comment.
@anderspapitto has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
setup.py now compiles libtorch.so via CMake, and _C.so takes a dependency on libtorch.so. Most cpp files that were previously built directly into _C.so have been removed from _C.so and added to libtorch.so.
facebook-github-bot
left a comment
There was a problem hiding this comment.
@anderspapitto has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
|
@anderspapitto I'm using the PyTorch C++ API in csrc/api, and I used to rely on ./build_all.sh to build the libs before linking (in open source). However, this PR got rid of that, and the command seems quite cumbersome: Any chance it could be brought back and supported in the tests again so it does not break? |
Prior to this diff, there have been two ways of compiling the bulk of the torch codebase. There was no interaction between them - you had to pick one or the other.
This diff combines the two.
In terms of code changes, this mostly means extending the cmake build to support the full variety of environments and platforms. There are also a small number of changes related to the fact that there are now two shared objects - in particular, windows requires annotating some symbols with dllimport/dllexport, and doesn't allow exposing thread_local globals directly.