torch-linear-assignment 0.0.2__tar.gz → 0.0.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (18) hide show
  1. {torch_linear_assignment-0.0.2/torch_linear_assignment.egg-info → torch_linear_assignment-0.0.4}/PKG-INFO +14 -2
  2. {torch_linear_assignment-0.0.2 → torch_linear_assignment-0.0.4}/README.md +5 -0
  3. {torch_linear_assignment-0.0.2 → torch_linear_assignment-0.0.4}/setup.py +1 -1
  4. {torch_linear_assignment-0.0.2 → torch_linear_assignment-0.0.4}/src/torch_linear_assignment_cuda_kernel.cu +35 -25
  5. {torch_linear_assignment-0.0.2 → torch_linear_assignment-0.0.4/torch_linear_assignment.egg-info}/PKG-INFO +14 -2
  6. {torch_linear_assignment-0.0.2 → torch_linear_assignment-0.0.4}/LICENSE +0 -0
  7. {torch_linear_assignment-0.0.2 → torch_linear_assignment-0.0.4}/MANIFEST.in +0 -0
  8. {torch_linear_assignment-0.0.2 → torch_linear_assignment-0.0.4}/pyproject.toml +0 -0
  9. {torch_linear_assignment-0.0.2 → torch_linear_assignment-0.0.4}/requirements.txt +0 -0
  10. {torch_linear_assignment-0.0.2 → torch_linear_assignment-0.0.4}/setup.cfg +0 -0
  11. {torch_linear_assignment-0.0.2 → torch_linear_assignment-0.0.4}/src/torch_linear_assignment.cpp +0 -0
  12. {torch_linear_assignment-0.0.2 → torch_linear_assignment-0.0.4}/src/torch_linear_assignment_cuda.cpp +0 -0
  13. {torch_linear_assignment-0.0.2 → torch_linear_assignment-0.0.4}/torch_linear_assignment/__init__.py +0 -0
  14. {torch_linear_assignment-0.0.2 → torch_linear_assignment-0.0.4}/torch_linear_assignment/assignment.py +0 -0
  15. {torch_linear_assignment-0.0.2 → torch_linear_assignment-0.0.4}/torch_linear_assignment.egg-info/SOURCES.txt +0 -0
  16. {torch_linear_assignment-0.0.2 → torch_linear_assignment-0.0.4}/torch_linear_assignment.egg-info/dependency_links.txt +0 -0
  17. {torch_linear_assignment-0.0.2 → torch_linear_assignment-0.0.4}/torch_linear_assignment.egg-info/requires.txt +0 -0
  18. {torch_linear_assignment-0.0.2 → torch_linear_assignment-0.0.4}/torch_linear_assignment.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: torch-linear-assignment
3
- Version: 0.0.2
3
+ Version: 0.0.4
4
4
  Summary: Batched linear assignment with PyTorch and CUDA.
5
5
  Author: Ivan Karpukhin
6
6
  Author-email: karpuhini@yandex.ru
@@ -8,6 +8,13 @@ Description-Content-Type: text/markdown
8
8
  License-File: LICENSE
9
9
  Requires-Dist: torch>=1.12.0
10
10
  Requires-Dist: scipy>=1.6.0
11
+ Dynamic: author
12
+ Dynamic: author-email
13
+ Dynamic: description
14
+ Dynamic: description-content-type
15
+ Dynamic: license-file
16
+ Dynamic: requires-dist
17
+ Dynamic: summary
11
18
 
12
19
  # Batch linear assignment for PyTorch
13
20
  [![PyPI version](https://badge.fury.io/py/torch-linear-assignment.svg)](https://badge.fury.io/py/torch-linear-assignment)
@@ -34,6 +41,11 @@ Build and install from Git repository:
34
41
  pip install .
35
42
  ```
36
43
 
44
+ Building in an isolated environment may use a different PyTorch version. To match the current environment and reduce the disk usage, apply the following flag:
45
+ ```bash
46
+ pip install --no-build-isolation torch-linear-assignment
47
+ ```
48
+
37
49
  When building with CUDA, make sure NVCC has the same CUDA version as PyTorch.
38
50
  You can choose CUDA version by
39
51
  ```bash
@@ -23,6 +23,11 @@ Build and install from Git repository:
23
23
  pip install .
24
24
  ```
25
25
 
26
+ Building in an isolated environment may use a different PyTorch version. To match the current environment and reduce the disk usage, apply the following flag:
27
+ ```bash
28
+ pip install --no-build-isolation torch-linear-assignment
29
+ ```
30
+
26
31
  When building with CUDA, make sure NVCC has the same CUDA version as PyTorch.
27
32
  You can choose CUDA version by
28
33
  ```bash
@@ -48,7 +48,7 @@ with open("README.md") as fp:
48
48
  if __name__ == '__main__':
49
49
  setuptools.setup(
50
50
  name="torch-linear-assignment",
51
- version="0.0.2",
51
+ version="0.0.4",
52
52
  author="Ivan Karpukhin",
53
53
  author_email="karpuhini@yandex.ru",
54
54
  description="Batched linear assignment with PyTorch and CUDA.",
@@ -9,8 +9,6 @@
9
9
 
10
10
  #include <cuda.h>
11
11
  #include <cuda_runtime.h>
12
- #include <thrust/device_vector.h>
13
- #include <thrust/fill.h>
14
12
 
15
13
  #include <torch/extension.h>
16
14
  #include <ATen/cuda/CUDAContext.h>
@@ -37,17 +35,20 @@ int SMPCores(int device_index)
37
35
  case 6: // Pascal
38
36
  if ((devProp.minor == 1) || (devProp.minor == 2)) return 128;
39
37
  else if (devProp.minor == 0) return 64;
38
+ break;
40
39
  case 7: // Volta and Turing
41
40
  if ((devProp.minor == 0) || (devProp.minor == 5)) return 64;
41
+ break;
42
42
  case 8: // Ampere
43
43
  if (devProp.minor == 0) return 64;
44
44
  else if (devProp.minor == 6) return 128;
45
45
  else if (devProp.minor == 9) return 128; // ada lovelace
46
+ break;
46
47
  case 9: // Hopper
47
48
  if (devProp.minor == 0) return 128;
48
- // Unknown device;
49
+ break;
49
50
  }
50
- return 128;
51
+ return 128; // Unknown device
51
52
  }
52
53
 
53
54
 
@@ -203,8 +204,10 @@ void solve_cuda_kernel_batch(int bs, int nr, int nc,
203
204
  }
204
205
 
205
206
 
207
+
206
208
  template <typename scalar_t>
207
- void solve_cuda_batch(int device_index,
209
+ void solve_cuda_batch(c10::ScalarType scalar_type,
210
+ int device_index,
208
211
  int bs, int nr, int nc,
209
212
  scalar_t *cost, int *col4row, int *row4col) {
210
213
  cudaSetDevice(device_index);
@@ -212,32 +215,38 @@ void solve_cuda_batch(int device_index,
212
215
  TORCH_CHECK(std::numeric_limits<scalar_t>::has_infinity, "Data type doesn't have infinity.");
213
216
  auto infinity = std::numeric_limits<scalar_t>::infinity();
214
217
 
215
- thrust::device_vector<scalar_t> u(bs * nr);
216
- thrust::device_vector<scalar_t> v(bs * nc);
217
- thrust::device_vector<scalar_t> shortestPathCosts(bs * nc);
218
- thrust::device_vector<int> path(bs * nc);
219
- thrust::device_vector<uint8_t> SR(bs * nr);
220
- thrust::device_vector<uint8_t> SC(bs * nc);
221
- thrust::device_vector<int> remaining(bs * nc);
222
-
223
- thrust::fill(u.begin(), u.end(), (scalar_t) 0);
224
- thrust::fill(v.begin(), v.end(), (scalar_t) 0);
225
- thrust::fill(path.begin(), path.end(), -1);
226
-
227
- int blockSize = SMPCores(device_index);
218
+ auto int_opt = torch::TensorOptions()
219
+ .dtype(torch::kInt)
220
+ .device(torch::kCUDA, device_index);
221
+ auto scalar_t_opt = torch::TensorOptions()
222
+ .dtype(scalar_type)
223
+ .device(torch::kCUDA, device_index);
224
+ auto uint8_opt = torch::TensorOptions()
225
+ .dtype(torch::kUInt8)
226
+ .device(torch::kCUDA, device_index);
227
+
228
+ torch::Tensor u = torch::zeros({bs * nr}, scalar_t_opt);
229
+ torch::Tensor v = torch::zeros({bs * nc}, scalar_t_opt);
230
+ torch::Tensor shortestPathCosts = torch::empty({bs * nc}, scalar_t_opt);
231
+ torch::Tensor path = torch::full({bs * nc}, -1, int_opt);
232
+ torch::Tensor SR = torch::empty({bs * nr}, uint8_opt);
233
+ torch::Tensor SC = torch::empty({bs * nc}, uint8_opt);
234
+ torch::Tensor remaining = torch::empty({bs * nc}, int_opt);
235
+
236
+ static const int blockSize = SMPCores(device_index);
228
237
  int gridSize = (bs + blockSize - 1) / blockSize;
229
238
  at::cuda::CUDAStream stream = at::cuda::getCurrentCUDAStream(device_index);
230
239
  solve_cuda_kernel_batch<<<gridSize, blockSize, 0, stream.stream()>>>(
231
240
  bs, nr, nc,
232
241
  cost,
233
- thrust::raw_pointer_cast(&u.front()),
234
- thrust::raw_pointer_cast(&v.front()),
235
- thrust::raw_pointer_cast(&shortestPathCosts.front()),
236
- thrust::raw_pointer_cast(&path.front()),
242
+ u.data<scalar_t>(),
243
+ v.data<scalar_t>(),
244
+ shortestPathCosts.data<scalar_t>(),
245
+ path.data<int>(),
237
246
  col4row, row4col,
238
- thrust::raw_pointer_cast(&SR.front()),
239
- thrust::raw_pointer_cast(&SC.front()),
240
- thrust::raw_pointer_cast(&remaining.front()),
247
+ SR.data<uint8_t>(),
248
+ SC.data<uint8_t>(),
249
+ remaining.data<int>(),
241
250
  infinity);
242
251
  cudaError_t err = cudaGetLastError();
243
252
  if (err != cudaSuccess) {
@@ -265,6 +274,7 @@ std::vector<torch::Tensor> batch_linear_assignment_cuda(torch::Tensor cost) {
265
274
 
266
275
  AT_DISPATCH_FLOATING_TYPES(cost.scalar_type(), "solve_cuda_batch", [&] {
267
276
  solve_cuda_batch<scalar_t>(
277
+ cost.scalar_type(),
268
278
  device.index(),
269
279
  sizes[0], sizes[1], sizes[2],
270
280
  cost.data<scalar_t>(),
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: torch-linear-assignment
3
- Version: 0.0.2
3
+ Version: 0.0.4
4
4
  Summary: Batched linear assignment with PyTorch and CUDA.
5
5
  Author: Ivan Karpukhin
6
6
  Author-email: karpuhini@yandex.ru
@@ -8,6 +8,13 @@ Description-Content-Type: text/markdown
8
8
  License-File: LICENSE
9
9
  Requires-Dist: torch>=1.12.0
10
10
  Requires-Dist: scipy>=1.6.0
11
+ Dynamic: author
12
+ Dynamic: author-email
13
+ Dynamic: description
14
+ Dynamic: description-content-type
15
+ Dynamic: license-file
16
+ Dynamic: requires-dist
17
+ Dynamic: summary
11
18
 
12
19
  # Batch linear assignment for PyTorch
13
20
  [![PyPI version](https://badge.fury.io/py/torch-linear-assignment.svg)](https://badge.fury.io/py/torch-linear-assignment)
@@ -34,6 +41,11 @@ Build and install from Git repository:
34
41
  pip install .
35
42
  ```
36
43
 
44
+ Building in an isolated environment may use a different PyTorch version. To match the current environment and reduce the disk usage, apply the following flag:
45
+ ```bash
46
+ pip install --no-build-isolation torch-linear-assignment
47
+ ```
48
+
37
49
  When building with CUDA, make sure NVCC has the same CUDA version as PyTorch.
38
50
  You can choose CUDA version by
39
51
  ```bash