|
| 1 | +/* Copyright 2025 The OpenXLA Authors. |
| 2 | +
|
| 3 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +you may not use this file except in compliance with the License. |
| 5 | +You may obtain a copy of the License at |
| 6 | +
|
| 7 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +
|
| 9 | +Unless required by applicable law or agreed to in writing, software |
| 10 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +See the License for the specific language governing permissions and |
| 13 | +limitations under the License. |
| 14 | +==============================================================================*/ |
| 15 | + |
| 16 | +#include "xla/stream_executor/cuda/tma_util.h" |
| 17 | + |
| 18 | +#include <gmock/gmock.h> |
| 19 | +#include <gtest/gtest.h> |
| 20 | +#include "absl/status/status.h" |
| 21 | +#include "third_party/gpus/cuda/include/cuda.h" |
| 22 | +#include "xla/stream_executor/gpu/tma_metadata.h" |
| 23 | +#include "xla/tsl/platform/status_matchers.h" |
| 24 | + |
| 25 | +namespace stream_executor::gpu { |
| 26 | +namespace { |
| 27 | + |
| 28 | +using ::tsl::testing::IsOkAndHolds; |
| 29 | +using ::tsl::testing::StatusIs; |
| 30 | + |
| 31 | +TEST(TmaUtilTest, GetTensorMapDataTypeReturnsCorrectDataType) { |
| 32 | + EXPECT_THAT(GetTensorMapDataType(1), |
| 33 | + IsOkAndHolds(CU_TENSOR_MAP_DATA_TYPE_UINT8)); |
| 34 | + EXPECT_THAT(GetTensorMapDataType(2), |
| 35 | + IsOkAndHolds(CU_TENSOR_MAP_DATA_TYPE_UINT16)); |
| 36 | + EXPECT_THAT(GetTensorMapDataType(4), |
| 37 | + IsOkAndHolds(CU_TENSOR_MAP_DATA_TYPE_UINT32)); |
| 38 | + EXPECT_THAT(GetTensorMapDataType(8), |
| 39 | + IsOkAndHolds(CU_TENSOR_MAP_DATA_TYPE_UINT64)); |
| 40 | +} |
| 41 | + |
| 42 | +TEST(TmaUtilTest, GetTensorMapDataTypeFailsGracefully) { |
| 43 | + EXPECT_THAT(GetTensorMapDataType(0), |
| 44 | + StatusIs(absl::StatusCode::kInvalidArgument)); |
| 45 | + EXPECT_THAT(GetTensorMapDataType(16), |
| 46 | + StatusIs(absl::StatusCode::kInvalidArgument)); |
| 47 | +} |
| 48 | + |
| 49 | +TEST(TmaUtilTest, GetTensorMapSwizzleReturnsCorrectSwizzle) { |
| 50 | + EXPECT_EQ(GetTensorMapSwizzle(TmaDescriptor::TmaSwizzle::kNone), |
| 51 | + CU_TENSOR_MAP_SWIZZLE_NONE); |
| 52 | + EXPECT_EQ(GetTensorMapSwizzle(TmaDescriptor::TmaSwizzle::k32B), |
| 53 | + CU_TENSOR_MAP_SWIZZLE_32B); |
| 54 | + EXPECT_EQ(GetTensorMapSwizzle(TmaDescriptor::TmaSwizzle::k64B), |
| 55 | + CU_TENSOR_MAP_SWIZZLE_64B); |
| 56 | + EXPECT_EQ(GetTensorMapSwizzle(TmaDescriptor::TmaSwizzle::k128B), |
| 57 | + CU_TENSOR_MAP_SWIZZLE_128B); |
| 58 | +} |
| 59 | + |
| 60 | +TEST(TmaUtilTest, GetTensorMapL2PromotionReturnsCorrectL2Promotion) { |
| 61 | + EXPECT_EQ(GetTensorMapL2Promotion(TmaDescriptor::TmaL2Promotion::kNone), |
| 62 | + CU_TENSOR_MAP_L2_PROMOTION_NONE); |
| 63 | + EXPECT_EQ(GetTensorMapL2Promotion(TmaDescriptor::TmaL2Promotion::k64B), |
| 64 | + CU_TENSOR_MAP_L2_PROMOTION_L2_64B); |
| 65 | + EXPECT_EQ(GetTensorMapL2Promotion(TmaDescriptor::TmaL2Promotion::k128B), |
| 66 | + CU_TENSOR_MAP_L2_PROMOTION_L2_128B); |
| 67 | + EXPECT_EQ(GetTensorMapL2Promotion(TmaDescriptor::TmaL2Promotion::k256B), |
| 68 | + CU_TENSOR_MAP_L2_PROMOTION_L2_256B); |
| 69 | +} |
| 70 | + |
| 71 | +TEST(TmaUtilTest, GetTensorMapFloatOobFillReturnsCorrectFloatOobFill) { |
| 72 | + EXPECT_EQ(GetTensorMapFloatOOBFill(TmaDescriptor::TmaFloatOobFill::kNone), |
| 73 | + CU_TENSOR_MAP_FLOAT_OOB_FILL_NONE); |
| 74 | + EXPECT_EQ(GetTensorMapFloatOOBFill( |
| 75 | + TmaDescriptor::TmaFloatOobFill::kNanRequestZeroFma), |
| 76 | + CU_TENSOR_MAP_FLOAT_OOB_FILL_NAN_REQUEST_ZERO_FMA); |
| 77 | +} |
| 78 | + |
| 79 | +TEST(TmaUtilTest, GetTensorMapInterleaveReturnsCorrectInterleave) { |
| 80 | + EXPECT_EQ(GetTensorMapInterleave(TmaDescriptor::TmaInterleave::kNone), |
| 81 | + CU_TENSOR_MAP_INTERLEAVE_NONE); |
| 82 | + EXPECT_EQ(GetTensorMapInterleave(TmaDescriptor::TmaInterleave::k16B), |
| 83 | + CU_TENSOR_MAP_INTERLEAVE_16B); |
| 84 | + EXPECT_EQ(GetTensorMapInterleave(TmaDescriptor::TmaInterleave::k32B), |
| 85 | + CU_TENSOR_MAP_INTERLEAVE_32B); |
| 86 | +} |
| 87 | + |
| 88 | +} // namespace |
| 89 | +} // namespace stream_executor::gpu |
0 commit comments