-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpermuto.cpp
38 lines (27 loc) · 1.1 KB
/
permuto.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <torch/extension.h>
#include <cuda.h>
#include <cuda_runtime.h>
#include <vector>
#define CHECK_CUDA(x) TORCH_CHECK(x.device().is_cuda(), #x " must be a CUDA tensor")
#define CHECK_CONTIGUOUS(x) TORCH_CHECK(x.is_contiguous(), #x " must be contiguous")
#define CHECK_INPUT(x) \
CHECK_CUDA(x); \
CHECK_CONTIGUOUS(x)
std::vector<torch::Tensor> pfilter(torch::Tensor feature, torch::Tensor values);
torch::Tensor pfilter_grad(torch::Tensor feature, torch::Tensor g_values, torch::Tensor weight_saved);
std::vector<torch::Tensor> pfilter_cuda(torch::Tensor feature, torch::Tensor values){
CHECK_INPUT(feature);
CHECK_INPUT(values);
return pfilter(feature, values);
}
torch::Tensor pfilter_grad_cuda(torch::Tensor feature, torch::Tensor g_values, torch::Tensor weight_saved){
CHECK_INPUT(feature);
CHECK_INPUT(g_values);
CHECK_INPUT(weight_saved);
return pfilter_grad(feature, g_values, weight_saved);
}
PYBIND11_MODULE(TORCH_EXTENSION_NAME, m)
{
m.def("forward", &pfilter_cuda, "plattice forward");
m.def("backward", &pfilter_grad_cuda, "plattice backward");
}