Skip to content

Instantly share code, notes, and snippets.

@ygabuev
Last active May 24, 2019 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ygabuev/406d2ddbdd542725333193844998b2f0 to your computer and use it in GitHub Desktop.
Save ygabuev/406d2ddbdd542725333193844998b2f0 to your computer and use it in GitHub Desktop.
void donothing_cuda(int alloc_size, int device_index, int deallocate) {
cudaSetDevice((int)device_index);
void *buffer;
cudaMalloc((void**)&buffer, alloc_size);
if (deallocate) {
cudaFree(buffer);
}
}
#include <torch/extension.h>
// CUDA forward declaration
void donothing_cuda(int alloc_size, int device_index, int deallocate);
// C++ interface
void donothing(int alloc_size, int device_index, int deallocate) {
donothing_cuda(alloc_size, device_index, deallocate);
}
// Binding to Python
PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
m.def("call", &donothing, "Does exactly nothing (ok, it allocates memory)");
}
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment