Commit 1308d4d
authored
Fix multiple find_package(Torch) calls (pytorch#8407)
While debugging the build issue on pytorch#8322 w.r.t mkl, I undercover a complex interaction between pytorch#8322, pytorch#8248 (to install mkl), and https://github.com/pytorch/pytorch/blob/main/cmake/public/mkl.cmake from PyTorch. The error is as follows:
```
CMake Error at /opt/conda/envs/py_3.10/lib/cmake/mkl/MKLConfig.cmake:744 (add_library): <-- This file comes from conda mkl
add_library cannot create imported target "MKL::MKL" because another target
with the same name already exists.
Call Stack (most recent call first):
/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/share/cmake/Caffe2/public/mkl.cmake:1 (find_package) <-- this is from PyTorch
/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/share/cmake/Caffe2/Caffe2Config.cmake:106 (include)
/opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/share/cmake/Torch/TorchConfig.cmake:68 (find_package)
CMakeLists.txt:753 (find_package)
```
The conclusion is that, with mkl installed, there should be just one `find_package(Torch)` call because the mkl target is defined globally. The `torch` target, on the other hand, is only defined locally.
So, this change adds `if(NOT TARGET torch)` check to only call `find_package(Torch)` if needed.
### Testing
The change on top of pytorch#8322 looks like this pytorch@f705b01
https://github.com/pytorch/executorch/actions/runs/13278590926?pr=83991 parent 012b5e9 commit 1308d4d
File tree
3 files changed
+9
-3
lines changed- build
- extension/llm/custom_ops
3 files changed
+9
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
750 | 750 | | |
751 | 751 | | |
752 | 752 | | |
753 | | - | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
754 | 756 | | |
755 | 757 | | |
756 | 758 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
149 | | - | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
150 | 152 | | |
151 | 153 | | |
152 | 154 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
72 | | - | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
73 | 75 | | |
74 | 76 | | |
75 | 77 | | |
| |||
0 commit comments