add kernel with torch

This commit is contained in:
Pritimay Sarkar
2023-12-10 16:49:32 +05:30
parent a62238b30d
commit c0b9a88a53
2 changed files with 44 additions and 0 deletions

14
train/run_cuda.py Normal file
View File

@@ -0,0 +1,14 @@
import torch
from torch.utils.cpp_extension import load
# Load the compiled CUDA extension
my_cuda_extension = load(name='my_cuda_kernel', sources=['my_cuda_kernel.cu'])
# Define a PyTorch tensor on the GPU
input_tensor = torch.cuda.FloatTensor([1, 2, 3, 4])
# Call the CUDA function
output_tensor = my_cuda_extension.my_cuda_function(input_tensor)
# Print the result
print(output_tensor)