-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Compile torch extension in setup.py (#216)
* Compile torch extension in setup.py * Fix extension library discovery * Make CI more verbose * Install gxx from conda-forge to ensure ABI compatibility * Change extension name so it does not collide with NNPOps
- Loading branch information
1 parent
ac16c09
commit eeaa20f
Showing
4 changed files
with
38 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,4 @@ dependencies: | |
- pytest | ||
- psutil | ||
- ninja | ||
- gxx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,14 @@ | ||
import os | ||
import os.path as osp | ||
import torch | ||
from torch.utils import cpp_extension | ||
|
||
def compile_extension(): | ||
src_dir = os.path.dirname(__file__) | ||
sources = ["neighbors.cpp", "neighbors_cpu.cpp"] + ( | ||
["neighbors_cuda.cu"] if torch.cuda.is_available() else [] | ||
) | ||
sources = [os.path.join(src_dir, name) for name in sources] | ||
cpp_extension.load( | ||
name="torchmdnet_neighbors", sources=sources, is_python_module=False | ||
) | ||
|
||
compile_extension() | ||
import importlib.machinery | ||
library = "torchmdnet_neighbors" | ||
# Find the specification for the library | ||
spec = importlib.machinery.PathFinder().find_spec( | ||
library, [osp.dirname(__file__)] | ||
) | ||
# Check if the specification is found and load the library | ||
if spec is not None: | ||
torch.ops.load_library(spec.origin) | ||
else: | ||
raise ImportError(f"Could not find module '{library}' in {osp.dirname(__file__)}") | ||
get_neighbor_pairs_kernel = torch.ops.torchmdnet_neighbors.get_neighbor_pairs |