Skip to content

Fix incorrect operation in add_kernel and add related tests #117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion extension_cpp/csrc/cuda/muladd.cu
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ at::Tensor mymul_cuda(const at::Tensor& a, const at::Tensor& b) {

__global__ void add_kernel(int numel, const float* a, const float* b, float* result) {
int idx = blockIdx.x * blockDim.x + threadIdx.x;
if (idx < numel) result[idx] = a[idx] * b[idx];
if (idx < numel) result[idx] = a[idx] + b[idx];
}

void myadd_out_cuda(const at::Tensor& a, const at::Tensor& b, at::Tensor& out) {
Expand Down
7 changes: 7 additions & 0 deletions test/test_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ def _test_correctness(self, device):
expected = torch.add(*args[:2])
torch.testing.assert_close(result, expected)

def test_correctness_cpu(self):
self._test_correctness("cpu")

@unittest.skipIf(not torch.cuda.is_available(), "requires cuda")
def test_correctness_cuda(self):
self._test_correctness("cuda")

def _opcheck(self, device):
# Use opcheck to check for incorrect usage of operator registration APIs
samples = self.sample_inputs(device, requires_grad=True)
Expand Down