Skip to content

Commit

Permalink
Made CUDA optional
Browse files Browse the repository at this point in the history
  • Loading branch information
stemann committed Dec 18, 2022
1 parent af53e2b commit d1fb8e6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions build/torch_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
#include<torch/torch.h>
#include<ATen/autocast_mode.h>
#include<torch/script.h>
#ifdef CUDA
#include<c10/cuda/CUDACachingAllocator.h>
#include<c10/cuda/CUDAStream.h>
#endif
#include<vector>
// #include<caml/fail.h>
// #include<julia.h>
Expand Down Expand Up @@ -74,13 +76,15 @@ int at_new_tensor(tensor *out__) {
return 1;
}

#ifdef CUDA
int at_empty_cache() {
PROTECT(
c10::cuda::CUDACachingAllocator::emptyCache();
return 0;
)
return 1;
}
#endif

int at_no_grad(int flag) {
PROTECT(
Expand All @@ -91,6 +95,7 @@ int at_no_grad(int flag) {
return 1;
}

#ifdef CUDA
int at_sync() {
PROTECT(
at::cuda::CUDAStream stream = at::cuda::getCurrentCUDAStream();
Expand All @@ -100,6 +105,7 @@ int at_sync() {
// torch::cuda::synchronize();
return 1;
}
#endif

int at_tensor_of_data(tensor *out__, void *vs, int64_t *dims, int ndims, int element_size_in_bytes, int type) {
PROTECT(
Expand Down Expand Up @@ -754,6 +760,7 @@ int ats_free(scalar s) {
return 1;
}

#ifdef CUDA
int atc_cuda_device_count(int *i) {
PROTECT(
i[0] = torch::cuda::device_count();
Expand Down Expand Up @@ -788,6 +795,7 @@ int atc_set_benchmark_cudnn(int b) {
)
return 1;
}
#endif

int atm_load(char *filename, module *out__) {
PROTECT(
Expand Down
6 changes: 6 additions & 0 deletions build/torch_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,13 @@ int flush_error();

int at_manual_seed(int64_t);
int at_new_tensor(tensor *);
#ifdef CUDA
int at_empty_cache();
#endif
int at_no_grad(int flag);
#ifdef CUDA
int at_sync();
#endif
int at_from_blob(tensor *, void *data, int64_t *dims, int ndims, int64_t *strides, int nstrides, int dev);
int at_tensor_of_data(tensor *, void *vs, int64_t *dims, int ndims, int element_size_in_bytes, int type);
int at_copy_data(tensor tensor, void *vs, int64_t numel, int element_size_in_bytes);
Expand Down Expand Up @@ -124,10 +128,12 @@ int ats_int(scalar *, int64_t);
int ats_float(scalar *, double);
int ats_free(scalar);

#ifdef CUDA
int atc_cuda_device_count(int *);
int atc_cuda_is_available(int *);
int atc_cudnn_is_available(int *);
int atc_set_benchmark_cudnn(int b);
#endif

int atm_load(char *, module *);
int atm_forward(tensor *, module, tensor *tensors, int ntensors);
Expand Down

0 comments on commit d1fb8e6

Please sign in to comment.