Skip to content

Commit eee47ee

Browse files
committed
metis support optional
1 parent 0a659cd commit eee47ee

File tree

5 files changed

+23
-8
lines changed

5 files changed

+23
-8
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,20 @@ $ echo $CPATH
5959
>>> /usr/local/cuda/include:...
6060
```
6161

62-
Afterwards, download and install the [METIS library](http://glaros.dtc.umn.edu/gkhome/metis/metis/download) by following the instructions in the `Install.txt` file.
62+
If you want to additionally build `torch-sparse` with METIS support, *e.g.* for partioning, please download and install the [METIS library](http://glaros.dtc.umn.edu/gkhome/metis/metis/download) by following the instructions in the `Install.txt` file.
63+
Afterwards, set the environment variable `WITH_METIS=1`.
6364

6465
Then run:
6566

6667
```
6768
pip install torch-scatter torch-sparse
6869
```
6970

70-
When running in a docker container without nvidia driver, PyTorch needs to evaluate the compute capabilities and may fail.
71+
When running in a docker container without NVIDIA driver, PyTorch needs to evaluate the compute capabilities and may fail.
7172
In this case, ensure that the compute capabilities are set via `TORCH_CUDA_ARCH_LIST`, *e.g.*:
7273

7374
```
74-
export TORCH_CUDA_ARCH_LIST = "6.0 6.1 7.2+PTX 7.5+PTX"
75+
export TORCH_CUDA_ARCH_LIST="6.0 6.1 7.2+PTX 7.5+PTX"
7576
```
7677

7778
## Functions

csrc/cpu/metis_cpu.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
#include "metis_cpu.h"
22

3+
#ifdef WITH_METIS
34
#include <metis.h>
5+
#endif
46

57
#include "utils.h"
68

79
torch::Tensor partition_cpu(torch::Tensor rowptr, torch::Tensor col,
810
int64_t num_parts, bool recursive) {
11+
#ifdef WITH_METIS
912
CHECK_CPU(rowptr);
1013
CHECK_CPU(col);
1114

1215
int64_t nvtxs = rowptr.numel() - 1;
16+
auto part = torch::empty(nvtxs, rowptr.options());
17+
1318
auto *xadj = rowptr.data_ptr<int64_t>();
1419
auto *adjncy = col.data_ptr<int64_t>();
1520
int64_t ncon = 1;
1621
int64_t objval = -1;
17-
auto part = torch::empty(nvtxs, rowptr.options());
1822
auto part_data = part.data_ptr<int64_t>();
1923

2024
if (recursive) {
@@ -26,4 +30,7 @@ torch::Tensor partition_cpu(torch::Tensor rowptr, torch::Tensor col,
2630
}
2731

2832
return part;
33+
#else
34+
AT_ERROR("Not compiled with METIS support");
35+
#endif
2936
}

csrc/metis.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33

44
#include "cpu/metis_cpu.h"
55

6-
#include <metis.h>
7-
86
#ifdef _WIN32
9-
PyMODINIT_FUNC PyInit__metis_wrapper(void) { return NULL; }
7+
PyMODINIT_FUNC PyInit__metis(void) { return NULL; }
108
#endif
119

1210
torch::Tensor partition(torch::Tensor rowptr, torch::Tensor col,

script/metis.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/bin/bash
22

33
METIS=metis-5.1.0
4+
export WITH_METIS=1
45

56
wget -nv http://glaros.dtc.umn.edu/gkhome/fetch/sw/metis/${METIS}.tar.gz
67
tar -xvzf ${METIS}.tar.gz

setup.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,18 @@
1616

1717
BUILD_DOCS = os.getenv('BUILD_DOCS', '0') == '1'
1818

19+
WITH_METIS = False
20+
if os.getenv('WITH_METIS', '0') == '1':
21+
WITH_METIS = True
22+
1923

2024
def get_extensions():
2125
Extension = CppExtension
2226
define_macros = []
27+
libraries = []
28+
if WITH_METIS:
29+
define_macros += [('WITH_METIS', None)]
30+
libraries += ['metis']
2331
extra_compile_args = {'cxx': []}
2432
extra_link_args = []
2533

@@ -59,7 +67,7 @@ def get_extensions():
5967
define_macros=define_macros,
6068
extra_compile_args=extra_compile_args,
6169
extra_link_args=extra_link_args,
62-
libraries=['metis'],
70+
libraries=libraries,
6371
)
6472
extensions += [extension]
6573

0 commit comments

Comments
 (0)