Skip to content
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

Add test cases for stride kernels #641

Merged
merged 1 commit into from
May 30, 2024
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
6 changes: 1 addition & 5 deletions include/matx/executors/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,7 @@ namespace matx
bool stride = detail::get_grid_dims<Op::Rank()>(blocks, threads, sizes, 256);

if constexpr (Op::Rank() == 1) {
if(stride) {
detail::matxOpT1StrideKernel<<<blocks, threads, 0, stream_>>>(op, sizes[0]);
} else {
detail::matxOpT1Kernel<<<blocks, threads, 0, stream_>>>(op, sizes[0]);
}
detail::matxOpT1Kernel<<<blocks, threads, 0, stream_>>>(op, sizes[0]);
}
else if constexpr (Op::Rank() == 2) {
if(stride) {
Expand Down
13 changes: 0 additions & 13 deletions include/matx/executors/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,6 @@ __global__ void matxOpT1Kernel(Op op, index_t size0) {
}
}

template <class Op>
__global__ void matxOpT1StrideKernel(Op op, index_t size0) {
for(index_t idx = static_cast<index_t>(blockIdx.x) * blockDim.x + threadIdx.x;
idx < size0;
idx += blockDim.x * gridDim.x) {
if constexpr (std::is_pointer_v<Op>) {
(*op)(idx);
}
else {
op(idx);
}
}
}

template <class Op>
__global__ void matxOpT2Kernel(Op op, index_t size0, index_t size1) {
Expand Down
54 changes: 54 additions & 0 deletions test/00_tensor/BasicTensorTests.cu
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,60 @@ TYPED_TEST(BasicTensorTestsIntegral, InitAssign)
MATX_EXIT_HANDLER();
}

TYPED_TEST(BasicTensorTestsIntegral, StridedKernels)
{
MATX_ENTER_HANDLER();

using TestType = std::tuple_element_t<0, TypeParam>;

{
auto ta = make_tensor<TestType>({70000 * 1024, 1});
auto tb = make_tensor<TestType>({70000 * 1024, 1});
auto tc = make_tensor<TestType>({70000 * 1024, 1});

(ta = 1, tb = 2).run();
(tc = ta + tb).run();

cudaStreamSynchronize(0);

for (index_t i = 0; i < tc.Size(0); i++) {
ASSERT_EQ(tc(i, 0), 3);
}
}

{
auto ta = make_tensor<TestType>({70000 * 1024, 1, 1});
auto tb = make_tensor<TestType>({70000 * 1024, 1, 1});
auto tc = make_tensor<TestType>({70000 * 1024, 1, 1});

(ta = 1, tb = 2).run();
(tc = ta + tb).run();

cudaStreamSynchronize(0);

for (index_t i = 0; i < tc.Size(0); i++) {
ASSERT_EQ(tc(i, 0, 0), 3);
}
}

{
auto ta = make_tensor<TestType>({70000 * 1024, 1, 1, 1});
auto tb = make_tensor<TestType>({70000 * 1024, 1, 1, 1});
auto tc = make_tensor<TestType>({70000 * 1024, 1, 1, 1});

(ta = 1, tb = 2).run();
(tc = ta + tb).run();

cudaStreamSynchronize(0);

for (index_t i = 0; i < tc.Size(0); i++) {
ASSERT_EQ(tc(i, 0, 0, 0), 3);
}
}

MATX_EXIT_HANDLER();
}


TYPED_TEST(BasicTensorTestsAll, Print)
{
Expand Down