mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 12:54:11 +08:00
Close https://github.com/pytorch/pytorch/issues/57543 Doc: check `Relocatable device code linking:` in https://docs-preview.pytorch.org/78225/cpp_extension.html#torch.utils.cpp_extension.CUDAExtension Pull Request resolved: https://github.com/pytorch/pytorch/pull/78225 Approved by: https://github.com/ezyang, https://github.com/malfet
23 lines
608 B
Plaintext
23 lines
608 B
Plaintext
#include <cuda.h>
|
|
#include <cuda_runtime.h>
|
|
#include <c10/cuda/CUDAException.h>
|
|
|
|
#include <ATen/ATen.h>
|
|
|
|
#include "cuda_dlink_extension_add.cuh"
|
|
|
|
__global__ void add_kernel(const float* a, const float* b, float* output, int size) {
|
|
int i = blockIdx.x * blockDim.x + threadIdx.x;
|
|
if (i < size) {
|
|
add(a + i, b + i, output + i);
|
|
}
|
|
}
|
|
|
|
// output = a * b + c
|
|
void add_cuda(const float* a, const float* b, float* output, int size) {
|
|
const int threads = 1024;
|
|
const int blocks = (size + threads - 1) / threads;
|
|
add_kernel<<<blocks, threads>>>(a, b, output, size);
|
|
C10_CUDA_KERNEL_LAUNCH_CHECK();
|
|
}
|