From 876d82ad255f90240adaaf7c8a2ca5e8439839fe Mon Sep 17 00:00:00 2001 From: Nicolas Date: Fri, 22 May 2020 09:49:09 +0100 Subject: [PATCH 1/8] Supporting MacOS --- CHANGELOG.md | 5 +++++ cpu/include/neighbors.h | 10 +++++----- cpu/src/ball_query.cpp | 17 +++++++++-------- cpu/src/fps.cpp | 2 +- cpu/src/interpolate.cpp | 4 ++-- cpu/src/knn.cpp | 4 ++-- cpu/src/neighbors.cpp | 11 +++++------ 7 files changed, 29 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eccc6b1..6ffc6c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +# UNRELEASED + +## Bug fix +- CPU version works for MacOS + # 0.6.2 ## Bug fix diff --git a/cpu/include/neighbors.h b/cpu/include/neighbors.h index ce4d27d..1c83851 100644 --- a/cpu/include/neighbors.h +++ b/cpu/include/neighbors.h @@ -9,15 +9,15 @@ using namespace std; template int nanoflann_neighbors(vector& queries, vector& supports, - vector& neighbors_indices, vector& dists, float radius, + vector& neighbors_indices, vector& dists, float radius, int max_num, int mode, bool sorted); template int batch_nanoflann_neighbors(vector& queries, vector& supports, - vector& q_batches, vector& s_batches, - vector& neighbors_indices, vector& dists, float radius, - int max_num, int mode, bool sorted); + vector& q_batches, vector& s_batches, + vector& neighbors_indices, vector& dists, + float radius, int max_num, int mode, bool sorted); template void nanoflann_knn_neighbors(vector& queries, vector& supports, - vector& neighbors_indices, vector& dists, int k); + vector& neighbors_indices, vector& dists, int k); diff --git a/cpu/src/ball_query.cpp b/cpu/src/ball_query.cpp index c9a4777..339ea74 100644 --- a/cpu/src/ball_query.cpp +++ b/cpu/src/ball_query.cpp @@ -15,7 +15,7 @@ std::pair ball_query(at::Tensor support, at::Tensor quer at::Tensor out; at::Tensor out_dists; - std::vector neighbors_indices(query.size(0), 0); + std::vector neighbors_indices(query.size(0), 0); std::vector neighbors_dists(query.size(0), -1); auto options = torch::TensorOptions().dtype(torch::kLong).device(torch::kCPU); @@ -34,7 +34,7 @@ std::pair ball_query(at::Tensor support, at::Tensor quer neighbors_dists, radius, max_num, mode, sorted); }); auto neighbors_dists_ptr = neighbors_dists.data(); - long* neighbors_indices_ptr = neighbors_indices.data(); + int64_t* neighbors_indices_ptr = neighbors_indices.data(); if (mode == 0) { out = @@ -73,7 +73,7 @@ std::pair batch_ball_query(at::Tensor support, at::Tenso at::Tensor idx; at::Tensor dist; - std::vector neighbors_indices; + std::vector neighbors_indices; std::vector neighbors_dists; auto options = torch::TensorOptions().dtype(torch::kLong).device(torch::kCPU); @@ -91,10 +91,11 @@ std::pair batch_ball_query(at::Tensor support, at::Tenso query_batch = at::cat({at::zeros(1, query_batch.options()), query_batch.cumsum(0)}, 0); support_batch = degree(support_batch, batch_size); support_batch = at::cat({at::zeros(1, support_batch.options()), support_batch.cumsum(0)}, 0); - std::vector query_batch_stl(query_batch.DATA_PTR(), - query_batch.DATA_PTR() + query_batch.numel()); - std::vector support_batch_stl(support_batch.DATA_PTR(), - support_batch.DATA_PTR() + support_batch.numel()); + std::vector query_batch_stl(query_batch.DATA_PTR(), + query_batch.DATA_PTR() + query_batch.numel()); + std::vector support_batch_stl(support_batch.DATA_PTR(), + support_batch.DATA_PTR() + + support_batch.numel()); AT_DISPATCH_ALL_TYPES(query.scalar_type(), "batch_radius_search", [&] { std::vector queries_stl(query.DATA_PTR(), @@ -107,7 +108,7 @@ std::pair batch_ball_query(at::Tensor support, at::Tenso neighbors_dists, radius, max_num, mode, sorted); }); auto neighbors_dists_ptr = neighbors_dists.data(); - long* neighbors_indices_ptr = neighbors_indices.data(); + int64_t* neighbors_indices_ptr = neighbors_indices.data(); if (mode == 0) { diff --git a/cpu/src/fps.cpp b/cpu/src/fps.cpp index f05364a..5454724 100644 --- a/cpu/src/fps.cpp +++ b/cpu/src/fps.cpp @@ -15,7 +15,7 @@ at::Tensor fps(at::Tensor points, const int nsamples, bool random) auto out_options = torch::TensorOptions().dtype(torch::kLong).device(torch::kCPU); auto batch_size = points.size(0); auto out = torch::empty({batch_size, nsamples}, out_options); - auto out_a = out.accessor(); + auto out_a = out.accessor(); for (ptrdiff_t b = 0; b < batch_size; b++) { diff --git a/cpu/src/interpolate.cpp b/cpu/src/interpolate.cpp index ae1f5f9..c241ed5 100644 --- a/cpu/src/interpolate.cpp +++ b/cpu/src/interpolate.cpp @@ -19,7 +19,7 @@ at::Tensor knn_interpolate(at::Tensor features, at::Tensor idx, at::Tensor weigh auto output_a = output.accessor(); auto features_a = features.accessor(); auto weight_a = weight.accessor(); - auto idx_a = idx.accessor(); + auto idx_a = idx.accessor(); auto batch_size = idx.size(0); for (auto b = 0; b < batch_size; b++) @@ -51,7 +51,7 @@ at::Tensor knn_interpolate_grad(at::Tensor grad_out, at::Tensor idx, at::Tensor auto output_a = output.accessor(); auto grad_out_a = grad_out.accessor(); auto weight_a = weight.accessor(); - auto idx_a = idx.accessor(); + auto idx_a = idx.accessor(); auto batch_size = idx.size(0); for (auto b = 0; b < batch_size; b++) diff --git a/cpu/src/knn.cpp b/cpu/src/knn.cpp index c0ff0e6..e64eba5 100644 --- a/cpu/src/knn.cpp +++ b/cpu/src/knn.cpp @@ -12,7 +12,7 @@ std::pair _single_batch_knn(at::Tensor support, at::Tens if (support.size(0) < k) TORCH_CHECK(false, "Not enough points in support to find " + std::to_string(k) + " neighboors") - std::vector neighbors_indices(query.size(0) * k, -1); + std::vector neighbors_indices(query.size(0) * k, -1); std::vector neighbors_dists(query.size(0) * k, -1); auto options = torch::TensorOptions().dtype(torch::kLong).device(torch::kCPU); @@ -29,7 +29,7 @@ std::pair _single_batch_knn(at::Tensor support, at::Tens neighbors_dists, k); }); auto neighbors_dists_ptr = neighbors_dists.data(); - long* neighbors_indices_ptr = neighbors_indices.data(); + int64_t* neighbors_indices_ptr = neighbors_indices.data(); auto out = torch::from_blob(neighbors_indices_ptr, {query.size(0), k}, options = options); auto out_dists = torch::from_blob(neighbors_dists_ptr, {query.size(0), k}, options = options_dist); diff --git a/cpu/src/neighbors.cpp b/cpu/src/neighbors.cpp index 449a85e..6265e03 100644 --- a/cpu/src/neighbors.cpp +++ b/cpu/src/neighbors.cpp @@ -7,7 +7,7 @@ template int nanoflann_neighbors(vector& queries, vector& supports, - vector& neighbors_indices, vector& dists, float radius, + vector& neighbors_indices, vector& dists, float radius, int max_num, int mode, bool sorted) { // Initiate variables @@ -138,9 +138,9 @@ int nanoflann_neighbors(vector& queries, vector& supports, template int batch_nanoflann_neighbors(vector& queries, vector& supports, - vector& q_batches, vector& s_batches, - vector& neighbors_indices, vector& dists, float radius, - int max_num, int mode, bool sorted) + vector& q_batches, vector& s_batches, + vector& neighbors_indices, vector& dists, + float radius, int max_num, int mode, bool sorted) { // Initiate variables // ****************** @@ -187,7 +187,6 @@ int batch_nanoflann_neighbors(vector& queries, vector& suppo // Search params nanoflann::SearchParams search_params; search_params.sorted = sorted; - std::chrono::microseconds duration_search(0); for (size_t i = 0; i < num_query_points; i++) { // Check if we changed batch @@ -295,7 +294,7 @@ int batch_nanoflann_neighbors(vector& queries, vector& suppo template void nanoflann_knn_neighbors(vector& queries, vector& supports, - vector& neighbors_indices, vector& dists, int k) + vector& neighbors_indices, vector& dists, int k) { // Nanoflann related variables // *************************** From da6c11b0175c2371c552f8ce5cbd861429f4ff66 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Fri, 22 May 2020 09:51:39 +0100 Subject: [PATCH 2/8] Testing on macos --- .github/workflows/tests.yaml | 57 +++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 1f4c0c2..9633641 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -7,30 +7,33 @@ on: - master jobs: - unittests: - runs-on: ubuntu-latest - strategy: - matrix: - python-version: [3.6, 3.7, 3.8] - steps: - - uses: actions/checkout@v2 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install torch numpy scikit-learn flake8 setuptools - - name: Build package - run: | - python setup.py build_ext --inplace - - name: Lint with flake8 - run: | - # stop the build if there are Python syntax errors or undefined names - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - - name: Test with unittest - run: | - python -m unittest -v + unittests: + strategy: + matrix: + platform: [ubuntu-latest, macos-latest] + runs-on: ${{ matrix.platform }} + strategy: + matrix: + python-version: [3.6, 3.7] + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install torch numpy scikit-learn flake8 setuptools + - name: Build package + run: | + python setup.py build_ext --inplace + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with unittest + run: | + python -m unittest -v From b484d460cca499e0181406c01e0b9ecaa8dfaf75 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Fri, 22 May 2020 09:58:01 +0100 Subject: [PATCH 3/8] Version bump --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 2284e3a..d743f59 100644 --- a/setup.py +++ b/setup.py @@ -67,7 +67,7 @@ def get_cmdclass(): requirements = ["torch>=1.1.0"] url = "https://github.com/nicolas-chaulet/torch-points-kernels" -__version__ = "0.6.3" +__version__ = "0.6.4" setup( name="torch-points-kernels", version=__version__, From 8a230784e12931f4f38c2d59a2d5a355f545acbf Mon Sep 17 00:00:00 2001 From: Nicolas Date: Fri, 22 May 2020 10:01:21 +0100 Subject: [PATCH 4/8] Correct github actions --- .github/workflows/tests.yaml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 9633641..f193334 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -10,11 +10,9 @@ jobs: unittests: strategy: matrix: - platform: [ubuntu-latest, macos-latest] - runs-on: ${{ matrix.platform }} - strategy: - matrix: + os: [ubuntu-latest, macos-latest] python-version: [3.6, 3.7] + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} From 351f97b21216f0d0266463e6b5b1c86b486ad847 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Fri, 22 May 2020 10:06:26 +0100 Subject: [PATCH 5/8] Windows as well? --- .github/workflows/tests.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index f193334..3e76af2 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -10,7 +10,7 @@ jobs: unittests: strategy: matrix: - os: [ubuntu-latest, macos-latest] + os: [ubuntu-latest, macos-latest, windows-latest] python-version: [3.6, 3.7] runs-on: ${{ matrix.os }} steps: From e7bf34273e2bd00de246f0c8baf3cea40c7dda5d Mon Sep 17 00:00:00 2001 From: Nicolas Date: Fri, 22 May 2020 10:10:29 +0100 Subject: [PATCH 6/8] Pin pytorch version --- .github/workflows/tests.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 3e76af2..87ca85e 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -22,7 +22,8 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install torch numpy scikit-learn flake8 setuptools + pip install numpy scikit-learn flake8 setuptools + pip install torch==1.5.0+cpu torchvision==0.6.0+cpu -f https://download.pytorch.org/whl/torch_stable.html - name: Build package run: | python setup.py build_ext --inplace From aea426b13900fe4e5f9f390c63eac5cb20b8adbb Mon Sep 17 00:00:00 2001 From: Nicolas Date: Fri, 22 May 2020 10:24:53 +0100 Subject: [PATCH 7/8] Conditional install --- .github/workflows/tests.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 87ca85e..b3f7963 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -23,7 +23,13 @@ jobs: run: | python -m pip install --upgrade pip pip install numpy scikit-learn flake8 setuptools + - name: Install torch windows + linux + if: ${{matrix.os != 'macos-latest'}} pip install torch==1.5.0+cpu torchvision==0.6.0+cpu -f https://download.pytorch.org/whl/torch_stable.html + - name: Install torch macos + if: ${{matrix.os == 'macos-latest'}} + pip install torch + - name: Build package run: | python setup.py build_ext --inplace From 28a4e6f615c0456650e0da7b9c642d8bbf2ea3d0 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Fri, 22 May 2020 10:28:53 +0100 Subject: [PATCH 8/8] Conditional install --- .github/workflows/tests.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index b3f7963..0d6643e 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -23,12 +23,13 @@ jobs: run: | python -m pip install --upgrade pip pip install numpy scikit-learn flake8 setuptools + - name: Install torch windows + linux if: ${{matrix.os != 'macos-latest'}} - pip install torch==1.5.0+cpu torchvision==0.6.0+cpu -f https://download.pytorch.org/whl/torch_stable.html + run: pip install torch==1.5.0+cpu torchvision==0.6.0+cpu -f https://download.pytorch.org/whl/torch_stable.html - name: Install torch macos if: ${{matrix.os == 'macos-latest'}} - pip install torch + run: pip install torch - name: Build package run: |