-
-
Save ygabuev/406d2ddbdd542725333193844998b2f0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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)"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment