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

Added test for batches GEMMs #174

Merged
merged 1 commit into from
Apr 29, 2022
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
35 changes: 35 additions & 0 deletions include/matx_matmul.h
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,41 @@ class matxMatMulHandle_t {
sizeof(params_.batch));
MATX_ASSERT(ret == CUBLAS_STATUS_SUCCESS, matxMatMulError);

index_t stride;

if constexpr (is_complex_half_v<T2>) {
stride = params_.a_rows * params_.a_cols * 2;
}
else {
stride = params_.a_rows * params_.a_cols;
}
ret = cublasLtMatrixLayoutSetAttribute(
Adesc, CUBLASLT_MATRIX_LAYOUT_STRIDED_BATCH_OFFSET, &stride,
sizeof(stride));
MATX_ASSERT(ret == CUBLAS_STATUS_SUCCESS, matxMatMulError);

if constexpr (is_complex_half_v<T3>) {
stride = params_.b_rows * params_.b_cols * 2;
}
else {
stride = params_.b_rows * params_.b_cols;
}
ret = cublasLtMatrixLayoutSetAttribute(
Bdesc, CUBLASLT_MATRIX_LAYOUT_STRIDED_BATCH_OFFSET, &stride,
sizeof(stride));
MATX_ASSERT(ret == CUBLAS_STATUS_SUCCESS, matxMatMulError);

if constexpr (is_complex_half_v<T1>) {
stride = params_.c_rows * params_.c_cols * 2;
}
else {
stride = params_.c_rows * params_.c_cols;
}
ret = cublasLtMatrixLayoutSetAttribute(
Cdesc, CUBLASLT_MATRIX_LAYOUT_STRIDED_BATCH_OFFSET, &stride,
sizeof(stride));
MATX_ASSERT(ret == CUBLAS_STATUS_SUCCESS, matxMatMulError);

if constexpr (is_complex_half_v<T1> && is_complex_half_v<T2>) {
size_t planarA = (params_.a_rows * params_.a_cols * sizeof(T1)) / 2;
size_t planarB = (params_.b_rows * params_.b_cols * sizeof(T1)) / 2;
Expand Down
25 changes: 25 additions & 0 deletions test/00_transform/MatMul.cu
Original file line number Diff line number Diff line change
Expand Up @@ -241,5 +241,30 @@ TYPED_TEST(MatMulTestFloatTypes, MediumRect)
// b);
// MATX_TEST_ASSERT_COMPARE(this->pb, c, "c", this->thresh);

MATX_EXIT_HANDLER();
}

TYPED_TEST(MatMulTestFloatTypes, MediumRectBatched)
{
MATX_ENTER_HANDLER();
constexpr index_t batches = 5;
constexpr index_t m = 128;
constexpr index_t k = 256;
constexpr index_t n = 512;

tensor_t<TypeParam, 3> a{{batches, m, k}};
tensor_t<TypeParam, 3> b{{batches, k, n}};
tensor_t<TypeParam, 3> c{{batches, m, n}};

this->pb->template InitAndRunTVGenerator<TypeParam>(
"00_transforms", "matmul_operators", "run", {m, k, n, batches});

this->pb->NumpyToTensorView(a, "a");
this->pb->NumpyToTensorView(b, "b");

matmul<decltype(c), decltype(a), decltype(b), PROVIDER_TYPE_CUBLASLT>(c, a, b);

MATX_TEST_ASSERT_COMPARE(this->pb, c, "c", this->thresh);

MATX_EXIT_HANDLER();
}
15 changes: 11 additions & 4 deletions test/test_vectors/generators/00_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,19 @@ def corr_swap(self):
class matmul_operators:
def __init__(self, dtype: str, size: List[int]):
np.random.seed(1234)
batches = 1 if len(size) == 3 else size[-1]
self.size = size
self.dtype = dtype
self.res = {
'a': matx_common.randn_ndarray((size[0], size[1]), dtype),
'b': matx_common.randn_ndarray((size[1], size[2]), dtype)
}
if batches == 1:
self.res = {
'a': matx_common.randn_ndarray((size[0], size[1]), dtype),
'b': matx_common.randn_ndarray((size[1], size[2]), dtype)
}
else:
self.res = {
'a': matx_common.randn_ndarray((batches, size[0], size[1]), dtype),
'b': matx_common.randn_ndarray((batches, size[1], size[2]), dtype)
}

def run(self) -> Dict[str, np.ndarray]:
self.res['c'] = self.res['a'] @ self.res['b']
Expand Down