Commit 11a7e434 authored by Shaoshuai Shi's avatar Shaoshuai Shi
Browse files

update cuda codes to support PyTorch 1.5

parent f3846870
...@@ -13,7 +13,19 @@ All Rights Reserved 2020. ...@@ -13,7 +13,19 @@ All Rights Reserved 2020.
#include <cuda_runtime_api.h> #include <cuda_runtime_api.h>
#include "iou3d_cpu.h" #include "iou3d_cpu.h"
#define CHECK_CONTIGUOUS(x) AT_CHECK(x.is_contiguous(), #x, " must be contiguous ") #define CHECK_CUDA(x) do { \
if (!x.type().is_cuda()) { \
fprintf(stderr, "%s must be CUDA tensor at %s:%d\n", #x, __FILE__, __LINE__); \
exit(-1); \
} \
} while (0)
#define CHECK_CONTIGUOUS(x) do { \
if (!x.is_contiguous()) { \
fprintf(stderr, "%s must be contiguous tensor at %s:%d\n", #x, __FILE__, __LINE__); \
exit(-1); \
} \
} while (0)
#define CHECK_INPUT(x) CHECK_CUDA(x);CHECK_CONTIGUOUS(x)
inline float min(float a, float b){ inline float min(float a, float b){
return a > b ? b : a; return a > b ? b : a;
......
...@@ -11,8 +11,18 @@ All Rights Reserved 2019-2020. ...@@ -11,8 +11,18 @@ All Rights Reserved 2019-2020.
#include <cuda_runtime_api.h> #include <cuda_runtime_api.h>
#include "iou3d_nms.h" #include "iou3d_nms.h"
#define CHECK_CUDA(x) AT_CHECK(x.type().is_cuda(), #x, " must be a CUDAtensor ") #define CHECK_CUDA(x) do { \
#define CHECK_CONTIGUOUS(x) AT_CHECK(x.is_contiguous(), #x, " must be contiguous ") if (!x.type().is_cuda()) { \
fprintf(stderr, "%s must be CUDA tensor at %s:%d\n", #x, __FILE__, __LINE__); \
exit(-1); \
} \
} while (0)
#define CHECK_CONTIGUOUS(x) do { \
if (!x.is_contiguous()) { \
fprintf(stderr, "%s must be contiguous tensor at %s:%d\n", #x, __FILE__, __LINE__); \
exit(-1); \
} \
} while (0)
#define CHECK_INPUT(x) CHECK_CUDA(x);CHECK_CONTIGUOUS(x) #define CHECK_INPUT(x) CHECK_CUDA(x);CHECK_CONTIGUOUS(x)
#define DIVUP(m,n) ((m) / (n) + ((m) % (n) > 0)) #define DIVUP(m,n) ((m) / (n) + ((m) % (n) > 0))
...@@ -80,7 +90,6 @@ int boxes_iou_bev_gpu(at::Tensor boxes_a, at::Tensor boxes_b, at::Tensor ans_iou ...@@ -80,7 +90,6 @@ int boxes_iou_bev_gpu(at::Tensor boxes_a, at::Tensor boxes_b, at::Tensor ans_iou
int nms_gpu(at::Tensor boxes, at::Tensor keep, float nms_overlap_thresh){ int nms_gpu(at::Tensor boxes, at::Tensor keep, float nms_overlap_thresh){
// params boxes: (N, 7) [x, y, z, dx, dy, dz, heading] // params boxes: (N, 7) [x, y, z, dx, dy, dz, heading]
// params keep: (N) // params keep: (N)
CHECK_INPUT(boxes); CHECK_INPUT(boxes);
CHECK_CONTIGUOUS(keep); CHECK_CONTIGUOUS(keep);
......
...@@ -14,8 +14,18 @@ All Rights Reserved 2019-2020. ...@@ -14,8 +14,18 @@ All Rights Reserved 2019-2020.
extern THCState *state; extern THCState *state;
#define CHECK_CUDA(x) AT_CHECK(x.type().is_cuda(), #x, " must be a CUDAtensor ") #define CHECK_CUDA(x) do { \
#define CHECK_CONTIGUOUS(x) AT_CHECK(x.is_contiguous(), #x, " must be contiguous ") if (!x.type().is_cuda()) { \
fprintf(stderr, "%s must be CUDA tensor at %s:%d\n", #x, __FILE__, __LINE__); \
exit(-1); \
} \
} while (0)
#define CHECK_CONTIGUOUS(x) do { \
if (!x.is_contiguous()) { \
fprintf(stderr, "%s must be contiguous tensor at %s:%d\n", #x, __FILE__, __LINE__); \
exit(-1); \
} \
} while (0)
#define CHECK_INPUT(x) CHECK_CUDA(x);CHECK_CONTIGUOUS(x) #define CHECK_INPUT(x) CHECK_CUDA(x);CHECK_CONTIGUOUS(x)
int ball_query_wrapper_stack(int B, int M, float radius, int nsample, int ball_query_wrapper_stack(int B, int M, float radius, int nsample,
......
...@@ -13,8 +13,18 @@ All Rights Reserved 2019-2020. ...@@ -13,8 +13,18 @@ All Rights Reserved 2019-2020.
#include "group_points_gpu.h" #include "group_points_gpu.h"
extern THCState *state; extern THCState *state;
#define CHECK_CUDA(x) AT_CHECK(x.type().is_cuda(), #x, " must be a CUDAtensor ") #define CHECK_CUDA(x) do { \
#define CHECK_CONTIGUOUS(x) AT_CHECK(x.is_contiguous(), #x, " must be contiguous ") if (!x.type().is_cuda()) { \
fprintf(stderr, "%s must be CUDA tensor at %s:%d\n", #x, __FILE__, __LINE__); \
exit(-1); \
} \
} while (0)
#define CHECK_CONTIGUOUS(x) do { \
if (!x.is_contiguous()) { \
fprintf(stderr, "%s must be contiguous tensor at %s:%d\n", #x, __FILE__, __LINE__); \
exit(-1); \
} \
} while (0)
#define CHECK_INPUT(x) CHECK_CUDA(x);CHECK_CONTIGUOUS(x) #define CHECK_INPUT(x) CHECK_CUDA(x);CHECK_CONTIGUOUS(x)
......
...@@ -17,6 +17,20 @@ All Rights Reserved 2019-2020. ...@@ -17,6 +17,20 @@ All Rights Reserved 2019-2020.
extern THCState *state; extern THCState *state;
#define CHECK_CUDA(x) do { \
if (!x.type().is_cuda()) { \
fprintf(stderr, "%s must be CUDA tensor at %s:%d\n", #x, __FILE__, __LINE__); \
exit(-1); \
} \
} while (0)
#define CHECK_CONTIGUOUS(x) do { \
if (!x.is_contiguous()) { \
fprintf(stderr, "%s must be contiguous tensor at %s:%d\n", #x, __FILE__, __LINE__); \
exit(-1); \
} \
} while (0)
#define CHECK_INPUT(x) CHECK_CUDA(x);CHECK_CONTIGUOUS(x)
void three_nn_wrapper_stack(at::Tensor unknown_tensor, void three_nn_wrapper_stack(at::Tensor unknown_tensor,
at::Tensor unknown_batch_cnt_tensor, at::Tensor known_tensor, at::Tensor unknown_batch_cnt_tensor, at::Tensor known_tensor,
...@@ -28,6 +42,12 @@ void three_nn_wrapper_stack(at::Tensor unknown_tensor, ...@@ -28,6 +42,12 @@ void three_nn_wrapper_stack(at::Tensor unknown_tensor,
// Return: // Return:
// dist: (N1 + N2 ..., 3) l2 distance to the three nearest neighbors // dist: (N1 + N2 ..., 3) l2 distance to the three nearest neighbors
// idx: (N1 + N2 ..., 3) index of the three nearest neighbors // idx: (N1 + N2 ..., 3) index of the three nearest neighbors
CHECK_INPUT(unknown_tensor);
CHECK_INPUT(unknown_batch_cnt_tensor);
CHECK_INPUT(known_tensor);
CHECK_INPUT(known_batch_cnt_tensor);
CHECK_INPUT(dist2_tensor);
CHECK_INPUT(idx_tensor);
int batch_size = unknown_batch_cnt_tensor.size(0); int batch_size = unknown_batch_cnt_tensor.size(0);
int N = unknown_tensor.size(0); int N = unknown_tensor.size(0);
...@@ -50,6 +70,10 @@ void three_interpolate_wrapper_stack(at::Tensor features_tensor, ...@@ -50,6 +70,10 @@ void three_interpolate_wrapper_stack(at::Tensor features_tensor,
// weight_tensor: [N1 + N2 ..., 3] // weight_tensor: [N1 + N2 ..., 3]
// Return: // Return:
// out_tensor: (N1 + N2 ..., C) // out_tensor: (N1 + N2 ..., C)
CHECK_INPUT(features_tensor);
CHECK_INPUT(idx_tensor);
CHECK_INPUT(weight_tensor);
CHECK_INPUT(out_tensor);
int N = out_tensor.size(0); int N = out_tensor.size(0);
int channels = features_tensor.size(1); int channels = features_tensor.size(1);
...@@ -69,6 +93,10 @@ void three_interpolate_grad_wrapper_stack(at::Tensor grad_out_tensor, at::Tensor ...@@ -69,6 +93,10 @@ void three_interpolate_grad_wrapper_stack(at::Tensor grad_out_tensor, at::Tensor
// weight_tensor: [N1 + N2 ..., 3] // weight_tensor: [N1 + N2 ..., 3]
// Return: // Return:
// grad_features_tensor: (M1 + M2 ..., C) // grad_features_tensor: (M1 + M2 ..., C)
CHECK_INPUT(grad_out_tensor);
CHECK_INPUT(idx_tensor);
CHECK_INPUT(weight_tensor);
CHECK_INPUT(grad_features_tensor);
int N = grad_out_tensor.size(0); int N = grad_out_tensor.size(0);
int channels = grad_out_tensor.size(1); int channels = grad_out_tensor.size(1);
......
...@@ -6,11 +6,28 @@ ...@@ -6,11 +6,28 @@
#include "sampling_gpu.h" #include "sampling_gpu.h"
extern THCState *state; extern THCState *state;
#define CHECK_CUDA(x) do { \
if (!x.type().is_cuda()) { \
fprintf(stderr, "%s must be CUDA tensor at %s:%d\n", #x, __FILE__, __LINE__); \
exit(-1); \
} \
} while (0)
#define CHECK_CONTIGUOUS(x) do { \
if (!x.is_contiguous()) { \
fprintf(stderr, "%s must be contiguous tensor at %s:%d\n", #x, __FILE__, __LINE__); \
exit(-1); \
} \
} while (0)
#define CHECK_INPUT(x) CHECK_CUDA(x);CHECK_CONTIGUOUS(x)
int furthest_point_sampling_wrapper(int b, int n, int m, int furthest_point_sampling_wrapper(int b, int n, int m,
at::Tensor points_tensor, at::Tensor temp_tensor, at::Tensor idx_tensor) { at::Tensor points_tensor, at::Tensor temp_tensor, at::Tensor idx_tensor) {
CHECK_INPUT(points_tensor);
CHECK_INPUT(temp_tensor);
CHECK_INPUT(idx_tensor);
const float *points = points_tensor.data<float>(); const float *points = points_tensor.data<float>();
float *temp = temp_tensor.data<float>(); float *temp = temp_tensor.data<float>();
int *idx = idx_tensor.data<int>(); int *idx = idx_tensor.data<int>();
......
...@@ -11,9 +11,9 @@ All Rights Reserved 2019-2020. ...@@ -11,9 +11,9 @@ All Rights Reserved 2019-2020.
#include <assert.h> #include <assert.h>
#define CHECK_CUDA(x) AT_CHECK(x.type().is_cuda(), #x, " must be a CUDAtensor ") //#define CHECK_CUDA(x) AT_CHECK(x.type().is_cuda(), #x, " must be a CUDAtensor ")
#define CHECK_CONTIGUOUS(x) AT_CHECK(x.is_contiguous(), #x, " must be contiguous ") //#define CHECK_CONTIGUOUS(x) AT_CHECK(x.is_contiguous(), #x, " must be contiguous ")
#define CHECK_INPUT(x) CHECK_CUDA(x);CHECK_CONTIGUOUS(x) //#define CHECK_INPUT(x) CHECK_CUDA(x);CHECK_CONTIGUOUS(x)
void roiaware_pool3d_launcher(int boxes_num, int pts_num, int channels, int max_pts_each_voxel, void roiaware_pool3d_launcher(int boxes_num, int pts_num, int channels, int max_pts_each_voxel,
...@@ -36,12 +36,12 @@ int roiaware_pool3d_gpu(at::Tensor rois, at::Tensor pts, at::Tensor pts_feature, ...@@ -36,12 +36,12 @@ int roiaware_pool3d_gpu(at::Tensor rois, at::Tensor pts, at::Tensor pts_feature,
// params pooled_features: (N, out_x, out_y, out_z, C) // params pooled_features: (N, out_x, out_y, out_z, C)
// params pool_method: 0: max_pool 1: avg_pool // params pool_method: 0: max_pool 1: avg_pool
CHECK_INPUT(rois); // CHECK_INPUT(rois);
CHECK_INPUT(pts); // CHECK_INPUT(pts);
CHECK_INPUT(pts_feature); // CHECK_INPUT(pts_feature);
CHECK_INPUT(argmax); // CHECK_INPUT(argmax);
CHECK_INPUT(pts_idx_of_voxels); // CHECK_INPUT(pts_idx_of_voxels);
CHECK_INPUT(pooled_features); // CHECK_INPUT(pooled_features);
int boxes_num = rois.size(0); int boxes_num = rois.size(0);
int pts_num = pts.size(0); int pts_num = pts.size(0);
...@@ -72,10 +72,10 @@ int roiaware_pool3d_gpu_backward(at::Tensor pts_idx_of_voxels, at::Tensor argmax ...@@ -72,10 +72,10 @@ int roiaware_pool3d_gpu_backward(at::Tensor pts_idx_of_voxels, at::Tensor argmax
// params grad_in: (npoints, C), return value // params grad_in: (npoints, C), return value
// params pool_method: 0: max_pool 1: avg_pool // params pool_method: 0: max_pool 1: avg_pool
CHECK_INPUT(pts_idx_of_voxels); // CHECK_INPUT(pts_idx_of_voxels);
CHECK_INPUT(argmax); // CHECK_INPUT(argmax);
CHECK_INPUT(grad_out); // CHECK_INPUT(grad_out);
CHECK_INPUT(grad_in); // CHECK_INPUT(grad_in);
int boxes_num = pts_idx_of_voxels.size(0); int boxes_num = pts_idx_of_voxels.size(0);
int out_x = pts_idx_of_voxels.size(1); int out_x = pts_idx_of_voxels.size(1);
...@@ -100,9 +100,9 @@ int points_in_boxes_gpu(at::Tensor boxes_tensor, at::Tensor pts_tensor, at::Tens ...@@ -100,9 +100,9 @@ int points_in_boxes_gpu(at::Tensor boxes_tensor, at::Tensor pts_tensor, at::Tens
// params pts: (B, npoints, 3) [x, y, z] // params pts: (B, npoints, 3) [x, y, z]
// params boxes_idx_of_points: (B, npoints), default -1 // params boxes_idx_of_points: (B, npoints), default -1
CHECK_INPUT(boxes_tensor); // CHECK_INPUT(boxes_tensor);
CHECK_INPUT(pts_tensor); // CHECK_INPUT(pts_tensor);
CHECK_INPUT(box_idx_of_points_tensor); // CHECK_INPUT(box_idx_of_points_tensor);
int batch_size = boxes_tensor.size(0); int batch_size = boxes_tensor.size(0);
int boxes_num = boxes_tensor.size(1); int boxes_num = boxes_tensor.size(1);
...@@ -145,9 +145,9 @@ int points_in_boxes_cpu(at::Tensor boxes_tensor, at::Tensor pts_tensor, at::Tens ...@@ -145,9 +145,9 @@ int points_in_boxes_cpu(at::Tensor boxes_tensor, at::Tensor pts_tensor, at::Tens
// params pts: (num_points, 3) [x, y, z] // params pts: (num_points, 3) [x, y, z]
// params pts_indices: (N, num_points) // params pts_indices: (N, num_points)
CHECK_CONTIGUOUS(boxes_tensor); // CHECK_CONTIGUOUS(boxes_tensor);
CHECK_CONTIGUOUS(pts_tensor); // CHECK_CONTIGUOUS(pts_tensor);
CHECK_CONTIGUOUS(pts_indices_tensor); // CHECK_CONTIGUOUS(pts_indices_tensor);
int boxes_num = boxes_tensor.size(0); int boxes_num = boxes_tensor.size(0);
int pts_num = pts_tensor.size(0); int pts_num = pts_tensor.size(0);
......
#include <torch/serialize/tensor.h> #include <torch/serialize/tensor.h>
#include <torch/extension.h> #include <torch/extension.h>
#define CHECK_CUDA(x) do { \
#define CHECK_CUDA(x) AT_CHECK(x.type().is_cuda(), #x, " must be a CUDAtensor ") if (!x.type().is_cuda()) { \
#define CHECK_CONTIGUOUS(x) AT_CHECK(x.is_contiguous(), #x, " must be contiguous ") fprintf(stderr, "%s must be CUDA tensor at %s:%d\n", #x, __FILE__, __LINE__); \
exit(-1); \
} \
} while (0)
#define CHECK_CONTIGUOUS(x) do { \
if (!x.is_contiguous()) { \
fprintf(stderr, "%s must be contiguous tensor at %s:%d\n", #x, __FILE__, __LINE__); \
exit(-1); \
} \
} while (0)
#define CHECK_INPUT(x) CHECK_CUDA(x);CHECK_CONTIGUOUS(x) #define CHECK_INPUT(x) CHECK_CUDA(x);CHECK_CONTIGUOUS(x)
......
...@@ -27,7 +27,7 @@ def write_version_to_file(version, target_file): ...@@ -27,7 +27,7 @@ def write_version_to_file(version, target_file):
if __name__ == '__main__': if __name__ == '__main__':
version = '0.2.0+%s' % get_git_commit_number() version = '0.3.0+%s' % get_git_commit_number()
write_version_to_file(version, 'pcdet/version.py') write_version_to_file(version, 'pcdet/version.py')
setup( setup(
...@@ -37,7 +37,7 @@ if __name__ == '__main__': ...@@ -37,7 +37,7 @@ if __name__ == '__main__':
install_requires=[ install_requires=[
'numpy', 'numpy',
'torch>=1.1', 'torch>=1.1',
'spconv==1.0', 'spconv',
'numba', 'numba',
'tensorboardX', 'tensorboardX',
'easydict', 'easydict',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment