Skip to content

Commit

Permalink
fix CPU only build with memman
Browse files Browse the repository at this point in the history
  • Loading branch information
chrischoy committed May 20, 2020
1 parent 1ddf529 commit be5c3c1
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 18 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Change Log

## [master] - 2020-05-07
## [master] - 2020-05-19

### Changed

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ We visualized a sparse tensor network operation on a sparse tensor, convolution,

- Ubuntu 14.04 or higher
- CUDA 10.1 or higher
- pytorch 1.3 or higher
- pytorch 1.5 or higher
- python 3.6 or higher
- GCC 7 or higher

Expand Down
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ def _argparse(pattern, argv, is_flag=True):

# extra_compile_args+=['-g'] # Uncomment for debugging
if CPU_ONLY and not FORCE_CUDA:
print("\nCPU_ONLY build set")
print("--------------------------------")
print("| WARNING: CPU_ONLY build set |")
print("--------------------------------")
compile_args += ["CPU_ONLY=1"]
extra_compile_args += ["-DCPU_ONLY"]
Extension = CppExtension
Expand Down
18 changes: 9 additions & 9 deletions src/coords_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,18 +122,18 @@ template <typename MapType = CoordsToIndexMap> class CoordsManager {
unordered_map<InOutMapKey, InOutMaps<int>, InOutMapKeyHash> in_maps;
unordered_map<InOutMapKey, InOutMaps<int>, InOutMapKeyHash> out_maps;

CoordsManager(){
gpu_memory_manager = std::make_shared<GPUMemoryManager>();
};
CoordsManager(int num_threads) {
omp_set_dynamic(0);
omp_set_num_threads(num_threads);
}
CoordsManager(int num_threads, MemoryManagerBackend backend) {
omp_set_dynamic(0);
omp_set_num_threads(num_threads);
if (num_threads > 0) {
omp_set_dynamic(0);
omp_set_num_threads(num_threads);
}
#ifndef CPU_ONLY
gpu_memory_manager = std::make_shared<GPUMemoryManager>(backend);
#endif
}
CoordsManager(int num_threads): CoordsManager(num_threads, PYTORCH) {}
CoordsManager(): CoordsManager(-1, PYTORCH) {}

~CoordsManager() { clear(); }

void printDiagnostics(py::object py_coords_key) const;
Expand Down
2 changes: 0 additions & 2 deletions src/gpu_memory_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ namespace minkowski {

using std::vector;

enum MemoryManagerBackend { CUDA = 0, PYTORCH = 1 };

class GPUMemoryManager {
private:
int initial_size = 256;
Expand Down
3 changes: 3 additions & 0 deletions src/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ using InOutMapsRefPair = pair<InOutMaps<Itype> &, InOutMaps<Itype> &>;
template <typename Itype>
using pInOutMapsRefPair = pair<pInOutMaps<Itype> &, pInOutMaps<Itype> &>;

// GPU memory manager backend. No effect with CPU_ONLY build
enum MemoryManagerBackend { CUDA = 0, PYTORCH = 1 };

// FNV64-1a
// uint64_t for unsigned long, must use CXX -m64
template <typename T> uint64_t hash_vec(T p) {
Expand Down
11 changes: 7 additions & 4 deletions tests/coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,14 @@ def test_batch_size_initialize(self):
self.assertTrue(cm.get_batch_size() == 2)

def test_memory_manager_backend(self):
CoordsManager(memory_manager_backend=MemoryManagerBackend.CUDA, D=2)
CoordsManager(memory_manager_backend=MemoryManagerBackend.PYTORCH, D=2)

# Set the global GPU memory manager backend. By default PYTORCH.
ME.set_memory_manager_backend(MemoryManagerBackend.PYTORCH)
CoordsManager(D=2)
ME.set_memory_manager_backend(MemoryManagerBackend.CUDA)

# Create a coords man with the specified GPU memory manager backend.
# No effect with CPU_ONLY build
cm = CoordsManager(memory_manager_backend=MemoryManagerBackend.CUDA, D=2)
cm = CoordsManager(memory_manager_backend=MemoryManagerBackend.PYTORCH, D=2)


if __name__ == '__main__':
Expand Down

0 comments on commit be5c3c1

Please sign in to comment.