Skip to content

Commit

Permalink
Merge pull request #36 from nicolas-chaulet/mac
Browse files Browse the repository at this point in the history
Mac
  • Loading branch information
nicolas-chaulet authored May 22, 2020
2 parents 16e2846 + 28a4e6f commit 8cc7b07
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 52 deletions.
63 changes: 36 additions & 27 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,39 @@ 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:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: [3.6, 3.7]
runs-on: ${{ matrix.os }}
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 numpy scikit-learn flake8 setuptools
- name: Install torch windows + linux
if: ${{matrix.os != 'macos-latest'}}
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'}}
run: pip install torch

- 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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# UNRELEASED

## Bug fix
- CPU version works for MacOS

# 0.6.2

## Bug fix
Expand Down
10 changes: 5 additions & 5 deletions cpu/include/neighbors.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ using namespace std;

template <typename scalar_t>
int nanoflann_neighbors(vector<scalar_t>& queries, vector<scalar_t>& supports,
vector<long>& neighbors_indices, vector<float>& dists, float radius,
vector<int64_t>& neighbors_indices, vector<float>& dists, float radius,
int max_num, int mode, bool sorted);

template <typename scalar_t>
int batch_nanoflann_neighbors(vector<scalar_t>& queries, vector<scalar_t>& supports,
vector<long>& q_batches, vector<long>& s_batches,
vector<long>& neighbors_indices, vector<float>& dists, float radius,
int max_num, int mode, bool sorted);
vector<int64_t>& q_batches, vector<int64_t>& s_batches,
vector<int64_t>& neighbors_indices, vector<float>& dists,
float radius, int max_num, int mode, bool sorted);

template <typename scalar_t>
void nanoflann_knn_neighbors(vector<scalar_t>& queries, vector<scalar_t>& supports,
vector<long>& neighbors_indices, vector<float>& dists, int k);
vector<int64_t>& neighbors_indices, vector<float>& dists, int k);
17 changes: 9 additions & 8 deletions cpu/src/ball_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ std::pair<at::Tensor, at::Tensor> ball_query(at::Tensor support, at::Tensor quer

at::Tensor out;
at::Tensor out_dists;
std::vector<long> neighbors_indices(query.size(0), 0);
std::vector<int64_t> neighbors_indices(query.size(0), 0);
std::vector<float> neighbors_dists(query.size(0), -1);

auto options = torch::TensorOptions().dtype(torch::kLong).device(torch::kCPU);
Expand All @@ -34,7 +34,7 @@ std::pair<at::Tensor, at::Tensor> 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 =
Expand Down Expand Up @@ -73,7 +73,7 @@ std::pair<at::Tensor, at::Tensor> batch_ball_query(at::Tensor support, at::Tenso
at::Tensor idx;

at::Tensor dist;
std::vector<long> neighbors_indices;
std::vector<int64_t> neighbors_indices;
std::vector<float> neighbors_dists;

auto options = torch::TensorOptions().dtype(torch::kLong).device(torch::kCPU);
Expand All @@ -91,10 +91,11 @@ std::pair<at::Tensor, at::Tensor> 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<long> query_batch_stl(query_batch.DATA_PTR<long>(),
query_batch.DATA_PTR<long>() + query_batch.numel());
std::vector<long> support_batch_stl(support_batch.DATA_PTR<long>(),
support_batch.DATA_PTR<long>() + support_batch.numel());
std::vector<int64_t> query_batch_stl(query_batch.DATA_PTR<int64_t>(),
query_batch.DATA_PTR<int64_t>() + query_batch.numel());
std::vector<int64_t> support_batch_stl(support_batch.DATA_PTR<int64_t>(),
support_batch.DATA_PTR<int64_t>() +
support_batch.numel());

AT_DISPATCH_ALL_TYPES(query.scalar_type(), "batch_radius_search", [&] {
std::vector<scalar_t> queries_stl(query.DATA_PTR<scalar_t>(),
Expand All @@ -107,7 +108,7 @@ std::pair<at::Tensor, at::Tensor> 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)
{
Expand Down
2 changes: 1 addition & 1 deletion cpu/src/fps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<long, 2>();
auto out_a = out.accessor<int64_t, 2>();

for (ptrdiff_t b = 0; b < batch_size; b++)
{
Expand Down
4 changes: 2 additions & 2 deletions cpu/src/interpolate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ at::Tensor knn_interpolate(at::Tensor features, at::Tensor idx, at::Tensor weigh
auto output_a = output.accessor<scalar_t, 3>();
auto features_a = features.accessor<scalar_t, 3>();
auto weight_a = weight.accessor<scalar_t, 3>();
auto idx_a = idx.accessor<long, 3>();
auto idx_a = idx.accessor<int64_t, 3>();

auto batch_size = idx.size(0);
for (auto b = 0; b < batch_size; b++)
Expand Down Expand Up @@ -51,7 +51,7 @@ at::Tensor knn_interpolate_grad(at::Tensor grad_out, at::Tensor idx, at::Tensor
auto output_a = output.accessor<scalar_t, 3>();
auto grad_out_a = grad_out.accessor<scalar_t, 3>();
auto weight_a = weight.accessor<scalar_t, 3>();
auto idx_a = idx.accessor<long, 3>();
auto idx_a = idx.accessor<int64_t, 3>();

auto batch_size = idx.size(0);
for (auto b = 0; b < batch_size; b++)
Expand Down
4 changes: 2 additions & 2 deletions cpu/src/knn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ std::pair<at::Tensor, at::Tensor> _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<long> neighbors_indices(query.size(0) * k, -1);
std::vector<int64_t> neighbors_indices(query.size(0) * k, -1);
std::vector<float> neighbors_dists(query.size(0) * k, -1);

auto options = torch::TensorOptions().dtype(torch::kLong).device(torch::kCPU);
Expand All @@ -29,7 +29,7 @@ std::pair<at::Tensor, at::Tensor> _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);
Expand Down
11 changes: 5 additions & 6 deletions cpu/src/neighbors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

template <typename scalar_t>
int nanoflann_neighbors(vector<scalar_t>& queries, vector<scalar_t>& supports,
vector<long>& neighbors_indices, vector<float>& dists, float radius,
vector<int64_t>& neighbors_indices, vector<float>& dists, float radius,
int max_num, int mode, bool sorted)
{
// Initiate variables
Expand Down Expand Up @@ -138,9 +138,9 @@ int nanoflann_neighbors(vector<scalar_t>& queries, vector<scalar_t>& supports,

template <typename scalar_t>
int batch_nanoflann_neighbors(vector<scalar_t>& queries, vector<scalar_t>& supports,
vector<long>& q_batches, vector<long>& s_batches,
vector<long>& neighbors_indices, vector<float>& dists, float radius,
int max_num, int mode, bool sorted)
vector<int64_t>& q_batches, vector<int64_t>& s_batches,
vector<int64_t>& neighbors_indices, vector<float>& dists,
float radius, int max_num, int mode, bool sorted)
{
// Initiate variables
// ******************
Expand Down Expand Up @@ -187,7 +187,6 @@ int batch_nanoflann_neighbors(vector<scalar_t>& queries, vector<scalar_t>& 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
Expand Down Expand Up @@ -295,7 +294,7 @@ int batch_nanoflann_neighbors(vector<scalar_t>& queries, vector<scalar_t>& suppo

template <typename scalar_t>
void nanoflann_knn_neighbors(vector<scalar_t>& queries, vector<scalar_t>& supports,
vector<long>& neighbors_indices, vector<float>& dists, int k)
vector<int64_t>& neighbors_indices, vector<float>& dists, int k)
{
// Nanoflann related variables
// ***************************
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__,
Expand Down

0 comments on commit 8cc7b07

Please sign in to comment.