CUTLASS 3.5.0 (#1411)
This commit is contained in:
@@ -93,6 +93,20 @@ if (CUTLASS_NVCC_MAX_ARCH GREATER_EQUAL 80)
|
||||
|
||||
endif()
|
||||
|
||||
if (CUTLASS_NVCC_MAX_ARCH GREATER_EQUAL 89)
|
||||
|
||||
add_dependencies(
|
||||
cutlass_test_unit_conv_device
|
||||
cutlass_test_unit_conv_device_tensorop_f8_sm89
|
||||
)
|
||||
|
||||
add_dependencies(
|
||||
test_unit_conv_device
|
||||
test_unit_conv_device_tensorop_f8_sm89
|
||||
)
|
||||
|
||||
endif()
|
||||
|
||||
#
|
||||
# OpClassSimt (CUDA cores)
|
||||
#
|
||||
@@ -126,6 +140,14 @@ if (CUTLASS_NVCC_MAX_ARCH GREATER_EQUAL 80)
|
||||
conv2d_fprop_implicit_gemm_cf32nhwc_cf32nhwc_cf32nhwc_simt_f32_sm80.cu
|
||||
conv2d_dgrad_implicit_gemm_cf32nhwc_cf32nhwc_cf32nhwc_simt_f32_sm80.cu
|
||||
conv2d_wgrad_implicit_gemm_cf32nhwc_cf32nhwc_cf32nhwc_simt_f32_sm80.cu
|
||||
|
||||
conv2d_fprop_with_broadcast_simt_sm80.cu
|
||||
|
||||
conv3d_fprop_implicit_gemm_f32ndhwc_f32ndhwc_f32ndhwc_simt_f32_sm80.cu
|
||||
conv3d_dgrad_implicit_gemm_f32ndhwc_f32ndhwc_f32ndhwc_simt_f32_sm80.cu
|
||||
conv3d_wgrad_implicit_gemm_f32ndhwc_f32ndhwc_f32ndhwc_simt_f32_sm80.cu
|
||||
|
||||
conv3d_fprop_with_broadcast_simt_sm80.cu
|
||||
)
|
||||
|
||||
endif()
|
||||
@@ -245,3 +267,14 @@ if (CUTLASS_NVCC_MAX_ARCH GREATER_EQUAL 75)
|
||||
|
||||
endif()
|
||||
|
||||
if (CUTLASS_NVCC_MAX_ARCH GREATER_EQUAL 89)
|
||||
|
||||
# Conv - F8 input, F8 output, F32 accumulation
|
||||
cutlass_test_unit_add_executable(
|
||||
cutlass_test_unit_conv_device_tensorop_f8_sm89
|
||||
|
||||
conv2d_fprop_implicit_gemm_f8nhwc_f8nhwc_f8nhwc_tensor_op_f32_sm89.cu
|
||||
)
|
||||
|
||||
endif()
|
||||
|
||||
|
||||
+368
@@ -0,0 +1,368 @@
|
||||
/***************************************************************************************************
|
||||
* Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! \file
|
||||
\brief Tests for device-wide Conv2d fprop interface with:
|
||||
A: NHWC, of type FE4M4 or FE5M2
|
||||
B: NHWC, of type FE4M3 or FE5M2
|
||||
C: NHWC, of FE4M3 or FE5M2
|
||||
Accum: F32
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "../../common/cutlass_unit_test.h"
|
||||
#include "cutlass/cutlass.h"
|
||||
#include "cutlass/epilogue/thread/activation.h"
|
||||
#include "cutlass/epilogue/thread/linear_combination_generic_with_scaling.h"
|
||||
#include "cutlass/conv/kernel/default_conv2d_fprop_with_absmax.h"
|
||||
#include "cutlass/conv/device/implicit_gemm_convolution.h"
|
||||
#include "cutlass/util/tensor_view_io.h"
|
||||
|
||||
#include "conv2d_with_absmax_testbed.h"
|
||||
|
||||
#if defined(CUTLASS_ARCH_MMA_SM89_SUPPORTED)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TEST(SM89_Device_Conv2d_Fprop_Analytic_ImplicitGemm_fe4m3nhwc_fe4mnhwc_fe4mnhwc_tensor_op_f32,
|
||||
identity_128x256x64_64x3_64x64x64) {
|
||||
|
||||
using ElementA = cutlass::float_e4m3_t;
|
||||
using ElementB = cutlass::float_e4m3_t;
|
||||
using ElementOutput = cutlass::float_e4m3_t;
|
||||
using ElementAuxOutput = ElementOutput;
|
||||
using ElementAccumulator = float;;
|
||||
static int const kStages = 3;
|
||||
|
||||
using EpilogueOutputOp = cutlass::epilogue::thread::LinearCombinationGenericWithScalingAndAbsMax<
|
||||
cutlass::epilogue::thread::Identity,
|
||||
ElementOutput,
|
||||
ElementAuxOutput,
|
||||
128 / cutlass::sizeof_bits<ElementOutput>::value,
|
||||
ElementAccumulator,
|
||||
ElementAccumulator
|
||||
>;
|
||||
|
||||
using Conv2dFpropKernel = typename cutlass::conv::kernel::DefaultConv2dFpropWithAbsMax<
|
||||
ElementA, cutlass::layout::TensorNHWC,
|
||||
ElementB, cutlass::layout::TensorNHWC,
|
||||
ElementOutput, cutlass::layout::TensorNHWC,
|
||||
ElementAccumulator,
|
||||
cutlass::arch::OpClassTensorOp,
|
||||
cutlass::arch::Sm89,
|
||||
cutlass::gemm::GemmShape<128, 256, 64>,
|
||||
cutlass::gemm::GemmShape<64, 64, 64>,
|
||||
cutlass::gemm::GemmShape<16, 8, 32>,
|
||||
EpilogueOutputOp,
|
||||
cutlass::gemm::threadblock::GemmIdentityThreadblockSwizzle<>,
|
||||
kStages,
|
||||
cutlass::arch::OpMultiplyAdd,
|
||||
cutlass::conv::IteratorAlgorithm::kAnalytic
|
||||
>::Kernel;
|
||||
|
||||
using Conv2dFprop = cutlass::conv::device::ImplicitGemmConvolution<Conv2dFpropKernel>;
|
||||
|
||||
bool passed = test::conv::device::TestAllConv2dWithAbsmax<Conv2dFprop, cutlass::epilogue::thread::Identity>();
|
||||
EXPECT_TRUE(passed);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TEST(SM89_Device_Conv2d_Fprop_Analytic_ImplicitGemm_fe5m2nhwc_fe4m3nhwc_fe4m3nhwc_tensor_op_f32,
|
||||
identity_128x256x64_64x3_64x64x64) {
|
||||
|
||||
using ElementA = cutlass::float_e5m2_t;
|
||||
using ElementB = cutlass::float_e4m3_t;
|
||||
using ElementOutput = cutlass::float_e4m3_t;
|
||||
using ElementAuxOutput = ElementOutput;
|
||||
using ElementAccumulator = float;;
|
||||
static int const kStages = 3;
|
||||
|
||||
using EpilogueOutputOp = cutlass::epilogue::thread::LinearCombinationGenericWithScalingAndAbsMax<
|
||||
cutlass::epilogue::thread::Identity,
|
||||
ElementOutput,
|
||||
ElementAuxOutput,
|
||||
128 / cutlass::sizeof_bits<ElementOutput>::value,
|
||||
ElementAccumulator,
|
||||
ElementAccumulator
|
||||
>;
|
||||
|
||||
using Conv2dFpropKernel = typename cutlass::conv::kernel::DefaultConv2dFpropWithAbsMax<
|
||||
ElementA, cutlass::layout::TensorNHWC,
|
||||
ElementB, cutlass::layout::TensorNHWC,
|
||||
ElementOutput, cutlass::layout::TensorNHWC,
|
||||
ElementAccumulator,
|
||||
cutlass::arch::OpClassTensorOp,
|
||||
cutlass::arch::Sm89,
|
||||
cutlass::gemm::GemmShape<128, 256, 64>,
|
||||
cutlass::gemm::GemmShape<64, 64, 64>,
|
||||
cutlass::gemm::GemmShape<16, 8, 32>,
|
||||
EpilogueOutputOp,
|
||||
cutlass::gemm::threadblock::GemmIdentityThreadblockSwizzle<>,
|
||||
kStages,
|
||||
cutlass::arch::OpMultiplyAdd,
|
||||
cutlass::conv::IteratorAlgorithm::kAnalytic
|
||||
>::Kernel;
|
||||
|
||||
using Conv2dFprop = cutlass::conv::device::ImplicitGemmConvolution<Conv2dFpropKernel>;
|
||||
|
||||
bool passed = test::conv::device::TestAllConv2dWithAbsmax<Conv2dFprop, cutlass::epilogue::thread::Identity>();
|
||||
EXPECT_TRUE(passed);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TEST(SM89_Device_Conv2d_Fprop_Analytic_ImplicitGemm_fe5m2nhwc_fe4m3nhwc_fe5m2nhwc_tensor_op_f32,
|
||||
identity_128x256x64_64x3_64x64x64) {
|
||||
|
||||
using ElementA = cutlass::float_e5m2_t;
|
||||
using ElementB = cutlass::float_e4m3_t;
|
||||
using ElementOutput = cutlass::float_e5m2_t;
|
||||
using ElementAuxOutput = ElementOutput;
|
||||
using ElementAccumulator = float;;
|
||||
static int const kStages = 3;
|
||||
|
||||
using EpilogueOutputOp = cutlass::epilogue::thread::LinearCombinationGenericWithScalingAndAbsMax<
|
||||
cutlass::epilogue::thread::Identity,
|
||||
ElementOutput,
|
||||
ElementAuxOutput,
|
||||
128 / cutlass::sizeof_bits<ElementOutput>::value,
|
||||
ElementAccumulator,
|
||||
ElementAccumulator
|
||||
>;
|
||||
|
||||
using Conv2dFpropKernel = typename cutlass::conv::kernel::DefaultConv2dFpropWithAbsMax<
|
||||
ElementA, cutlass::layout::TensorNHWC,
|
||||
ElementB, cutlass::layout::TensorNHWC,
|
||||
ElementOutput, cutlass::layout::TensorNHWC,
|
||||
ElementAccumulator,
|
||||
cutlass::arch::OpClassTensorOp,
|
||||
cutlass::arch::Sm89,
|
||||
cutlass::gemm::GemmShape<128, 256, 64>,
|
||||
cutlass::gemm::GemmShape<64, 64, 64>,
|
||||
cutlass::gemm::GemmShape<16, 8, 32>,
|
||||
EpilogueOutputOp,
|
||||
cutlass::gemm::threadblock::GemmIdentityThreadblockSwizzle<>,
|
||||
kStages,
|
||||
cutlass::arch::OpMultiplyAdd,
|
||||
cutlass::conv::IteratorAlgorithm::kAnalytic
|
||||
>::Kernel;
|
||||
|
||||
using Conv2dFprop = cutlass::conv::device::ImplicitGemmConvolution<Conv2dFpropKernel>;
|
||||
|
||||
bool passed = test::conv::device::TestAllConv2dWithAbsmax<Conv2dFprop, cutlass::epilogue::thread::Identity>();
|
||||
EXPECT_TRUE(passed);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TEST(SM89_Device_Conv2d_Fprop_Optimized_ImplicitGemm_fe4m3nhwc_fe4mnhwc_fe4mnhwc_tensor_op_f32,
|
||||
identity_128x256x64_64x3_64x64x64) {
|
||||
|
||||
using ElementA = cutlass::float_e4m3_t;
|
||||
using ElementB = cutlass::float_e4m3_t;
|
||||
using ElementOutput = cutlass::float_e4m3_t;
|
||||
using ElementAuxOutput = ElementOutput;
|
||||
using ElementAccumulator = float;;
|
||||
static int const kStages = 3;
|
||||
|
||||
using EpilogueOutputOp = cutlass::epilogue::thread::LinearCombinationGenericWithScalingAndAbsMax<
|
||||
cutlass::epilogue::thread::Identity,
|
||||
ElementOutput,
|
||||
ElementAuxOutput,
|
||||
128 / cutlass::sizeof_bits<ElementOutput>::value,
|
||||
ElementAccumulator,
|
||||
ElementAccumulator
|
||||
>;
|
||||
|
||||
using Conv2dFpropKernel = typename cutlass::conv::kernel::DefaultConv2dFpropWithAbsMax<
|
||||
ElementA, cutlass::layout::TensorNHWC,
|
||||
ElementB, cutlass::layout::TensorNHWC,
|
||||
ElementOutput, cutlass::layout::TensorNHWC,
|
||||
ElementAccumulator,
|
||||
cutlass::arch::OpClassTensorOp,
|
||||
cutlass::arch::Sm89,
|
||||
cutlass::gemm::GemmShape<128, 256, 64>,
|
||||
cutlass::gemm::GemmShape<64, 64, 64>,
|
||||
cutlass::gemm::GemmShape<16, 8, 32>,
|
||||
EpilogueOutputOp,
|
||||
cutlass::gemm::threadblock::GemmIdentityThreadblockSwizzle<>,
|
||||
kStages,
|
||||
cutlass::arch::OpMultiplyAdd,
|
||||
cutlass::conv::IteratorAlgorithm::kOptimized
|
||||
>::Kernel;
|
||||
|
||||
using Conv2dFprop = cutlass::conv::device::ImplicitGemmConvolution<Conv2dFpropKernel>;
|
||||
|
||||
bool passed = test::conv::device::TestAllConv2dWithAbsmax<Conv2dFprop, cutlass::epilogue::thread::Identity>();
|
||||
EXPECT_TRUE(passed);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TEST(SM89_Device_Conv2d_Fprop_Optimized_ImplicitGemm_fe4m3nhwc_fe4mnhwc_fe4mnhwc_tensor_op_f32,
|
||||
relu_128x256x64_64x3_64x64x64) {
|
||||
|
||||
using ElementA = cutlass::float_e4m3_t;
|
||||
using ElementB = cutlass::float_e4m3_t;
|
||||
using ElementOutput = cutlass::float_e4m3_t;
|
||||
using ElementAuxOutput = ElementOutput;
|
||||
using ElementAccumulator = float;;
|
||||
static int const kStages = 3;
|
||||
|
||||
using EpilogueOutputOp = cutlass::epilogue::thread::LinearCombinationGenericWithScalingAndAbsMax<
|
||||
cutlass::epilogue::thread::ReLu,
|
||||
ElementOutput,
|
||||
ElementAuxOutput,
|
||||
128 / cutlass::sizeof_bits<ElementOutput>::value,
|
||||
ElementAccumulator,
|
||||
ElementAccumulator
|
||||
>;
|
||||
|
||||
using Conv2dFpropKernel = typename cutlass::conv::kernel::DefaultConv2dFpropWithAbsMax<
|
||||
ElementA, cutlass::layout::TensorNHWC,
|
||||
ElementB, cutlass::layout::TensorNHWC,
|
||||
ElementOutput, cutlass::layout::TensorNHWC,
|
||||
ElementAccumulator,
|
||||
cutlass::arch::OpClassTensorOp,
|
||||
cutlass::arch::Sm89,
|
||||
cutlass::gemm::GemmShape<128, 256, 64>,
|
||||
cutlass::gemm::GemmShape<64, 64, 64>,
|
||||
cutlass::gemm::GemmShape<16, 8, 32>,
|
||||
EpilogueOutputOp,
|
||||
cutlass::gemm::threadblock::GemmIdentityThreadblockSwizzle<>,
|
||||
kStages,
|
||||
cutlass::arch::OpMultiplyAdd,
|
||||
cutlass::conv::IteratorAlgorithm::kOptimized
|
||||
>::Kernel;
|
||||
|
||||
using Conv2dFprop = cutlass::conv::device::ImplicitGemmConvolution<Conv2dFpropKernel>;
|
||||
|
||||
bool passed = test::conv::device::TestAllConv2dWithAbsmax<Conv2dFprop, cutlass::epilogue::thread::ReLu>();
|
||||
EXPECT_TRUE(passed);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TEST(SM89_Device_Conv2d_Fprop_Optimized_ImplicitGemm_fe4m3nhwc_fe4mnhwc_fe4mnhwc_tensor_op_f32,
|
||||
identity_fastacc_128x256x64_64x3_64x64x64) {
|
||||
|
||||
using ElementA = cutlass::float_e4m3_t;
|
||||
using ElementB = cutlass::float_e4m3_t;
|
||||
using ElementOutput = cutlass::float_e4m3_t;
|
||||
using ElementAuxOutput = ElementOutput;
|
||||
using ElementAccumulator = float;;
|
||||
static int const kStages = 3;
|
||||
|
||||
using EpilogueOutputOp = cutlass::epilogue::thread::LinearCombinationGenericWithScalingAndAbsMax<
|
||||
cutlass::epilogue::thread::Identity,
|
||||
ElementOutput,
|
||||
ElementAuxOutput,
|
||||
128 / cutlass::sizeof_bits<ElementOutput>::value,
|
||||
ElementAccumulator,
|
||||
ElementAccumulator
|
||||
>;
|
||||
|
||||
using Conv2dFpropKernel = typename cutlass::conv::kernel::DefaultConv2dFpropWithAbsMax<
|
||||
ElementA, cutlass::layout::TensorNHWC,
|
||||
ElementB, cutlass::layout::TensorNHWC,
|
||||
ElementOutput, cutlass::layout::TensorNHWC,
|
||||
ElementAccumulator,
|
||||
cutlass::arch::OpClassTensorOp,
|
||||
cutlass::arch::Sm89,
|
||||
cutlass::gemm::GemmShape<128, 256, 64>,
|
||||
cutlass::gemm::GemmShape<64, 64, 64>,
|
||||
cutlass::gemm::GemmShape<16, 8, 32>,
|
||||
EpilogueOutputOp,
|
||||
cutlass::gemm::threadblock::GemmIdentityThreadblockSwizzle<>,
|
||||
kStages,
|
||||
cutlass::arch::OpMultiplyAddFastAccum,
|
||||
cutlass::conv::IteratorAlgorithm::kOptimized
|
||||
>::Kernel;
|
||||
|
||||
using Conv2dFprop = cutlass::conv::device::ImplicitGemmConvolution<Conv2dFpropKernel>;
|
||||
|
||||
bool passed = test::conv::device::TestAllConv2dWithAbsmax<Conv2dFprop, cutlass::epilogue::thread::Identity>();
|
||||
EXPECT_TRUE(passed);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TEST(SM89_Device_Conv2d_Fprop_Optimized_ImplicitGemm_fe4m3nhwc_fe4mnhwc_fe4mnhwc_tensor_op_f32,
|
||||
identity_noScale_128x256x64_64x3_64x64x64) {
|
||||
|
||||
using ElementA = cutlass::float_e4m3_t;
|
||||
using ElementB = cutlass::float_e4m3_t;
|
||||
using ElementOutput = cutlass::float_e4m3_t;
|
||||
using ElementAuxOutput = ElementOutput;
|
||||
using ElementAccumulator = float;;
|
||||
static int const kStages = 3;
|
||||
|
||||
using EpilogueOutputOp = cutlass::epilogue::thread::LinearCombinationGenericWithScalingAndAbsMax<
|
||||
cutlass::epilogue::thread::Identity,
|
||||
ElementOutput,
|
||||
ElementAuxOutput,
|
||||
128 / cutlass::sizeof_bits<ElementOutput>::value,
|
||||
ElementAccumulator,
|
||||
ElementAccumulator
|
||||
>;
|
||||
|
||||
using Conv2dFpropKernel = typename cutlass::conv::kernel::DefaultConv2dFpropWithAbsMax<
|
||||
ElementA, cutlass::layout::TensorNHWC,
|
||||
ElementB, cutlass::layout::TensorNHWC,
|
||||
ElementOutput, cutlass::layout::TensorNHWC,
|
||||
ElementAccumulator,
|
||||
cutlass::arch::OpClassTensorOp,
|
||||
cutlass::arch::Sm89,
|
||||
cutlass::gemm::GemmShape<128, 256, 64>,
|
||||
cutlass::gemm::GemmShape<64, 64, 64>,
|
||||
cutlass::gemm::GemmShape<16, 8, 32>,
|
||||
EpilogueOutputOp,
|
||||
cutlass::gemm::threadblock::GemmIdentityThreadblockSwizzle<>,
|
||||
kStages,
|
||||
cutlass::arch::OpMultiplyAdd,
|
||||
cutlass::conv::IteratorAlgorithm::kOptimized
|
||||
>::Kernel;
|
||||
|
||||
using Conv2dFprop = cutlass::conv::device::ImplicitGemmConvolution<Conv2dFpropKernel>;
|
||||
|
||||
bool passed = test::conv::device::TestAllConv2dWithAbsmax<Conv2dFprop, cutlass::epilogue::thread::Identity>(
|
||||
/* scaleA = */false,
|
||||
/* scaleB = */false,
|
||||
/* scaleC = */false
|
||||
);
|
||||
EXPECT_TRUE(passed);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif // CUTLASS_ARCH_MMA_SM89_SUPPORTED
|
||||
@@ -0,0 +1,171 @@
|
||||
/***************************************************************************************************
|
||||
* Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
**************************************************************************************************/
|
||||
/*! \file
|
||||
\brief Tests for device-wide Implicit GEMM interface
|
||||
*/
|
||||
|
||||
#include "../../common/cutlass_unit_test.h"
|
||||
#include "cutlass/cutlass.h"
|
||||
#include "cutlass/array.h"
|
||||
#include "cutlass/epilogue/thread/linear_combination_bias_elementwise.h"
|
||||
#include "cutlass/epilogue/thread/linear_combination_residual_block.h"
|
||||
#include "cutlass/epilogue/thread/activation.h"
|
||||
#include "cutlass/conv/kernel/default_conv2d_fprop_with_broadcast.h"
|
||||
#include "cutlass/conv/device/implicit_gemm_convolution.h"
|
||||
|
||||
#include "conv2d_with_broadcast_testbed.h"
|
||||
|
||||
#if defined(CUTLASS_ARCH_MMA_SM80_SUPPORTED)
|
||||
|
||||
|
||||
TEST(SM80_Device_Conv2d_Fprop_With_Broadcast_Analytic_ImplicitGemm_f32nhwc_f32nhwc_f32nhwc_simt_f32,
|
||||
128x128_32x2_64x64x32) {
|
||||
|
||||
/// Conv operation element types for the Gemm equivalent (ImplicitGemm)
|
||||
using ElementA = float;
|
||||
using ElementB = float;
|
||||
using ElementC = float;
|
||||
using ElementCompute = float;
|
||||
using ElementAccumulator = float;
|
||||
|
||||
using EpilogueOutputOp = cutlass::epilogue::thread::LinearCombinationBiasElementwise<
|
||||
ElementC,
|
||||
ElementAccumulator,
|
||||
ElementCompute,
|
||||
ElementC,
|
||||
ElementC,
|
||||
1,
|
||||
cutlass::epilogue::thread::ReLu<float>
|
||||
>;
|
||||
|
||||
/// Device-level Conv2d instance
|
||||
using Conv2dFpropKernel = typename cutlass::conv::kernel::DefaultConv2dFpropWithBroadcast<
|
||||
ElementA, cutlass::layout::TensorNHWC,
|
||||
ElementB, cutlass::layout::TensorNHWC,
|
||||
ElementC, cutlass::layout::TensorNHWC,
|
||||
ElementAccumulator,
|
||||
cutlass::arch::OpClassSimt,
|
||||
cutlass::arch::Sm80,
|
||||
cutlass::gemm::GemmShape<128, 128, 8>,
|
||||
cutlass::gemm::GemmShape<32, 64, 8>,
|
||||
cutlass::gemm::GemmShape<1, 1, 1>,
|
||||
EpilogueOutputOp,
|
||||
cutlass::gemm::threadblock::GemmIdentityThreadblockSwizzle<>,
|
||||
4,
|
||||
cutlass::arch::OpMultiplyAdd,
|
||||
cutlass::conv::IteratorAlgorithm::kAnalytic
|
||||
>::Kernel;
|
||||
|
||||
using Conv2dFprop = cutlass::conv::device::ImplicitGemmConvolution<Conv2dFpropKernel>;
|
||||
|
||||
/// Run all unit test sizes with device-level Conv2d instance
|
||||
EXPECT_TRUE(test::conv::device::TestAllConv2dWithBroadcast<Conv2dFprop>());
|
||||
}
|
||||
|
||||
// Test residual block fusion: UnaryOp(BinaryOp(ActivationOp(Conv2d(X) + bias), residual))
|
||||
// LinearCombinationResidualBlock does not support the split-k mode unless ActivationOp is Identity.
|
||||
// This is because the activation needs to be applied to the fully accumulated output of the Conv2d op,
|
||||
// which only the last thread block would have an access to, before applying BinaryOp.
|
||||
// The epilogue functor in the last thread block would have to be given three inputs, namely
|
||||
// partial outputs, bias, and residual, but this is not supported in the current interface.
|
||||
// Set TestSplitK = false to skip split-k tests with non-trivial ActivationOp.
|
||||
template <
|
||||
template<typename T> class ActivationOp,
|
||||
template<typename T> class BinaryOp,
|
||||
template<typename T> class UnaryOp,
|
||||
bool TestSplitK = true
|
||||
>
|
||||
void TestResidaulBlock() {
|
||||
using ElementA = float;
|
||||
using ElementB = float;
|
||||
using ElementC = float;
|
||||
using ElementD = ElementC;
|
||||
using ElementCompute = float;
|
||||
using ElementAccumulator = float;
|
||||
|
||||
using EpilogueOutputOp = cutlass::epilogue::thread::LinearCombinationResidualBlock<
|
||||
ElementD,
|
||||
ElementAccumulator,
|
||||
ElementCompute,
|
||||
ElementC,
|
||||
1,
|
||||
ActivationOp,
|
||||
BinaryOp,
|
||||
UnaryOp
|
||||
>;
|
||||
|
||||
using Conv2dFpropKernel = typename cutlass::conv::kernel::DefaultConv2dFpropWithBroadcast<
|
||||
ElementA, cutlass::layout::TensorNHWC,
|
||||
ElementB, cutlass::layout::TensorNHWC,
|
||||
ElementC, cutlass::layout::TensorNHWC,
|
||||
ElementAccumulator,
|
||||
cutlass::arch::OpClassSimt,
|
||||
cutlass::arch::Sm80,
|
||||
cutlass::gemm::GemmShape<128, 128, 8>,
|
||||
cutlass::gemm::GemmShape<32, 64, 8>,
|
||||
cutlass::gemm::GemmShape<1, 1, 1>,
|
||||
EpilogueOutputOp,
|
||||
cutlass::gemm::threadblock::GemmIdentityThreadblockSwizzle<>,
|
||||
4,
|
||||
cutlass::arch::OpMultiplyAdd,
|
||||
cutlass::conv::IteratorAlgorithm::kAnalytic
|
||||
>::Kernel;
|
||||
|
||||
using Conv2dFprop = cutlass::conv::device::ImplicitGemmConvolution<Conv2dFpropKernel>;
|
||||
|
||||
struct ReferenceOp {
|
||||
using OutputOp = typename Conv2dFprop::EpilogueOutputOp;
|
||||
using ElementZ = typename OutputOp::ElementZ;
|
||||
|
||||
ActivationOp<ElementCompute> activation;
|
||||
BinaryOp<ElementCompute> binary_op;
|
||||
UnaryOp<ElementCompute> unary_op;
|
||||
|
||||
void operator()(ElementZ &Z, ElementZ&, ElementCompute conv2d, ElementCompute residual) {
|
||||
Z = ElementZ(unary_op(binary_op(activation(conv2d), residual)));
|
||||
}
|
||||
};
|
||||
|
||||
bool passed = test::conv::device::TestAllConv2dWithBroadcast<Conv2dFprop, ReferenceOp, true, TestSplitK>();
|
||||
EXPECT_TRUE(passed);
|
||||
}
|
||||
|
||||
TEST(SM80_Device_Conv2d_Fprop_With_Residual_Block_Plus_Analytic_ImplicitGemm_f32nhwc_f32nhwc_f32nhwc_simt_f32,
|
||||
128x128_8x4_32x64x8) {
|
||||
// Resnet
|
||||
TestResidaulBlock<cutlass::epilogue::thread::Identity, cutlass::plus, cutlass::epilogue::thread::ReLu>();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif // CUTLASS_ARCH_MMA_SM80_SUPPORTED
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -231,6 +231,75 @@ struct TestbedConv2dProblemSizes {
|
||||
{1, 1} // dilation (dilation_h, dilation_w)
|
||||
));
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Small input size x stride (1,1) asymmetric paddings (1, 0, 1, 0)
|
||||
// C < CTA::K and non-multiples of CTA::K. Typical CTA::K = {32, 64}
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
conv2d_default_sizes.push_back(cutlass::conv::Conv2dProblemSize(
|
||||
{1, 1, 1, minimum_channel_size}, // input size (NHWC)
|
||||
{8, 1, 1, minimum_channel_size}, // filter size (KRSC)
|
||||
{1, 0, 1, 0}, // padding (pad_h, _, pad_w, _)
|
||||
{1, 1}, // stride (stride_h, stride_w)
|
||||
{1, 1} // dilation (dilation_h, dilation_w)
|
||||
));
|
||||
|
||||
conv2d_default_sizes.push_back(cutlass::conv::Conv2dProblemSize(
|
||||
{1, 1, 8, minimum_channel_size}, // input size (NHWC)
|
||||
{8, 1, 3, minimum_channel_size}, // filter size (KRSC)
|
||||
{1, 0, 1, 0}, // padding (pad_h, _, pad_w, _)
|
||||
{1, 1}, // stride (stride_h, stride_w)
|
||||
{1, 1} // dilation (dilation_h, dilation_w)
|
||||
));
|
||||
|
||||
conv2d_default_sizes.push_back(cutlass::conv::Conv2dProblemSize(
|
||||
{1, 7, 8, minimum_channel_size}, // input size (NHWC)
|
||||
{8, 3, 3, minimum_channel_size}, // filter size (KRSC)
|
||||
{1, 0, 1, 0}, // padding (pad_h, _, pad_w, _)
|
||||
{1, 1}, // stride (stride_h, stride_w)
|
||||
{1, 1} // dilation (dilation_h, dilation_w)
|
||||
));
|
||||
|
||||
conv2d_default_sizes.push_back(cutlass::conv::Conv2dProblemSize(
|
||||
{1, 7, 9, minimum_channel_size}, // input size (NHWC)
|
||||
{8, 4, 4, minimum_channel_size}, // filter size (KRSC)
|
||||
{1, 0, 1, 0}, // padding (pad_h, _, pad_w, _)
|
||||
{1, 1}, // stride (stride_h, stride_w)
|
||||
{1, 1} // dilation (dilation_h, dilation_w)
|
||||
));
|
||||
|
||||
conv2d_default_sizes.push_back(cutlass::conv::Conv2dProblemSize(
|
||||
{2, 7, 9, minimum_channel_size}, // input size (NHWC)
|
||||
{8, 5, 5, minimum_channel_size}, // filter size (KRSC)
|
||||
{1, 0, 1, 0}, // padding (pad_h, _, pad_w, _)
|
||||
{1, 1}, // stride (stride_h, stride_w)
|
||||
{1, 1} // dilation (dilation_h, dilation_w)
|
||||
));
|
||||
|
||||
conv2d_default_sizes.push_back(cutlass::conv::Conv2dProblemSize(
|
||||
{3, 7, 9, minimum_channel_size}, // input size (NHWC)
|
||||
{8, 6, 5, minimum_channel_size}, // filter size (KRSC)
|
||||
{1, 0, 1, 0}, // padding (pad_h, _, pad_w, _)
|
||||
{1, 1}, // stride (stride_h, stride_w)
|
||||
{1, 1} // dilation (dilation_h, dilation_w)
|
||||
));
|
||||
|
||||
conv2d_default_sizes.push_back(cutlass::conv::Conv2dProblemSize(
|
||||
{3, 7, 9, minimum_channel_size}, // input size (NHWC)
|
||||
{8, 6, 6, minimum_channel_size}, // filter size (KRSC)
|
||||
{1, 0, 1, 0}, // padding (pad_h, _, pad_w, _)
|
||||
{1, 1}, // stride (stride_h, stride_w)
|
||||
{1, 1} // dilation (dilation_h, dilation_w)
|
||||
));
|
||||
|
||||
conv2d_default_sizes.push_back(cutlass::conv::Conv2dProblemSize(
|
||||
{3, 7, 9, minimum_channel_size}, // input size (NHWC)
|
||||
{8, 7, 7, minimum_channel_size}, // filter size (KRSC)
|
||||
{1, 0, 1, 0}, // padding (pad_h, _, pad_w, _)
|
||||
{1, 1}, // stride (stride_h, stride_w)
|
||||
{1, 1} // dilation (dilation_h, dilation_w)
|
||||
));
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Small input size x stride (2,2)
|
||||
// C < CTA::K and non-multiples of CTA::K. Typical CTA::K = {32, 64}
|
||||
|
||||
@@ -192,7 +192,7 @@ public:
|
||||
// Determine SMEM requirements and waive if not satisfied
|
||||
//
|
||||
|
||||
int smem_size = int(sizeof(typename Conv2d::UnderlyingKernel::SharedStorage));
|
||||
size_t smem_size = sizeof(typename Conv2d::UnderlyingKernel::SharedStorage);
|
||||
|
||||
cudaDeviceProp properties;
|
||||
int device_idx;
|
||||
|
||||
@@ -191,7 +191,7 @@ public:
|
||||
// Determine SMEM requirements and waive if not satisfied
|
||||
//
|
||||
|
||||
int smem_size = int(sizeof(typename Conv2d::UnderlyingKernel::SharedStorage));
|
||||
size_t smem_size = sizeof(typename Conv2d::UnderlyingKernel::SharedStorage);
|
||||
|
||||
cudaDeviceProp properties;
|
||||
int device_idx;
|
||||
|
||||
@@ -0,0 +1,622 @@
|
||||
/***************************************************************************************************
|
||||
* Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! \file
|
||||
\brief Testbed for running device-level Conv2Ds with absolute maximum calculation and scaling
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
#include "conv2d_problems.h"
|
||||
#include "../../common/cutlass_unit_test.h"
|
||||
#include "../../gemm/device/testbed_utils.h"
|
||||
|
||||
#include "cutlass/matrix_coord.h"
|
||||
#include "cutlass/conv/convolution.h"
|
||||
#include "cutlass/layout/matrix.h"
|
||||
|
||||
#include "cutlass/util/host_tensor.h"
|
||||
#include "cutlass/util/tensor_view_io.h"
|
||||
#include "cutlass/util/distribution.h"
|
||||
#include "cutlass/util/reference/host/convolution.h"
|
||||
#include "cutlass/util/reference/host/tensor_copy.h"
|
||||
#include "cutlass/util/reference/host/tensor_compare.h"
|
||||
#include "cutlass/util/reference/host/tensor_fill.h"
|
||||
#include "cutlass/util/reference/host/tensor_reduce.h"
|
||||
|
||||
namespace test {
|
||||
namespace conv {
|
||||
namespace device {
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template <
|
||||
typename Conv,
|
||||
template<typename T> class ActivationFunctor
|
||||
>
|
||||
struct TestbedConv2dWithAbsMax {
|
||||
|
||||
using ElementAccumulator = typename Conv::ElementAccumulator;
|
||||
using ElementCompute = typename Conv::UnderlyingKernel::Epilogue::OutputOp::ElementCompute;
|
||||
using ElementScalingFactor = typename Conv::EpilogueOutputOp::ElementScalingFactor;
|
||||
using ElementAbsmax = typename Conv::EpilogueOutputOp::ElementAbsmax;
|
||||
static cutlass::conv::Operator const kConvolutionalOperator = Conv::kConvolutionalOperator;
|
||||
|
||||
static bool const kScaleAux = Conv::EpilogueOutputOp::kIsScalingAndAmaxAuxOutputNeeded;
|
||||
static bool const kScaleOutput = Conv::EpilogueOutputOp::kIsScalingAndAmaxOutputNeeded;
|
||||
bool doScaleA;
|
||||
bool doScaleB;
|
||||
bool doScaleC;
|
||||
|
||||
/// Initialization
|
||||
cutlass::Distribution::Kind init_A;
|
||||
cutlass::Distribution::Kind init_B;
|
||||
cutlass::Distribution::Kind init_C;
|
||||
uint64_t seed;
|
||||
|
||||
cutlass::HostTensor<typename Conv::ElementA, typename Conv::LayoutA> tensor_A;
|
||||
cutlass::HostTensor<typename Conv::ElementB, typename Conv::LayoutB> tensor_B;
|
||||
cutlass::HostTensor<typename Conv::ElementC, typename Conv::LayoutC> tensor_C;
|
||||
cutlass::HostTensor<typename Conv::EpilogueOutputOp::ElementAuxOutput, typename Conv::LayoutC> tensor_Aux;
|
||||
cutlass::HostTensor<typename Conv::EpilogueOutputOp::ElementOutput, typename Conv::LayoutC> tensor_D;
|
||||
cutlass::HostTensor<typename Conv::ElementC, typename Conv::LayoutC> tensor_Vector;
|
||||
cutlass::HostTensor<ElementAccumulator, typename Conv::LayoutC> tmp_D;
|
||||
cutlass::HostTensor<typename Conv::EpilogueOutputOp::ElementOutput, typename Conv::LayoutC> reference_D;
|
||||
cutlass::HostTensor<typename Conv::EpilogueOutputOp::ElementAuxOutput, typename Conv::LayoutC> reference_Aux;
|
||||
cutlass::HostTensor<ElementScalingFactor, typename Conv::LayoutC> scale_A;
|
||||
cutlass::HostTensor<ElementScalingFactor, typename Conv::LayoutC> scale_B;
|
||||
cutlass::HostTensor<ElementScalingFactor, typename Conv::LayoutC> scale_C;
|
||||
cutlass::HostTensor<ElementScalingFactor, typename Conv::LayoutC> scale_D;
|
||||
cutlass::HostTensor<ElementScalingFactor, typename Conv::LayoutC> scale_Aux;
|
||||
cutlass::HostTensor<ElementAbsmax, typename Conv::LayoutC> abs_max_Aux;
|
||||
cutlass::HostTensor<ElementAbsmax, typename Conv::LayoutC> abs_max_D;
|
||||
cutlass::HostTensor<ElementAbsmax, typename Conv::LayoutC> reference_abs_max_Aux;
|
||||
cutlass::HostTensor<ElementAbsmax, typename Conv::LayoutC> reference_abs_max_D;
|
||||
|
||||
//
|
||||
// Methods
|
||||
//
|
||||
|
||||
TestbedConv2dWithAbsMax(
|
||||
bool scaleA = true,
|
||||
bool scaleB = true,
|
||||
bool scaleC = true,
|
||||
cutlass::Distribution::Kind init_A_ = cutlass::Distribution::Uniform,
|
||||
cutlass::Distribution::Kind init_B_ = cutlass::Distribution::Uniform,
|
||||
cutlass::Distribution::Kind init_C_ = cutlass::Distribution::Uniform,
|
||||
uint64_t seed_ = 2080
|
||||
):
|
||||
doScaleA(scaleA), doScaleB(scaleB), doScaleC(scaleC),
|
||||
init_A(init_A_), init_B(init_B_), init_C(init_C_), seed(seed_) { }
|
||||
|
||||
/// Helper to initialize scaling factors
|
||||
template <typename Element, typename Layout>
|
||||
bool initialize_scale_factor(cutlass::TensorView<Element, Layout> view, uint64_t seed, int bits=0) {
|
||||
cutlass::reference::host::TensorFillRandomUniform(view, seed, double(1.), double(0.), bits);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Helper to initialize a tensor view
|
||||
template <typename Element, typename Layout>
|
||||
bool initialize_tensor(
|
||||
cutlass::TensorView<Element, Layout> view,
|
||||
cutlass::Distribution::Kind dist_kind,
|
||||
uint64_t seed) {
|
||||
|
||||
if (dist_kind == cutlass::Distribution::Uniform) {
|
||||
|
||||
double scope_max, scope_min;
|
||||
int bits_input = cutlass::sizeof_bits<Element>::value;
|
||||
int bits_output = cutlass::sizeof_bits<typename Conv::ElementC>::value;
|
||||
|
||||
if (bits_input == 1) {
|
||||
scope_max = 2;
|
||||
scope_min = 0;
|
||||
} else if (bits_input <= 8) {
|
||||
scope_max = 2;
|
||||
scope_min = -2;
|
||||
} else if (bits_output == 16) {
|
||||
scope_max = 5;
|
||||
scope_min = -5;
|
||||
} else {
|
||||
scope_max = 8;
|
||||
scope_min = -8;
|
||||
}
|
||||
|
||||
cutlass::reference::host::TensorFillRandomUniform(
|
||||
view, seed, scope_max, scope_min, 0);
|
||||
}
|
||||
else if (dist_kind == cutlass::Distribution::Identity) {
|
||||
|
||||
cutlass::reference::host::TensorFillIdentity(view);
|
||||
}
|
||||
else if (dist_kind == cutlass::Distribution::Gaussian) {
|
||||
|
||||
cutlass::reference::host::TensorFillRandomGaussian(view, seed, 0, 0.5);
|
||||
}
|
||||
else if (dist_kind == cutlass::Distribution::Sequential) {
|
||||
|
||||
cutlass::reference::host::BlockFillSequential(
|
||||
view.data(), view.capacity());
|
||||
}
|
||||
else {
|
||||
EXPECT_TRUE(false) << "Not implemented";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Initializes data structures
|
||||
void initialize(cutlass::conv::Conv2dProblemSize const &problem_size) {
|
||||
//
|
||||
// Allocate the GEMM workspace
|
||||
//
|
||||
|
||||
tensor_A.resize(implicit_gemm_tensor_a_extent(kConvolutionalOperator, problem_size));
|
||||
tensor_B.resize(implicit_gemm_tensor_b_extent(kConvolutionalOperator, problem_size));
|
||||
tensor_C.resize(implicit_gemm_tensor_c_extent(kConvolutionalOperator, problem_size));
|
||||
tensor_D.resize(implicit_gemm_tensor_c_extent(kConvolutionalOperator, problem_size));
|
||||
tensor_Vector.resize({1, 1, 1, implicit_gemm_tensor_c_extent(kConvolutionalOperator, problem_size).c()});
|
||||
reference_D.resize(implicit_gemm_tensor_c_extent(kConvolutionalOperator, problem_size), false);
|
||||
tmp_D.resize(implicit_gemm_tensor_c_extent(kConvolutionalOperator, problem_size), false);
|
||||
|
||||
EXPECT_TRUE(initialize_tensor(tensor_A.host_view(), init_A, seed + 2019));
|
||||
EXPECT_TRUE(initialize_tensor(tensor_B.host_view(), init_B, seed + 2018));
|
||||
EXPECT_TRUE(initialize_tensor(tensor_C.host_view(), init_C, seed + 2017));
|
||||
EXPECT_TRUE(initialize_tensor(tensor_Vector.host_view(), init_C, seed + 2020));
|
||||
|
||||
// It is possible to randomly initialize to all zeros, so override this with non-zeros
|
||||
// in the upper left corner of each operand.
|
||||
cutlass::Coord<4> origin(0);
|
||||
tensor_A.host_view().at(origin) = typename Conv::ElementA(1);
|
||||
tensor_B.host_view().at(origin) = typename Conv::ElementB(1);
|
||||
tensor_C.host_view().at(origin) = typename Conv::ElementC(1);
|
||||
tensor_Vector.host_view().at(origin) = typename Conv::ElementC(1);
|
||||
|
||||
cutlass::reference::host::TensorFill(tensor_D.host_view());
|
||||
cutlass::reference::host::TensorCopy(reference_D.host_view(), tensor_C.host_view());
|
||||
|
||||
tensor_A.sync_device();
|
||||
tensor_B.sync_device();
|
||||
tensor_C.sync_device();
|
||||
tensor_D.sync_device();
|
||||
tensor_Vector.sync_device();
|
||||
|
||||
int scale_bits = 2;
|
||||
if (doScaleA) {
|
||||
scale_A.resize({1, 1, 1, 1});
|
||||
EXPECT_TRUE(initialize_scale_factor(scale_A.host_view(), seed + 2021, scale_bits));
|
||||
scale_A.sync_device();
|
||||
}
|
||||
|
||||
if (doScaleB) {
|
||||
scale_B.resize({1, 1, 1, 1});
|
||||
EXPECT_TRUE(initialize_scale_factor(scale_B.host_view(), seed + 2022, scale_bits));
|
||||
scale_B.sync_device();
|
||||
}
|
||||
|
||||
if (doScaleC) {
|
||||
scale_C.resize({1, 1, 1, 1});
|
||||
EXPECT_TRUE(initialize_scale_factor(scale_C.host_view(), seed + 2023, scale_bits));
|
||||
scale_C.sync_device();
|
||||
}
|
||||
|
||||
if (kScaleOutput) {
|
||||
scale_D.resize({1, 1, 1, 1});
|
||||
EXPECT_TRUE(initialize_scale_factor(scale_D.host_view(), seed + 2024, scale_bits));
|
||||
scale_D.sync_device();
|
||||
|
||||
abs_max_D.resize({1, 1, 1, 1});
|
||||
cutlass::reference::host::TensorFill(abs_max_D.host_view());
|
||||
abs_max_D.sync_device();
|
||||
|
||||
reference_abs_max_D.resize({1, 1, 1, 1});
|
||||
}
|
||||
|
||||
if (kScaleAux) {
|
||||
tensor_Aux.resize(implicit_gemm_tensor_c_extent(kConvolutionalOperator, problem_size));
|
||||
cutlass::reference::host::TensorFill(tensor_Aux.host_view());
|
||||
tensor_Aux.sync_device();
|
||||
|
||||
scale_Aux.resize({1, 1, 1, 1});
|
||||
EXPECT_TRUE(initialize_scale_factor(scale_Aux.host_view(), seed + 2025, scale_bits));
|
||||
scale_Aux.sync_device();
|
||||
|
||||
abs_max_Aux.resize({1, 1, 1, 1});
|
||||
cutlass::reference::host::TensorFill(abs_max_Aux.host_view());
|
||||
abs_max_Aux.sync_device();
|
||||
|
||||
reference_Aux.resize(implicit_gemm_tensor_c_extent(kConvolutionalOperator, problem_size), false);
|
||||
reference_abs_max_Aux.resize({1, 1, 1, 1});
|
||||
}
|
||||
}
|
||||
|
||||
/// Compares computed reference with device reference and outputs to a file if incorrect
|
||||
bool compare_reference(
|
||||
cutlass::conv::Conv2dProblemSize const &problem_size,
|
||||
ElementCompute alpha,
|
||||
ElementCompute beta) {
|
||||
|
||||
tensor_D.sync_host();
|
||||
|
||||
EXPECT_GT(cutlass::reference::host::TensorNorm(tensor_A.host_view()), 0);
|
||||
EXPECT_GT(cutlass::reference::host::TensorNorm(tensor_B.host_view()), 0);
|
||||
EXPECT_GT(cutlass::reference::host::TensorNorm(tensor_C.host_view()), 0);
|
||||
|
||||
EXPECT_GT(cutlass::reference::host::TensorNorm(tensor_D.host_view()), 0);
|
||||
EXPECT_GT(cutlass::reference::host::TensorNorm(reference_D.host_view()), 0);
|
||||
bool passed = cutlass::reference::host::TensorEquals(reference_D.host_view(), tensor_D.host_view());
|
||||
|
||||
if (kScaleAux) {
|
||||
tensor_Aux.sync_host();
|
||||
abs_max_Aux.sync_host();
|
||||
EXPECT_GT(cutlass::reference::host::TensorNorm(tensor_Aux.host_view()), 0);
|
||||
EXPECT_GT(cutlass::reference::host::TensorNorm(abs_max_Aux.host_view()), 0);
|
||||
EXPECT_GT(cutlass::reference::host::TensorNorm(reference_Aux.host_view()), 0);
|
||||
passed &= cutlass::reference::host::TensorEquals(reference_Aux.host_view(), tensor_Aux.host_view());
|
||||
passed &= cutlass::reference::host::TensorEquals(abs_max_Aux.host_view(), reference_abs_max_Aux.host_view());
|
||||
}
|
||||
|
||||
if (kScaleOutput) {
|
||||
abs_max_D.sync_host();
|
||||
EXPECT_GT(cutlass::reference::host::TensorNorm(abs_max_D.host_view()), 0);
|
||||
passed &= cutlass::reference::host::TensorEquals(abs_max_D.host_view(), reference_abs_max_D.host_view());
|
||||
}
|
||||
|
||||
EXPECT_TRUE(passed) << " mismatched reference";
|
||||
|
||||
if (!passed) {
|
||||
|
||||
std::ofstream file0("conv_testbed_with_amax_errors_reference.txt");
|
||||
std::ofstream file1("conv_testbed_with_amax_errors_computed.txt");
|
||||
|
||||
std::ofstream file("conv_testbed_with_amax_errors.txt");
|
||||
|
||||
file
|
||||
<< "problem: " << problem_size
|
||||
<< ", alpha: " << alpha << ", beta: " << beta << "\n\n";
|
||||
|
||||
file
|
||||
<< "A =\n" << tensor_A.host_view()
|
||||
<< "\nB =\n" << tensor_B.host_view()
|
||||
<< "\nC =\n" << tensor_C.host_view()
|
||||
<< "\nVector =\n" << tensor_Vector.host_view()
|
||||
<< "\nScaleA = " << scale_A.host_view()
|
||||
<< "\nScaleB = " << scale_B.host_view()
|
||||
<< "\nScaleC = " << scale_C.host_view()
|
||||
<< "\nScaleD = " << scale_D.host_view()
|
||||
<< "\nScaleAux = " << scale_Aux.host_view()
|
||||
<< std::endl;
|
||||
|
||||
file0 << "\n\nReference D =\n" << reference_D.host_view() << std::endl;
|
||||
file1 << "\n\nComputed D =\n" << tensor_D.host_view() << std::endl;
|
||||
if (kScaleAux) {
|
||||
file0 << "\n\nReference Aux =\n" << reference_Aux.host_view() << std::endl;
|
||||
file1 << "\n\nComputed Aux =\n" << tensor_Aux.host_view() << std::endl;
|
||||
file0 << "\n\nReference Absmax Aux = " << reference_abs_max_Aux.host_view() << std::endl;
|
||||
file1 << "\n\nComputed Absmax Aux = " << abs_max_Aux.host_view() << std::endl;
|
||||
}
|
||||
if (kScaleOutput) {
|
||||
file0 << "\n\nReference Absmax D = " << reference_abs_max_D.host_view() << std::endl;
|
||||
file1 << "\n\nComputed Absmax D = " << abs_max_D.host_view() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
return passed;
|
||||
}
|
||||
|
||||
/// Verifies the result is a GEMM
|
||||
bool verify(
|
||||
cutlass::conv::Conv2dProblemSize const &problem_size,
|
||||
ElementCompute alpha,
|
||||
ElementCompute beta) {
|
||||
|
||||
cutlass::Coord<4> origin(0);
|
||||
ElementCompute scaled_alpha = alpha;
|
||||
if (doScaleA) {
|
||||
scaled_alpha *= scale_A.host_view().at(origin);
|
||||
}
|
||||
if (doScaleB) {
|
||||
scaled_alpha *= scale_B.host_view().at(origin);
|
||||
}
|
||||
|
||||
ElementCompute scaled_beta = beta;
|
||||
if (doScaleC) {
|
||||
scaled_beta *= scale_C.host_view().at(origin);
|
||||
}
|
||||
|
||||
//
|
||||
// Verify
|
||||
//
|
||||
|
||||
cutlass::reference::host::Conv2d<
|
||||
typename Conv::ElementA, typename Conv::LayoutA,
|
||||
typename Conv::ElementB, typename Conv::LayoutB,
|
||||
typename Conv::ElementC, typename Conv::LayoutC,
|
||||
ElementCompute, ElementAccumulator, ElementAccumulator
|
||||
>(
|
||||
kConvolutionalOperator,
|
||||
problem_size,
|
||||
tensor_A.host_ref(),
|
||||
tensor_B.host_ref(),
|
||||
tensor_C.host_ref(),
|
||||
tmp_D.host_ref(),
|
||||
scaled_alpha,
|
||||
scaled_beta
|
||||
);
|
||||
|
||||
ElementCompute tmp_abs_max_Aux(0.);
|
||||
ElementCompute tmp_abs_max_D(0.);
|
||||
|
||||
cutlass::NumericConverter<ElementCompute, typename Conv::ElementC> cvt_c_to_compute;
|
||||
cutlass::NumericConverter<ElementCompute, ElementAccumulator> cvt_accum_to_compute;
|
||||
cutlass::NumericConverter<ElementAbsmax, ElementCompute> cvt_compute_to_absmax;
|
||||
cutlass::NumericConverter<typename Conv::EpilogueOutputOp::ElementOutput, ElementCompute> cvt_compute_to_d;
|
||||
cutlass::NumericConverter<typename Conv::EpilogueOutputOp::ElementAuxOutput, ElementCompute> cvt_compute_to_aux;
|
||||
|
||||
cutlass::absolute_value_op<ElementCompute> abs;
|
||||
cutlass::maximum_with_nan_propogation<ElementCompute> max;
|
||||
ActivationFunctor<ElementCompute> act;
|
||||
|
||||
ElementScalingFactor d_scale = kScaleOutput ? scale_D.host_view().at(origin) : ElementScalingFactor(1.);
|
||||
|
||||
for (int n = 0; n < problem_size.N; ++n) {
|
||||
for (int p = 0; p < problem_size.P; ++p) {
|
||||
for (int q = 0; q < problem_size.Q; ++q) {
|
||||
for (int k = 0; k < problem_size.K; ++k) {
|
||||
ElementCompute intermediate = cvt_accum_to_compute(tmp_D.host_view().at({n, p, q, k}));
|
||||
ElementCompute bias = cvt_c_to_compute(tensor_Vector.host_view().at({0, 0, 0, k}));
|
||||
ElementCompute aux = intermediate + bias;
|
||||
ElementCompute d = act(aux);
|
||||
tmp_abs_max_Aux = max(abs(aux), tmp_abs_max_Aux);
|
||||
tmp_abs_max_D = max(abs(d), tmp_abs_max_D);
|
||||
reference_D.host_view().at({n, p, q, k}) = cvt_compute_to_d(d * d_scale);
|
||||
|
||||
if (kScaleAux) {
|
||||
reference_Aux.host_view().at({n, p, q, k}) = cvt_compute_to_aux(aux * scale_Aux.host_view().at(origin));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (kScaleAux) {
|
||||
reference_abs_max_Aux.host_view().at(origin) = cvt_compute_to_absmax(tmp_abs_max_Aux);
|
||||
}
|
||||
|
||||
if (kScaleOutput) {
|
||||
reference_abs_max_D.host_view().at(origin) = cvt_compute_to_absmax(tmp_abs_max_D);
|
||||
}
|
||||
|
||||
return compare_reference(problem_size, alpha, beta);
|
||||
}
|
||||
|
||||
/// Returns true if the CUDA device is sufficient to execute the kernel.
|
||||
bool sufficient() const {
|
||||
//
|
||||
// Determine SMEM requirements and waive if not satisfied
|
||||
//
|
||||
|
||||
size_t smem_size = sizeof(typename Conv::UnderlyingKernel::SharedStorage);
|
||||
|
||||
cudaDeviceProp properties;
|
||||
int device_idx;
|
||||
cudaError_t result = cudaGetDevice(&device_idx);
|
||||
|
||||
if (result != cudaSuccess) {
|
||||
throw std::runtime_error("cudaGetDevice() API call failed.");
|
||||
}
|
||||
|
||||
result = cudaGetDeviceProperties(&properties, device_idx);
|
||||
|
||||
if (result != cudaSuccess) {
|
||||
throw std::runtime_error("cudaGetDeviceProperties() failed");
|
||||
}
|
||||
|
||||
if (properties.sharedMemPerBlockOptin < smem_size) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Executes one test
|
||||
bool run(
|
||||
cutlass::conv::Conv2dProblemSize const &problem_size,
|
||||
ElementCompute alpha = ElementCompute(1),
|
||||
ElementCompute beta = ElementCompute(0))
|
||||
{
|
||||
|
||||
// Waive test if insufficient CUDA device
|
||||
if (!sufficient()) {
|
||||
if (CUTLASS_TEST_UNIT_ENABLE_WARNINGS) {
|
||||
std::cerr << "Test waived due to insufficient CUDA device." << std::endl;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
this->initialize(problem_size);
|
||||
|
||||
//
|
||||
// Initialize the GEMM operator
|
||||
//
|
||||
|
||||
typename Conv::EpilogueOutputOp::Params::ActivationParams activation_params{alpha, beta};
|
||||
typename Conv::EpilogueOutputOp::Params epilogue_params{
|
||||
activation_params,
|
||||
scale_A.device_data(),
|
||||
scale_B.device_data(),
|
||||
scale_C.device_data(),
|
||||
scale_D.device_data(),
|
||||
scale_Aux.device_data(),
|
||||
abs_max_Aux.device_data(),
|
||||
abs_max_D.device_data()
|
||||
};
|
||||
|
||||
typename Conv::Arguments arguments{
|
||||
problem_size,
|
||||
tensor_A.device_ref(),
|
||||
tensor_B.device_ref(),
|
||||
tensor_C.device_ref(),
|
||||
tensor_D.device_ref(),
|
||||
tensor_Aux.device_ref(),
|
||||
epilogue_params,
|
||||
cutlass::conv::SplitKMode::kSerial,
|
||||
tensor_Vector.device_data(),
|
||||
0
|
||||
};
|
||||
|
||||
Conv conv2d_op;
|
||||
|
||||
cutlass::Status status = conv2d_op.can_implement(arguments);
|
||||
EXPECT_TRUE(status == cutlass::Status::kSuccess) << to_string(status);
|
||||
|
||||
size_t workspace_size = Conv::get_workspace_size(arguments);
|
||||
cutlass::device_memory::allocation<uint8_t> workspace(workspace_size);
|
||||
|
||||
status = conv2d_op.initialize(arguments, workspace.get());
|
||||
EXPECT_TRUE(status == cutlass::Status::kSuccess) << to_string(status);
|
||||
|
||||
//
|
||||
// Run the GEMM
|
||||
//
|
||||
|
||||
status = conv2d_op();
|
||||
|
||||
EXPECT_TRUE(status == cutlass::Status::kSuccess) << to_string(status);
|
||||
|
||||
cudaError_t cuda_error = cudaDeviceSynchronize();
|
||||
EXPECT_TRUE(cuda_error == cudaSuccess) << cudaGetErrorString(cuda_error);
|
||||
|
||||
//
|
||||
// Verify
|
||||
//
|
||||
|
||||
bool passed = this->verify(problem_size, alpha, beta);
|
||||
|
||||
if (!passed) {
|
||||
std::cout << "Failed" << std::endl;
|
||||
}
|
||||
|
||||
return passed;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template <
|
||||
typename ImplicitGemm,
|
||||
template<typename T> class ActivationFunctor = cutlass::epilogue::thread::Identity
|
||||
>
|
||||
bool TestAllConv2dWithAbsmax(bool scaleA=true, bool scaleB=true, bool scaleC=true) {
|
||||
const Conv2dProblemVector &conv_test_sizes = Conv2dProblemVector();
|
||||
const Conv2dProblemVector &conv_blacklist_sizes = Conv2dProblemVector();
|
||||
|
||||
//
|
||||
// Testbed object
|
||||
//
|
||||
|
||||
TestbedConv2dWithAbsMax<ImplicitGemm, ActivationFunctor> testbed(scaleA, scaleB, scaleC);
|
||||
|
||||
//
|
||||
// Get conv problem sizes to run conv operator
|
||||
//
|
||||
TestbedConv2dProblemSizes conv_problems(128/cutlass::sizeof_bits<typename ImplicitGemm::ElementA>::value);
|
||||
|
||||
// Vector of conv2d problem sizes to avoid duplicate runs
|
||||
Conv2dProblemVector conv_tested_sizes;
|
||||
|
||||
Conv2dProblemVector const *problem_vectors[] = {
|
||||
&conv_test_sizes, // run user specified sizes
|
||||
&conv_problems.conv2d_default_sizes, // run default and cudnn bug sizes
|
||||
&conv_problems.conv2d_resnet50_sizes, // run resnet50 sizes
|
||||
#if CUTLASS_CONV_UNIT_TEST_RIGOROUS_SIZE_ENABLED
|
||||
&conv_problems.conv2d_rigorous_sizes, // run large and rigorous sizes if enabled
|
||||
#endif
|
||||
};
|
||||
|
||||
bool passed = true;
|
||||
|
||||
// Sweep conv2d problem sizes (split-k-mode=kSerial, split-k-slice=1, alpha=1.0, beta=0.0)
|
||||
for (Conv2dProblemVector const * problem_vector : problem_vectors) {
|
||||
|
||||
// Prune all problems with channels that aren't divisible by the number of elements accessed per
|
||||
// load for operands A and B. This is meant to align with the requirements of iterators used for
|
||||
// fprop kernels.
|
||||
ChannelDivisibilitySpecification channel_spec(128 / cutlass::sizeof_bits<typename ImplicitGemm::ElementA>::value);
|
||||
auto pruned_problem_vector = prune(*problem_vector, channel_spec);
|
||||
|
||||
// Run conv testbed on default convolution sizes
|
||||
for(auto conv_problem : pruned_problem_vector) {
|
||||
|
||||
// Skip blacklist and avoid duplicate problem sizes
|
||||
if (std::find(conv_blacklist_sizes.begin(), conv_blacklist_sizes.end(), conv_problem) != conv_blacklist_sizes.end() ||
|
||||
std::find(conv_tested_sizes.begin(), conv_tested_sizes.end(), conv_problem) != conv_tested_sizes.end()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Test
|
||||
//
|
||||
// push back tested problem size to avoid re-running duplicates
|
||||
conv_tested_sizes.push_back(conv_problem);
|
||||
|
||||
// test mode = xcross
|
||||
passed &= testbed.run(conv_problem);
|
||||
|
||||
if (!passed) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// test mode = convolution
|
||||
passed &= testbed.run(conv_problem.reset_mode(cutlass::conv::Mode::kConvolution));
|
||||
|
||||
if (!passed) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return passed;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
} // namespace device
|
||||
} // namespace conv
|
||||
} // namespace test
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -254,7 +254,7 @@ public:
|
||||
// Determine SMEM requirements and waive if not satisfied
|
||||
//
|
||||
|
||||
int smem_size = int(sizeof(typename Conv2d::UnderlyingKernel::SharedStorage));
|
||||
size_t smem_size = sizeof(typename Conv2d::UnderlyingKernel::SharedStorage);
|
||||
|
||||
cudaDeviceProp properties;
|
||||
int device_idx;
|
||||
@@ -408,11 +408,11 @@ public:
|
||||
for (int q = 0; q < problem_size.Q; ++q) {
|
||||
for (int k = 0; k < problem_size.K; ++k) {
|
||||
|
||||
ElementZ z;
|
||||
ElementT t;
|
||||
ElementZ z{};
|
||||
ElementT t{};
|
||||
|
||||
ElementCompute accum = tensor_Y_reference.at({n, p, q, k});
|
||||
ElementCompute bias = ElementCompute(tensor_Broadcast.at({0, 0, 0, k}));
|
||||
ElementCompute bias = ElementCompute(tensor_Broadcast.at({0, 0, 0, k}));
|
||||
|
||||
|
||||
if (kAddBroadcastFirst) {
|
||||
@@ -499,6 +499,52 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template <typename ImplicitGemm,
|
||||
typename ReferenceOp = Conv2dWithBroadcastReferenceOp<ImplicitGemm>,
|
||||
bool AddBroadcastFirst = false>
|
||||
bool TestSpecificConv2dWithBroadcast(
|
||||
const Conv2dProblemVector & problem_sizes) {
|
||||
|
||||
bool passed = true;
|
||||
|
||||
//
|
||||
// Testbed object
|
||||
//
|
||||
|
||||
TestbedConv2dWithBroadcast<ImplicitGemm, ReferenceOp, AddBroadcastFirst> testbed;
|
||||
|
||||
// Sweep conv2d problem sizes (split-k-mode=kSerial, split-k-slice=1, alpha=1.0, beta=0.0)
|
||||
for(auto conv_problem : problem_sizes) {
|
||||
|
||||
//
|
||||
// Test
|
||||
//
|
||||
|
||||
// test mode = xcross
|
||||
passed = testbed.run(
|
||||
conv_problem,
|
||||
cutlass::conv::SplitKMode::kSerial);
|
||||
|
||||
if (!passed) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// test mode = convolution
|
||||
passed = testbed.run(
|
||||
conv_problem.reset_mode(cutlass::conv::Mode::kConvolution),
|
||||
cutlass::conv::SplitKMode::kSerial);
|
||||
|
||||
if (!passed) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// TestAllConv: Runs cutlass::conv::device::ImplicitGemmConvolution operator and compares it with reference
|
||||
// TestAllConv runs conv operator on default conv problem sizes from test::conv::device::TestbedConv2dProblemSizes
|
||||
|
||||
@@ -182,7 +182,7 @@ public:
|
||||
// Determine SMEM requirements and waive if not satisfied
|
||||
//
|
||||
|
||||
int smem_size = int(sizeof(typename Conv2d::UnderlyingKernel::SharedStorage));
|
||||
size_t smem_size = sizeof(typename Conv2d::UnderlyingKernel::SharedStorage);
|
||||
|
||||
cudaDeviceProp properties;
|
||||
int device_idx;
|
||||
|
||||
+142
@@ -0,0 +1,142 @@
|
||||
/***************************************************************************************************
|
||||
* Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
**************************************************************************************************/
|
||||
/*! \file
|
||||
\brief Tests for device-wide Implicit GEMM interface
|
||||
*/
|
||||
|
||||
#include "../../common/cutlass_unit_test.h"
|
||||
#include "cutlass/cutlass.h"
|
||||
|
||||
#include "cutlass/conv/kernel/default_conv3d_dgrad.h"
|
||||
#include "cutlass/conv/device/implicit_gemm_convolution.h"
|
||||
|
||||
#include "conv3d_testbed.h"
|
||||
|
||||
#if defined(CUTLASS_ARCH_MMA_SM80_SUPPORTED)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
TEST(SM80_Device_Conv3d_Dgrad_Analytic_ImplicitGemm_f32ndhwc_f32ndhwc_f32ndhwc_simt_f32,
|
||||
128x128_8x4_32x64x8) {
|
||||
|
||||
/// Conv operation element types for the Gemm equivalent (ImplicitGemm)
|
||||
using ElementA = float;
|
||||
using ElementB = float;
|
||||
using ElementC = float;
|
||||
using ElementAccumulator = float;
|
||||
using ElementCompute = float;
|
||||
|
||||
|
||||
/// Device-level Conv3d instance
|
||||
using Conv3dDgradKernel = typename cutlass::conv::kernel::DefaultConv3dDgrad<
|
||||
ElementA,
|
||||
cutlass::layout::TensorNDHWC,
|
||||
ElementB,
|
||||
cutlass::layout::TensorNDHWC,
|
||||
ElementC,
|
||||
cutlass::layout::TensorNDHWC,
|
||||
ElementAccumulator,
|
||||
cutlass::arch::OpClassSimt,
|
||||
cutlass::arch::Sm80,
|
||||
cutlass::gemm::GemmShape<128, 128, 8>,
|
||||
cutlass::gemm::GemmShape<32, 64, 8>,
|
||||
cutlass::gemm::GemmShape<1, 1, 1>,
|
||||
cutlass::epilogue::thread::LinearCombination<
|
||||
ElementC,
|
||||
1,
|
||||
ElementAccumulator,
|
||||
ElementCompute
|
||||
>,
|
||||
cutlass::gemm::threadblock::GemmIdentityThreadblockSwizzle<>,
|
||||
4,
|
||||
cutlass::arch::OpMultiplyAdd,
|
||||
cutlass::conv::IteratorAlgorithm::kAnalytic,
|
||||
cutlass::conv::StrideSupport::kStrided
|
||||
>::Kernel;
|
||||
|
||||
using Conv3dDgrad = cutlass::conv::device::ImplicitGemmConvolution<Conv3dDgradKernel>;
|
||||
|
||||
/// Run all unit test sizes with device-level Conv3d instance
|
||||
EXPECT_TRUE(test::conv::device::TestAllConv3d<Conv3dDgrad>());
|
||||
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
TEST(SM80_Device_Conv3d_Dgrad_Optimized_ImplicitGemm_f32ndhwc_f32ndhwc_f32ndhwc_simt_f32,
|
||||
128x128_8x4_64x32x8) {
|
||||
|
||||
/// Conv operation element types for the Gemm equivalent (ImplicitGemm)
|
||||
using ElementA = float;
|
||||
using ElementB = float;
|
||||
using ElementC = float;
|
||||
using ElementAccumulator = float;
|
||||
using ElementCompute = float;
|
||||
|
||||
|
||||
/// Device-level Conv3d instance
|
||||
using Conv3dDgradKernel = typename cutlass::conv::kernel::DefaultConv3dDgrad<
|
||||
ElementA,
|
||||
cutlass::layout::TensorNDHWC,
|
||||
ElementB,
|
||||
cutlass::layout::TensorNDHWC,
|
||||
ElementC,
|
||||
cutlass::layout::TensorNDHWC,
|
||||
ElementAccumulator,
|
||||
cutlass::arch::OpClassSimt,
|
||||
cutlass::arch::Sm80,
|
||||
cutlass::gemm::GemmShape<128, 128, 8>,
|
||||
cutlass::gemm::GemmShape<64, 32, 8>,
|
||||
cutlass::gemm::GemmShape<1, 1, 1>,
|
||||
cutlass::epilogue::thread::LinearCombination<
|
||||
ElementC,
|
||||
1,
|
||||
ElementAccumulator,
|
||||
ElementCompute
|
||||
>,
|
||||
cutlass::gemm::threadblock::GemmIdentityThreadblockSwizzle<>,
|
||||
4,
|
||||
cutlass::arch::OpMultiplyAdd,
|
||||
cutlass::conv::IteratorAlgorithm::kOptimized,
|
||||
cutlass::conv::StrideSupport::kUnity
|
||||
>::Kernel;
|
||||
|
||||
using Conv3dDgrad = cutlass::conv::device::ImplicitGemmConvolution<Conv3dDgradKernel>;
|
||||
|
||||
/// Run all unit test sizes with device-level Conv3d instance
|
||||
EXPECT_TRUE(test::conv::device::TestAllConv3d<Conv3dDgrad>());
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#endif // CUTLASS_ARCH_MMA_SM80_SUPPORTED
|
||||
+137
@@ -0,0 +1,137 @@
|
||||
/***************************************************************************************************
|
||||
* Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
**************************************************************************************************/
|
||||
/*! \file
|
||||
\brief Tests for device-wide Implicit GEMM interface
|
||||
*/
|
||||
|
||||
#include "../../common/cutlass_unit_test.h"
|
||||
#include "cutlass/cutlass.h"
|
||||
|
||||
|
||||
#include "cutlass/conv/kernel/default_conv3d_fprop.h"
|
||||
#include "cutlass/conv/device/implicit_gemm_convolution.h"
|
||||
|
||||
#include "conv3d_testbed.h"
|
||||
|
||||
#if defined(CUTLASS_ARCH_MMA_SM80_SUPPORTED)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
TEST(SM80_Device_Conv3d_Fprop_Analytic_ImplicitGemm_f32ndhwc_f32ndhwc_f32ndhwc_simt_f32,
|
||||
128x128_8x4_32x64x8) {
|
||||
|
||||
/// Conv operation element types for the Gemm equivalent (ImplicitGemm)
|
||||
using ElementA = float;
|
||||
using ElementB = float;
|
||||
using ElementC = float;
|
||||
using ElementAccumulator = float;
|
||||
using ElementCompute = float;
|
||||
|
||||
|
||||
/// Device-level Conv3d instance
|
||||
using Conv3dFpropKernel = typename cutlass::conv::kernel::DefaultConv3dFprop<
|
||||
ElementA,
|
||||
cutlass::layout::TensorNDHWC,
|
||||
ElementB,
|
||||
cutlass::layout::TensorNDHWC,
|
||||
ElementC,
|
||||
cutlass::layout::TensorNDHWC,
|
||||
ElementAccumulator,
|
||||
cutlass::arch::OpClassSimt,
|
||||
cutlass::arch::Sm80,
|
||||
cutlass::gemm::GemmShape<128, 128, 8>,
|
||||
cutlass::gemm::GemmShape<32, 64, 8>,
|
||||
cutlass::gemm::GemmShape<1, 1, 1>,
|
||||
cutlass::epilogue::thread::LinearCombination<
|
||||
ElementC,
|
||||
1,
|
||||
ElementAccumulator,
|
||||
ElementCompute
|
||||
>,
|
||||
cutlass::gemm::threadblock::GemmIdentityThreadblockSwizzle<>,
|
||||
4,
|
||||
cutlass::arch::OpMultiplyAdd,
|
||||
cutlass::conv::IteratorAlgorithm::kAnalytic
|
||||
>::Kernel;
|
||||
|
||||
using Conv3dFprop = cutlass::conv::device::ImplicitGemmConvolution<Conv3dFpropKernel>;
|
||||
|
||||
/// Run all unit test sizes with device-level Conv3d instance
|
||||
EXPECT_TRUE(test::conv::device::TestAllConv3d<Conv3dFprop>());
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
TEST(SM80_Device_Conv3d_Fprop_Optimized_ImplicitGemm_f32ndhwc_f32ndhwc_f32ndhwc_simt_f32,
|
||||
128x128_8x4_64x32x8) {
|
||||
|
||||
/// Conv operation element types for the Gemm equivalent (ImplicitGemm)
|
||||
using ElementA = float;
|
||||
using ElementB = float;
|
||||
using ElementC = float;
|
||||
using ElementAccumulator = float;
|
||||
using ElementCompute = float;
|
||||
|
||||
|
||||
/// Device-level Conv3d instance
|
||||
using Conv3dFpropKernel = typename cutlass::conv::kernel::DefaultConv3dFprop<
|
||||
ElementA,
|
||||
cutlass::layout::TensorNDHWC,
|
||||
ElementB,
|
||||
cutlass::layout::TensorNDHWC,
|
||||
ElementC,
|
||||
cutlass::layout::TensorNDHWC,
|
||||
ElementAccumulator,
|
||||
cutlass::arch::OpClassSimt,
|
||||
cutlass::arch::Sm80,
|
||||
cutlass::gemm::GemmShape<128, 128, 8>,
|
||||
cutlass::gemm::GemmShape<64, 32, 8>,
|
||||
cutlass::gemm::GemmShape<1, 1, 1>,
|
||||
cutlass::epilogue::thread::LinearCombination<
|
||||
ElementC,
|
||||
1,
|
||||
ElementAccumulator,
|
||||
ElementCompute
|
||||
>,
|
||||
cutlass::gemm::threadblock::GemmIdentityThreadblockSwizzle<>,
|
||||
4,
|
||||
cutlass::arch::OpMultiplyAdd,
|
||||
cutlass::conv::IteratorAlgorithm::kOptimized
|
||||
>::Kernel;
|
||||
|
||||
using Conv3dFprop = cutlass::conv::device::ImplicitGemmConvolution<Conv3dFpropKernel>;
|
||||
|
||||
/// Run all unit test sizes with device-level Conv3d instance
|
||||
EXPECT_TRUE(test::conv::device::TestAllConv3d<Conv3dFprop>());
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#endif // CUTLASS_ARCH_MMA_SM80_SUPPORTED
|
||||
@@ -0,0 +1,171 @@
|
||||
/***************************************************************************************************
|
||||
* Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
**************************************************************************************************/
|
||||
/*! \file
|
||||
\brief Tests for device-wide Implicit GEMM interface
|
||||
*/
|
||||
|
||||
#include "../../common/cutlass_unit_test.h"
|
||||
#include "cutlass/cutlass.h"
|
||||
#include "cutlass/array.h"
|
||||
#include "cutlass/epilogue/thread/linear_combination_bias_elementwise.h"
|
||||
#include "cutlass/epilogue/thread/linear_combination_residual_block.h"
|
||||
#include "cutlass/epilogue/thread/activation.h"
|
||||
#include "cutlass/conv/kernel/default_conv3d_fprop_with_broadcast.h"
|
||||
#include "cutlass/conv/device/implicit_gemm_convolution.h"
|
||||
|
||||
#include "conv3d_with_broadcast_testbed.h"
|
||||
|
||||
#if defined(CUTLASS_ARCH_MMA_SM80_SUPPORTED)
|
||||
|
||||
|
||||
TEST(SM80_Device_Conv3d_Fprop_With_Broadcast_Analytic_ImplicitGemm_f32ndhwc_f32ndhwc_f32ndhwc_simt_f32,
|
||||
128x128_32x2_64x64x32) {
|
||||
|
||||
/// Conv operation element types for the Gemm equivalent (ImplicitGemm)
|
||||
using ElementA = float;
|
||||
using ElementB = float;
|
||||
using ElementC = float;
|
||||
using ElementCompute = float;
|
||||
using ElementAccumulator = float;
|
||||
|
||||
using EpilogueOutputOp = cutlass::epilogue::thread::LinearCombinationBiasElementwise<
|
||||
ElementC,
|
||||
ElementAccumulator,
|
||||
ElementCompute,
|
||||
ElementC,
|
||||
ElementC,
|
||||
1,
|
||||
cutlass::epilogue::thread::ReLu<float>
|
||||
>;
|
||||
|
||||
/// Device-level Conv3d instance
|
||||
using Conv3dFpropKernel = typename cutlass::conv::kernel::DefaultConv3dFpropWithBroadcast<
|
||||
ElementA, cutlass::layout::TensorNDHWC,
|
||||
ElementB, cutlass::layout::TensorNDHWC,
|
||||
ElementC, cutlass::layout::TensorNDHWC,
|
||||
ElementAccumulator,
|
||||
cutlass::arch::OpClassSimt,
|
||||
cutlass::arch::Sm80,
|
||||
cutlass::gemm::GemmShape<128, 128, 8>,
|
||||
cutlass::gemm::GemmShape<32, 64, 8>,
|
||||
cutlass::gemm::GemmShape<1, 1, 1>,
|
||||
EpilogueOutputOp,
|
||||
cutlass::gemm::threadblock::GemmIdentityThreadblockSwizzle<>,
|
||||
4,
|
||||
cutlass::arch::OpMultiplyAdd,
|
||||
cutlass::conv::IteratorAlgorithm::kAnalytic
|
||||
>::Kernel;
|
||||
|
||||
using Conv3dFprop = cutlass::conv::device::ImplicitGemmConvolution<Conv3dFpropKernel>;
|
||||
|
||||
/// Run all unit test sizes with device-level Conv3d instance
|
||||
EXPECT_TRUE(test::conv::device::TestAllConv3dWithBroadcast<Conv3dFprop>());
|
||||
}
|
||||
|
||||
// Test residual block fusion: UnaryOp(BinaryOp(ActivationOp(Conv3d(X) + bias), residual))
|
||||
// LinearCombinationResidualBlock does not support the split-k mode unless ActivationOp is Identity.
|
||||
// This is because the activation needs to be applied to the fully accumulated output of the Conv3d op,
|
||||
// which only the last thread block would have an access to, before applying BinaryOp.
|
||||
// The epilogue functor in the last thread block would have to be given three inputs, namely
|
||||
// partial outputs, bias, and residual, but this is not supported in the current interface.
|
||||
// Set TestSplitK = false to skip split-k tests with non-trivial ActivationOp.
|
||||
template <
|
||||
template<typename T> class ActivationOp,
|
||||
template<typename T> class BinaryOp,
|
||||
template<typename T> class UnaryOp,
|
||||
bool TestSplitK = true
|
||||
>
|
||||
void TestResidaulBlock() {
|
||||
using ElementA = float;
|
||||
using ElementB = float;
|
||||
using ElementC = float;
|
||||
using ElementD = ElementC;
|
||||
using ElementCompute = float;
|
||||
using ElementAccumulator = float;
|
||||
|
||||
using EpilogueOutputOp = cutlass::epilogue::thread::LinearCombinationResidualBlock<
|
||||
ElementD,
|
||||
ElementAccumulator,
|
||||
ElementCompute,
|
||||
ElementC,
|
||||
1,
|
||||
ActivationOp,
|
||||
BinaryOp,
|
||||
UnaryOp
|
||||
>;
|
||||
|
||||
using Conv3dFpropKernel = typename cutlass::conv::kernel::DefaultConv3dFpropWithBroadcast<
|
||||
ElementA, cutlass::layout::TensorNDHWC,
|
||||
ElementB, cutlass::layout::TensorNDHWC,
|
||||
ElementC, cutlass::layout::TensorNDHWC,
|
||||
ElementAccumulator,
|
||||
cutlass::arch::OpClassSimt,
|
||||
cutlass::arch::Sm80,
|
||||
cutlass::gemm::GemmShape<128, 128, 8>,
|
||||
cutlass::gemm::GemmShape<32, 64, 8>,
|
||||
cutlass::gemm::GemmShape<1, 1, 1>,
|
||||
EpilogueOutputOp,
|
||||
cutlass::gemm::threadblock::GemmIdentityThreadblockSwizzle<>,
|
||||
4,
|
||||
cutlass::arch::OpMultiplyAdd,
|
||||
cutlass::conv::IteratorAlgorithm::kAnalytic
|
||||
>::Kernel;
|
||||
|
||||
using Conv3dFprop = cutlass::conv::device::ImplicitGemmConvolution<Conv3dFpropKernel>;
|
||||
|
||||
struct ReferenceOp {
|
||||
using OutputOp = typename Conv3dFprop::EpilogueOutputOp;
|
||||
using ElementZ = typename OutputOp::ElementZ;
|
||||
|
||||
ActivationOp<ElementCompute> activation;
|
||||
BinaryOp<ElementCompute> binary_op;
|
||||
UnaryOp<ElementCompute> unary_op;
|
||||
|
||||
void operator()(ElementZ &Z, ElementZ&, ElementCompute conv3d, ElementCompute residual) {
|
||||
Z = ElementZ(unary_op(binary_op(activation(conv3d), residual)));
|
||||
}
|
||||
};
|
||||
|
||||
bool passed = test::conv::device::TestAllConv3dWithBroadcast<Conv3dFprop, ReferenceOp, true, TestSplitK>();
|
||||
EXPECT_TRUE(passed);
|
||||
}
|
||||
|
||||
TEST(SM80_Device_Conv3d_Fprop_With_Residual_Block_Plus_Analytic_ImplicitGemm_f32ndhwc_f32ndhwc_f32ndhwc_simt_f32,
|
||||
128x128_8x4_32x64x8) {
|
||||
// Resnet
|
||||
TestResidaulBlock<cutlass::epilogue::thread::Identity, cutlass::plus, cutlass::epilogue::thread::ReLu>();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif // CUTLASS_ARCH_MMA_SM80_SUPPORTED
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -117,6 +117,17 @@ struct TestbedConv3dProblemSizes {
|
||||
{8, 1, 1, 3, minimum_channel_size}, // filter size (KTRSC)
|
||||
cutlass::Coord<3>({1, 1, 1}), // padding (pad_d, pad_h, pad_w)
|
||||
cutlass::Coord<3>({1, 1, 1}), // stride (stride_d, stride_h, stride_w)
|
||||
cutlass::Coord<3>({1, 1, 1}) // dilation (dilation_d, dilation_h, dilation_w)
|
||||
));
|
||||
|
||||
conv3d_default_sizes.push_back(cutlass::conv::Conv3dProblemSize(
|
||||
{1, 1, 1, 8, minimum_channel_size}, // input size (NDHWC)
|
||||
{8, 1, 1, 3, minimum_channel_size}, // filter size (KTRSC)
|
||||
CUTLASS_STL_NAMESPACE::make_tuple(
|
||||
cutlass::Coord<3>({1, 1, 1}), // near padding (pad_d, pad_h, pad_w)
|
||||
cutlass::Coord<3>({0, 0, 0}) // far padding (pad_d, pad_h, pad_w)
|
||||
),
|
||||
cutlass::Coord<3>({1, 1, 1}), // stride (stride_d, stride_h, stride_w)
|
||||
cutlass::Coord<3>({1, 1, 1}) // dilation (dilation_d, dilation_h, dilation_w)
|
||||
));
|
||||
|
||||
@@ -128,6 +139,17 @@ struct TestbedConv3dProblemSizes {
|
||||
cutlass::Coord<3>({1, 1, 1}) // dilation (dilation_d, dilation_h, dilation_w)
|
||||
));
|
||||
|
||||
conv3d_default_sizes.push_back(cutlass::conv::Conv3dProblemSize(
|
||||
{1, 8, 8, 8, minimum_channel_size}, // input size (NDHWC)
|
||||
{8, 3, 3, 3, minimum_channel_size}, // filter size (KTRSC)
|
||||
CUTLASS_STL_NAMESPACE::make_tuple(
|
||||
cutlass::Coord<3>({1, 1, 1}), // near padding (pad_d, pad_h, pad_w)
|
||||
cutlass::Coord<3>({0, 0, 0}) // far padding (pad_d, pad_h, pad_w)
|
||||
),
|
||||
cutlass::Coord<3>({1, 1, 1}), // stride (stride_d, stride_h, stride_w)
|
||||
cutlass::Coord<3>({1, 1, 1}) // dilation (dilation_d, dilation_h, dilation_w)
|
||||
));
|
||||
|
||||
conv3d_default_sizes.push_back(cutlass::conv::Conv3dProblemSize(
|
||||
{1, 16, 16, 16, minimum_channel_size}, // input size (NDHWC)
|
||||
{8, 3, 3, 3, minimum_channel_size}, // filter size (KTRSC)
|
||||
|
||||
@@ -184,7 +184,7 @@ public:
|
||||
// Determine SMEM requirements and waive if not satisfied
|
||||
//
|
||||
|
||||
int smem_size = int(sizeof(typename Conv3d::UnderlyingKernel::SharedStorage));
|
||||
size_t smem_size = sizeof(typename Conv3d::UnderlyingKernel::SharedStorage);
|
||||
|
||||
cudaDeviceProp properties;
|
||||
int device_idx;
|
||||
@@ -662,6 +662,47 @@ bool TestAllConv3d(
|
||||
return passed;
|
||||
}
|
||||
|
||||
template <typename ImplicitGemm>
|
||||
bool TestSpecificConv3d(
|
||||
const Conv3dProblemVector & problem_sizes) {
|
||||
|
||||
bool passed = true;
|
||||
|
||||
//
|
||||
// Testbed object
|
||||
//
|
||||
|
||||
TestbedConv3d<ImplicitGemm> testbed;
|
||||
|
||||
// Sweep conv3d problem sizes (split-k-mode=kSerial, split-k-slice=1, alpha=1.0, beta=0.0)
|
||||
for(auto conv_problem : problem_sizes) {
|
||||
|
||||
//
|
||||
// Test
|
||||
//
|
||||
|
||||
// test mode = xcross
|
||||
passed = testbed.run(
|
||||
conv_problem,
|
||||
cutlass::conv::SplitKMode::kSerial);
|
||||
|
||||
if (!passed) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// test mode = convolution
|
||||
passed = testbed.run(
|
||||
conv_problem.reset_mode(cutlass::conv::Mode::kConvolution),
|
||||
cutlass::conv::SplitKMode::kSerial);
|
||||
|
||||
if (!passed) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
} // namespace device
|
||||
|
||||
+136
@@ -0,0 +1,136 @@
|
||||
/***************************************************************************************************
|
||||
* Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
**************************************************************************************************/
|
||||
/*! \file
|
||||
\brief Tests for device-wide Implicit GEMM interface
|
||||
*/
|
||||
|
||||
#include "../../common/cutlass_unit_test.h"
|
||||
#include "cutlass/cutlass.h"
|
||||
|
||||
#include "cutlass/conv/kernel/default_conv3d_wgrad.h"
|
||||
#include "cutlass/conv/device/implicit_gemm_convolution.h"
|
||||
|
||||
#include "conv3d_testbed.h"
|
||||
|
||||
#if defined(CUTLASS_ARCH_MMA_SM80_SUPPORTED)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
TEST(SM80_Device_Conv3d_Wgrad_Analytic_ImplicitGemm_f32ndhwc_f32ndhwc_f32ndhwc_simt_f32,
|
||||
128x128_8x4_32x64x8) {
|
||||
|
||||
/// Conv operation element types for the Gemm equivalent (ImplicitGemm)
|
||||
using ElementA = float;
|
||||
using ElementB = float;
|
||||
using ElementC = float;
|
||||
using ElementAccumulator = float;
|
||||
using ElementCompute = float;
|
||||
|
||||
|
||||
/// Device-level Conv3d instance
|
||||
using Conv3dWgradKernel = typename cutlass::conv::kernel::DefaultConv3dWgrad<
|
||||
ElementA,
|
||||
cutlass::layout::TensorNDHWC,
|
||||
ElementB,
|
||||
cutlass::layout::TensorNDHWC,
|
||||
ElementC,
|
||||
cutlass::layout::TensorNDHWC,
|
||||
ElementAccumulator,
|
||||
cutlass::arch::OpClassSimt,
|
||||
cutlass::arch::Sm80,
|
||||
cutlass::gemm::GemmShape<128, 128, 8>,
|
||||
cutlass::gemm::GemmShape<32, 64, 8>,
|
||||
cutlass::gemm::GemmShape<1, 1, 1>,
|
||||
cutlass::epilogue::thread::LinearCombination<
|
||||
ElementC,
|
||||
1,
|
||||
ElementAccumulator,
|
||||
ElementCompute
|
||||
>,
|
||||
cutlass::gemm::threadblock::GemmIdentityThreadblockSwizzle<>,
|
||||
4,
|
||||
cutlass::arch::OpMultiplyAdd,
|
||||
cutlass::conv::IteratorAlgorithm::kAnalytic
|
||||
>::Kernel;
|
||||
|
||||
using Conv3dWgrad = cutlass::conv::device::ImplicitGemmConvolution<Conv3dWgradKernel>;
|
||||
|
||||
/// Run all unit test sizes with device-level Conv3d instance
|
||||
EXPECT_TRUE(test::conv::device::TestAllConv3d<Conv3dWgrad>());
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
TEST(SM80_Device_Conv3d_Wgrad_Optimized_ImplicitGemm_f32ndhwc_f32ndhwc_f32ndhwc_simt_f32,
|
||||
128x128_8x4_64x32x8) {
|
||||
|
||||
/// Conv operation element types for the Gemm equivalent (ImplicitGemm)
|
||||
using ElementA = float;
|
||||
using ElementB = float;
|
||||
using ElementC = float;
|
||||
using ElementAccumulator = float;
|
||||
using ElementCompute = float;
|
||||
|
||||
|
||||
/// Device-level Conv3d instance
|
||||
using Conv3dWgradKernel = typename cutlass::conv::kernel::DefaultConv3dWgrad<
|
||||
ElementA,
|
||||
cutlass::layout::TensorNDHWC,
|
||||
ElementB,
|
||||
cutlass::layout::TensorNDHWC,
|
||||
ElementC,
|
||||
cutlass::layout::TensorNDHWC,
|
||||
ElementAccumulator,
|
||||
cutlass::arch::OpClassSimt,
|
||||
cutlass::arch::Sm80,
|
||||
cutlass::gemm::GemmShape<128, 128, 8>,
|
||||
cutlass::gemm::GemmShape<64, 32, 8>,
|
||||
cutlass::gemm::GemmShape<1, 1, 1>,
|
||||
cutlass::epilogue::thread::LinearCombination<
|
||||
ElementC,
|
||||
1,
|
||||
ElementAccumulator,
|
||||
ElementCompute
|
||||
>,
|
||||
cutlass::gemm::threadblock::GemmIdentityThreadblockSwizzle<>,
|
||||
4,
|
||||
cutlass::arch::OpMultiplyAdd,
|
||||
cutlass::conv::IteratorAlgorithm::kOptimized
|
||||
>::Kernel;
|
||||
|
||||
using Conv3dWgrad = cutlass::conv::device::ImplicitGemmConvolution<Conv3dWgradKernel>;
|
||||
|
||||
/// Run all unit test sizes with device-level Conv3d instance
|
||||
EXPECT_TRUE(test::conv::device::TestAllConv3d<Conv3dWgrad>());
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#endif // CUTLASS_ARCH_MMA_SM80_SUPPORTED
|
||||
@@ -0,0 +1,716 @@
|
||||
/***************************************************************************************************
|
||||
* Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
**************************************************************************************************/
|
||||
/*! \file
|
||||
\brief Implicit GEMM for fused epilogue broadcast testbed
|
||||
|
||||
Parallel split-k is not tested because we can just use regular conv kernel
|
||||
when we need to use parallel-splitk. Broadcast can happen in the reduction
|
||||
kernel.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#include "../../common/cutlass_unit_test.h"
|
||||
#include "cutlass/cutlass.h"
|
||||
|
||||
#include "cutlass/conv/device/implicit_gemm_convolution.h"
|
||||
#include "cutlass/reduction/device/reduce_split_k.h"
|
||||
#include "cutlass/reduction/thread/reduction_operators.h"
|
||||
|
||||
#include "conv3d_problems.h"
|
||||
|
||||
#include "cutlass/util/host_tensor.h"
|
||||
#include "cutlass/util/reference/host/tensor_fill.h"
|
||||
#include "cutlass/util/reference/device/tensor_compare.h"
|
||||
#include "cutlass/util/reference/host/tensor_compare.h"
|
||||
|
||||
#include "cutlass/util/reference/host/convolution.h"
|
||||
#include "cutlass/util/reference/device/convolution.h"
|
||||
|
||||
#include "cutlass/core_io.h"
|
||||
#include "cutlass/util/tensor_view_io.h"
|
||||
|
||||
#include "../cache_testbed_output.h"
|
||||
|
||||
namespace test {
|
||||
namespace conv {
|
||||
namespace device {
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template <typename Conv3d>
|
||||
struct Conv3dWithBroadcastReferenceOp {
|
||||
|
||||
using OutputOp = typename Conv3d::EpilogueOutputOp;
|
||||
|
||||
using ElementCompute = typename OutputOp::ElementCompute;
|
||||
using ElementZ = typename OutputOp::ElementZ;
|
||||
using ElementT = typename OutputOp::ElementT;
|
||||
|
||||
typename OutputOp::BinaryOp binary_op;
|
||||
typename OutputOp::ElementwiseOp elementwise_op;
|
||||
|
||||
Conv3dWithBroadcastReferenceOp() { }
|
||||
|
||||
void operator()(ElementZ &Z, ElementT &T, ElementCompute conv3d, ElementCompute bias) {
|
||||
ElementCompute t_full = binary_op(conv3d, bias);
|
||||
T = ElementT(t_full);
|
||||
|
||||
ElementCompute z_full = elementwise_op(t_full);
|
||||
Z = ElementZ(z_full);
|
||||
}
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Fused testbed
|
||||
//
|
||||
// Y = CONV(AB, C)
|
||||
//
|
||||
// T[n, o, p, q, k] = ReductionOp(Y[n, o, p, q, k], Broadcast[k])
|
||||
//
|
||||
// Z[n, o, p, q, k] = Elementwise(T[n, o, p, q, k])
|
||||
//
|
||||
|
||||
template <
|
||||
typename Conv3d,
|
||||
typename ReferenceOp,
|
||||
bool AddBroadcastFirst = false
|
||||
>
|
||||
class TestbedConv3dWithBroadcast {
|
||||
public:
|
||||
|
||||
using ElementA = typename Conv3d::ElementA;
|
||||
using LayoutA = typename Conv3d::LayoutA;
|
||||
using ElementB = typename Conv3d::ElementB;
|
||||
using LayoutB = typename Conv3d::LayoutB;
|
||||
using ElementC = typename Conv3d::ElementC;
|
||||
using LayoutC = typename Conv3d::LayoutC;
|
||||
using ElementAccumulator = typename Conv3d::ElementAccumulator;
|
||||
using ElementCompute = typename Conv3d::ElementCompute;
|
||||
using EpilogueOutputOp = typename Conv3d::EpilogueOutputOp;
|
||||
using ElementZ = typename EpilogueOutputOp::ElementZ;
|
||||
using ElementT = typename EpilogueOutputOp::ElementT;
|
||||
using ElementVector = typename EpilogueOutputOp::ElementVector;
|
||||
|
||||
static cutlass::conv::Operator const kConvolutionalOperator = Conv3d::kConvolutionalOperator;
|
||||
static const bool kAddBroadcastFirst = AddBroadcastFirst;
|
||||
static const bool kStoreT = EpilogueOutputOp::kStoreT;
|
||||
|
||||
public:
|
||||
|
||||
/// Initialization
|
||||
cutlass::Distribution::Kind init_A;
|
||||
cutlass::Distribution::Kind init_B;
|
||||
cutlass::Distribution::Kind init_C;
|
||||
uint64_t seed;
|
||||
|
||||
cutlass::HostTensor<ElementA, LayoutA> tensor_A;
|
||||
cutlass::HostTensor<ElementB, LayoutB> tensor_B;
|
||||
cutlass::HostTensor<ElementC, LayoutC> tensor_C;
|
||||
cutlass::HostTensor<ElementAccumulator, LayoutC> tensor_C_reference;
|
||||
cutlass::HostTensor<ElementZ, LayoutC> tensor_Z_computed;
|
||||
cutlass::HostTensor<ElementZ, LayoutC> tensor_Z_reference;
|
||||
cutlass::HostTensor<ElementT, LayoutC> tensor_T_computed;
|
||||
cutlass::HostTensor<ElementT, LayoutC> tensor_T_reference;
|
||||
cutlass::HostTensor<ElementAccumulator, LayoutC> tensor_Y_reference;
|
||||
cutlass::HostTensor<ElementVector, LayoutC> tensor_Broadcast; // Input Broadcast
|
||||
|
||||
public:
|
||||
|
||||
TestbedConv3dWithBroadcast(
|
||||
cutlass::Distribution::Kind init_A_ = cutlass::Distribution::Uniform,
|
||||
cutlass::Distribution::Kind init_B_ = cutlass::Distribution::Uniform,
|
||||
cutlass::Distribution::Kind init_C_ = cutlass::Distribution::Uniform,
|
||||
uint64_t seed_ = 2080
|
||||
):
|
||||
init_A(init_A_), init_B(init_B_), init_C(init_C_), seed(seed_) {
|
||||
|
||||
}
|
||||
|
||||
/// Helper to initialize a tensor view
|
||||
template <typename Element, typename Layout>
|
||||
void initialize_tensor(
|
||||
cutlass::TensorView<Element, Layout> view,
|
||||
cutlass::Distribution::Kind dist_kind,
|
||||
uint64_t seed) {
|
||||
|
||||
if (dist_kind == cutlass::Distribution::Uniform) {
|
||||
|
||||
int scope;
|
||||
int bits = cutlass::sizeof_bits<Element>::value;
|
||||
|
||||
if (bits <= 8) {
|
||||
scope = 2;
|
||||
}
|
||||
else if (bits == 16) {
|
||||
if (cutlass::sizeof_bits<ElementAccumulator>::value <= 16) {
|
||||
scope = 3;
|
||||
}
|
||||
else {
|
||||
scope = 5;
|
||||
}
|
||||
}
|
||||
else {
|
||||
scope = 8;
|
||||
}
|
||||
|
||||
cutlass::reference::host::TensorFillRandomUniform(
|
||||
view, seed, scope, -scope, 0);
|
||||
}
|
||||
else if (dist_kind == cutlass::Distribution::Identity) {
|
||||
|
||||
cutlass::reference::host::TensorFillIdentity(view);
|
||||
}
|
||||
else if (dist_kind == cutlass::Distribution::Gaussian) {
|
||||
|
||||
cutlass::reference::host::TensorFillRandomGaussian(view, seed, 0, 0.5);
|
||||
}
|
||||
else if (dist_kind == cutlass::Distribution::Sequential) {
|
||||
|
||||
cutlass::reference::host::BlockFillSequential(view.data(), view.capacity());
|
||||
}
|
||||
else {
|
||||
}
|
||||
}
|
||||
|
||||
void initialize(
|
||||
cutlass::conv::Conv3dProblemSize const &problem_size, uint64_t seed = 2019) {
|
||||
|
||||
tensor_A.resize(implicit_gemm_tensor_a_extent(kConvolutionalOperator, problem_size));
|
||||
tensor_B.resize(implicit_gemm_tensor_b_extent(kConvolutionalOperator, problem_size));
|
||||
tensor_C.resize(implicit_gemm_tensor_c_extent(kConvolutionalOperator, problem_size));
|
||||
tensor_C_reference.resize(implicit_gemm_tensor_c_extent(kConvolutionalOperator, problem_size));
|
||||
tensor_Z_computed.resize(implicit_gemm_tensor_c_extent(kConvolutionalOperator, problem_size));
|
||||
tensor_Z_reference.resize(implicit_gemm_tensor_c_extent(kConvolutionalOperator, problem_size));
|
||||
tensor_T_computed.resize(implicit_gemm_tensor_c_extent(kConvolutionalOperator, problem_size));
|
||||
tensor_T_reference.resize(implicit_gemm_tensor_c_extent(kConvolutionalOperator, problem_size));
|
||||
tensor_Y_reference.resize(implicit_gemm_tensor_c_extent(kConvolutionalOperator, problem_size));
|
||||
tensor_Broadcast.resize({
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
implicit_gemm_tensor_c_extent(kConvolutionalOperator, problem_size).c(),
|
||||
});
|
||||
|
||||
initialize_tensor(tensor_A.host_view(), init_A, seed);
|
||||
initialize_tensor(tensor_B.host_view(), init_B, seed * 17);
|
||||
initialize_tensor(tensor_C.host_view(), init_C, seed * 39);
|
||||
initialize_tensor(tensor_Broadcast.host_view(), init_C, seed * 39);
|
||||
|
||||
for (int n = 0; n < tensor_C_reference.extent().n(); ++n) {
|
||||
for (int o = 0; o < tensor_C_reference.extent().d(); ++o) {
|
||||
for (int p = 0; p < tensor_C_reference.extent().h(); ++p) {
|
||||
for (int q = 0; q < tensor_C_reference.extent().w(); ++q) {
|
||||
for (int k = 0; k < tensor_C_reference.extent().c(); ++k) {
|
||||
tensor_C_reference.at({n, o, p, q, k}) = ElementAccumulator(tensor_C.at({n, o, p, q, k}));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tensor_A.sync_device();
|
||||
tensor_B.sync_device();
|
||||
tensor_C.sync_device();
|
||||
tensor_Broadcast.sync_device();
|
||||
tensor_C_reference.sync_device();
|
||||
tensor_Z_computed.sync_device();
|
||||
tensor_Z_reference.sync_device();
|
||||
tensor_T_computed.sync_device();
|
||||
tensor_T_reference.sync_device();
|
||||
tensor_Y_reference.sync_device();
|
||||
}
|
||||
|
||||
bool sufficient() const {
|
||||
//
|
||||
// Determine SMEM requirements and waive if not satisfied
|
||||
//
|
||||
|
||||
size_t smem_size = sizeof(typename Conv3d::UnderlyingKernel::SharedStorage);
|
||||
|
||||
cudaDeviceProp properties;
|
||||
int device_idx;
|
||||
cudaError_t result = cudaGetDevice(&device_idx);
|
||||
|
||||
if (result != cudaSuccess) {
|
||||
throw std::runtime_error("cudaGetDevice() API call failed.");
|
||||
}
|
||||
|
||||
result = cudaGetDeviceProperties(&properties, device_idx);
|
||||
|
||||
if (result != cudaSuccess) {
|
||||
throw std::runtime_error("cudaGetDeviceProperties() failed");
|
||||
}
|
||||
|
||||
if (properties.sharedMemPerBlockOptin < smem_size) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Executes one test
|
||||
bool run(
|
||||
cutlass::conv::Conv3dProblemSize const &problem_size,
|
||||
cutlass::conv::SplitKMode const &split_k_mode = cutlass::conv::SplitKMode::kSerial,
|
||||
ElementCompute alpha = ElementCompute(1),
|
||||
ElementCompute beta = ElementCompute(1)) {
|
||||
|
||||
// Waive test if insufficient CUDA device
|
||||
if (!sufficient()) {
|
||||
if (CUTLASS_TEST_UNIT_ENABLE_WARNINGS) {
|
||||
std::cerr << "Test waived due to insufficient CUDA device." << std::endl;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#if 0 //display conv3d problem size for debugging
|
||||
std::cout << problem_size << std::endl
|
||||
<< "alpha, beta: (" << alpha << ", " << beta << ")" << std::endl
|
||||
<< "split_k_mode: " << ((split_k_mode == cutlass::conv::SplitKMode::kSerial) ? "(serial)" : "(parallel)") << std::endl
|
||||
<< std::endl;
|
||||
#endif
|
||||
|
||||
initialize(problem_size);
|
||||
|
||||
// configure the operator
|
||||
Conv3d conv3d_op;
|
||||
typename Conv3d::Arguments conv3d_args(
|
||||
problem_size,
|
||||
tensor_A.device_ref(),
|
||||
tensor_B.device_ref(),
|
||||
tensor_C.device_ref(),
|
||||
tensor_Z_computed.device_ref(),
|
||||
{alpha, beta},
|
||||
split_k_mode,
|
||||
tensor_Broadcast.device_data(),
|
||||
kStoreT ? tensor_T_computed.device_data() : nullptr,
|
||||
0, // This must be zero
|
||||
implicit_gemm_tensor_c_extent(kConvolutionalOperator, problem_size).c()
|
||||
);
|
||||
|
||||
// initialize the kernel
|
||||
size_t workspace_size = Conv3d::get_workspace_size(conv3d_args);
|
||||
|
||||
cutlass::device_memory::allocation<uint8_t> workspace(workspace_size);
|
||||
|
||||
cutlass::Status status = conv3d_op.initialize(conv3d_args, workspace.get());
|
||||
|
||||
if (status != cutlass::Status::kSuccess) {
|
||||
cudaError_t error = cudaGetLastError();
|
||||
std::cerr << "This test is not supported: " << cudaGetErrorString(error) << "\n";
|
||||
return true;
|
||||
}
|
||||
|
||||
// run conv3d operator
|
||||
status = conv3d_op();
|
||||
|
||||
EXPECT_TRUE(status == cutlass::Status::kSuccess);
|
||||
if (status != cutlass::Status::kSuccess) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool passed = false;
|
||||
|
||||
cudaError_t result = cudaDeviceSynchronize();
|
||||
EXPECT_EQ(result, cudaSuccess) << " device reference error: "
|
||||
<< cudaGetErrorString(result);
|
||||
|
||||
tensor_T_computed.sync_host();
|
||||
tensor_Z_computed.sync_host();
|
||||
|
||||
//
|
||||
// Reference check
|
||||
//
|
||||
|
||||
// When kAddBroadcastFirst is true, add bias on the host
|
||||
ElementCompute beta_ref = kAddBroadcastFirst ? ElementCompute(0) : beta;
|
||||
|
||||
#if CUTLASS_CONV_TEST_UNIT_REFERENCE_DEVICE_ENABLED
|
||||
|
||||
cutlass::reference::device::Conv3d<
|
||||
ElementA,
|
||||
LayoutA,
|
||||
ElementB,
|
||||
LayoutB,
|
||||
ElementAccumulator,
|
||||
LayoutC,
|
||||
ElementAccumulator,
|
||||
ElementAccumulator
|
||||
>(
|
||||
kConvolutionalOperator,
|
||||
problem_size,
|
||||
tensor_A.device_ref(),
|
||||
tensor_B.device_ref(),
|
||||
tensor_C_reference.device_ref(),
|
||||
tensor_Y_reference.device_ref(),
|
||||
alpha,
|
||||
beta_ref);
|
||||
|
||||
// sync host (copy device data to host) for dumping error output in case of mismatches
|
||||
tensor_Y_reference.sync_host();
|
||||
|
||||
#else
|
||||
|
||||
cutlass::reference::host::Conv3d<
|
||||
ElementA,
|
||||
LayoutA,
|
||||
ElementB,
|
||||
LayoutB,
|
||||
ElementAccumulator,
|
||||
LayoutC,
|
||||
ElementAccumulator,
|
||||
ElementAccumulator
|
||||
>(
|
||||
kConvolutionalOperator,
|
||||
problem_size,
|
||||
tensor_A.host_ref(),
|
||||
tensor_B.host_ref(),
|
||||
tensor_C_reference.host_ref(),
|
||||
tensor_Y_reference.host_ref(),
|
||||
alpha,
|
||||
beta_ref);
|
||||
|
||||
#endif
|
||||
ReferenceOp reference_op;
|
||||
|
||||
// compute tensor Z and tensor T
|
||||
for (int n = 0; n < problem_size.N; ++n) {
|
||||
for (int o = 0; o < problem_size.Z; ++o) {
|
||||
for (int p = 0; p < problem_size.P; ++p) {
|
||||
for (int q = 0; q < problem_size.Q; ++q) {
|
||||
for (int k = 0; k < problem_size.K; ++k) {
|
||||
|
||||
ElementZ z{};
|
||||
ElementT t{};
|
||||
|
||||
ElementCompute accum = tensor_Y_reference.at({n, o, p, q, k});
|
||||
ElementCompute bias = ElementCompute(tensor_Broadcast.at({0, 0, 0, 0, k}));
|
||||
|
||||
|
||||
if (kAddBroadcastFirst) {
|
||||
reference_op(z, t, accum + bias,
|
||||
beta * ElementCompute(tensor_C_reference.at({n, o, p, q, k})));
|
||||
} else {
|
||||
reference_op(z, t, accum, bias);
|
||||
}
|
||||
|
||||
tensor_Z_reference.at({n, o, p, q, k}) = z;
|
||||
tensor_T_reference.at({n, o, p, q, k}) = t;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (kStoreT) {
|
||||
passed = cutlass::reference::host::TensorEquals(
|
||||
tensor_T_computed.host_view(),
|
||||
tensor_T_reference.host_view());
|
||||
|
||||
EXPECT_TRUE(passed);
|
||||
}
|
||||
|
||||
passed = cutlass::reference::host::TensorEquals(
|
||||
tensor_Z_computed.host_view(),
|
||||
tensor_Z_reference.host_view());
|
||||
|
||||
EXPECT_TRUE(passed);
|
||||
|
||||
if (!passed) {
|
||||
std::stringstream fname;
|
||||
|
||||
fname << "error_Conv3d_ImplicitGemm_device_"
|
||||
<< (split_k_mode == cutlass::conv::SplitKMode::kSerial ? "serial_reduction_" : "parallel_reduction_")
|
||||
<< (Conv3d::kConvolutionalOperator == cutlass::conv::Operator::kFprop ? "fprop_" :
|
||||
(Conv3d::kConvolutionalOperator == cutlass::conv::Operator::kDgrad ? "dgrad_" : "wgrad_"))
|
||||
<< "nnhwc_"
|
||||
<< problem_size.N << "x"
|
||||
<< problem_size.D << "x"
|
||||
<< problem_size.H << "x"
|
||||
<< problem_size.W << "x"
|
||||
<< problem_size.C
|
||||
<< "_krsc_"
|
||||
<< problem_size.K << "x"
|
||||
<< problem_size.T << "x"
|
||||
<< problem_size.R << "x"
|
||||
<< problem_size.S << "x"
|
||||
<< problem_size.C
|
||||
<< "_padding_"
|
||||
<< problem_size.pad_d << "x"
|
||||
<< problem_size.pad_h << "x"
|
||||
<< problem_size.pad_w
|
||||
<< "_stride_"
|
||||
<< problem_size.stride_d << "x"
|
||||
<< problem_size.stride_h << "x"
|
||||
<< problem_size.stride_w
|
||||
<< "_dilation_"
|
||||
<< problem_size.dilation_d << "x"
|
||||
<< problem_size.dilation_h << "x"
|
||||
<< problem_size.dilation_w << "_"
|
||||
<< (problem_size.mode == cutlass::conv::Mode::kCrossCorrelation ? "xcorr_" : "conv_")
|
||||
<< Conv3d::ThreadblockShape::kM << "x"
|
||||
<< Conv3d::ThreadblockShape::kN << "x"
|
||||
<< Conv3d::ThreadblockShape::kK << "_"
|
||||
<< Conv3d::WarpShape::kM << "x"
|
||||
<< Conv3d::WarpShape::kN << "x"
|
||||
<< Conv3d::WarpShape::kK << ".txt";
|
||||
|
||||
std::cout << fname.str() << std::endl;
|
||||
|
||||
std::ofstream results(fname.str());
|
||||
|
||||
results << problem_size << std::endl;
|
||||
|
||||
results
|
||||
<< "\nA:\n" << tensor_A.host_view() << "\n"
|
||||
<< "\nB:\n" << tensor_B.host_view() << "\n"
|
||||
<< "\nC:\n" << tensor_C.host_view() << "\n"
|
||||
<< "\nBroadcast:\n" << tensor_Broadcast.host_view() << "\n"
|
||||
<< "\nY reference:\n" << tensor_Y_reference.host_view() << "\n"
|
||||
<< "\nT reference:\n" << tensor_T_reference.host_view() << "\n"
|
||||
<< "\nT computed:\n" << tensor_T_computed.host_view() << "\n"
|
||||
<< "\nZ reference:\n" << tensor_Z_reference.host_view() << "\n"
|
||||
<< "\nZ computed:\n" << tensor_Z_computed.host_view() << "\n";
|
||||
}
|
||||
|
||||
return passed;
|
||||
}
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// TestAllConv: Runs cutlass::conv::device::ImplicitGemmConvolution operator and compares it with reference
|
||||
// TestAllConv runs conv operator on default conv problem sizes from test::conv::device::TestbedConv3dProblemSizes
|
||||
// Additionally, each conv3d test can provide conv problem sizes (conv_test_sizes) and blacklist of sizes
|
||||
// (conv_blacklist_sizes)
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
template <typename ImplicitGemm,
|
||||
typename ReferenceOp = Conv3dWithBroadcastReferenceOp<ImplicitGemm>,
|
||||
bool AddBroadcastFirst = false,
|
||||
bool TestSplitK = true
|
||||
>
|
||||
bool TestAllConv3dWithBroadcast(
|
||||
const Conv3dProblemVector &conv_test_sizes = Conv3dProblemVector(),
|
||||
const Conv3dProblemVector &conv_blacklist_sizes = Conv3dProblemVector()) {
|
||||
|
||||
bool passed = true;
|
||||
|
||||
//
|
||||
// Testbed object
|
||||
//
|
||||
|
||||
TestbedConv3dWithBroadcast<ImplicitGemm, ReferenceOp, AddBroadcastFirst> testbed;
|
||||
|
||||
//
|
||||
// Get conv problem sizes to run conv operator
|
||||
//
|
||||
TestbedConv3dProblemSizes conv3d_problems(128/cutlass::sizeof_bits<typename ImplicitGemm::ElementA>::value);
|
||||
|
||||
// Vector of conv3d problem sizes to avoid duplicate runs
|
||||
Conv3dProblemVector conv_tested_sizes;
|
||||
|
||||
Conv3dProblemVector const *problem_vectors[] = {
|
||||
&conv3d_problems.conv3d_default_sizes,
|
||||
&conv3d_problems.conv3d_vnet_medical_sizes,
|
||||
&conv_test_sizes
|
||||
};
|
||||
|
||||
// Sweep conv3d problem sizes (split-k-mode=kSerial, split-k-slice=1, alpha=1.0, beta=0.0)
|
||||
for (Conv3dProblemVector const * problem_vector : problem_vectors) {
|
||||
|
||||
// Run conv testbed on default convolution sizes
|
||||
for(auto conv_problem : *problem_vector) {
|
||||
|
||||
// Skip blacklist and avoid duplicate problem sizes
|
||||
if (std::find(conv_blacklist_sizes.begin(), conv_blacklist_sizes.end(), conv_problem) != conv_blacklist_sizes.end() ||
|
||||
std::find(conv_tested_sizes.begin(), conv_tested_sizes.end(), conv_problem) != conv_tested_sizes.end()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Procedurally disable certain cases
|
||||
//
|
||||
|
||||
// CUTLASS DGRAD's *unity* stride specialization only support stride {1, 1}
|
||||
if ((ImplicitGemm::kConvolutionalOperator ==
|
||||
cutlass::conv::Operator::kDgrad) &&
|
||||
(ImplicitGemm::UnderlyingKernel::Mma::IteratorA::kStrideSupport ==
|
||||
cutlass::conv::StrideSupport::kUnity)) {
|
||||
if (!((conv_problem.stride_d == 1) &&
|
||||
(conv_problem.stride_h == 1) &&
|
||||
(conv_problem.stride_w == 1))
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
#if 0 // relax restrictions on analytic strided dgrad
|
||||
// CUTLASS DGRAD's *strided* specialization only support stride >= {2, 2}
|
||||
if ((ImplicitGemm::kConvolutionalOperator ==
|
||||
cutlass::conv::Operator::kDgrad) &&
|
||||
(ImplicitGemm::UnderlyingKernel::Mma::IteratorA::kStrideSupport ==
|
||||
cutlass::conv::StrideSupport::kStrided)) {
|
||||
if (((conv_problem.stride_d == 1) && (conv_problem.stride_h == 1) && (conv_problem.stride_w == 1))) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
//
|
||||
// Test
|
||||
//
|
||||
// push back tested problem size to avoid re-running duplicates
|
||||
conv_tested_sizes.push_back(conv_problem);
|
||||
|
||||
// test mode = xcross
|
||||
passed = testbed.run(
|
||||
conv_problem,
|
||||
cutlass::conv::SplitKMode::kSerial);
|
||||
|
||||
if (!passed) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// test mode = convolution
|
||||
passed = testbed.run(
|
||||
conv_problem.reset_mode(cutlass::conv::Mode::kConvolution),
|
||||
cutlass::conv::SplitKMode::kSerial);
|
||||
|
||||
if (!passed) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!TestSplitK)
|
||||
return passed;
|
||||
|
||||
// Sweep split-k-slice using serial and prallel reduction with non-unity alpha and non-zero beta for
|
||||
// a single conv3d problem size. Convolution unit tests take a long time to run so only sweep parameters
|
||||
// which are abolutely necessary to catch functional bugs. The below code does provide option to sweep
|
||||
// alpha and beta for local testing, but only runs one value for alpha and beta.
|
||||
cutlass::conv::Conv3dProblemSize conv3d_split_k_test_size (
|
||||
{1, 8, 8, 8, 32}, // input size (NDHWC)
|
||||
{32, 3, 3, 3, 32}, // filter size (KTRSC)
|
||||
cutlass::Coord<3>({0, 0, 0}), // padding (pad_d, pad_h, pad_w)
|
||||
cutlass::Coord<3>({1, 1, 1}), // stride (stride_d, stride_h, stride_w)
|
||||
cutlass::Coord<3>({1, 1, 1}) // dilation (dilation_d, dilation_h, dilation_w)
|
||||
);
|
||||
|
||||
cutlass::conv::SplitKMode split_k_modes [] = {
|
||||
cutlass::conv::SplitKMode::kSerial
|
||||
};
|
||||
|
||||
int split_k_slices[] = {
|
||||
1, 2, 3, 4, 201
|
||||
};
|
||||
|
||||
double problem_alpha[] = {
|
||||
2.0
|
||||
};
|
||||
|
||||
double problem_beta[] = {
|
||||
2.0
|
||||
};
|
||||
|
||||
for (auto split_k_mode : split_k_modes) {
|
||||
for (auto split_k_slice : split_k_slices) {
|
||||
for (auto alpha : problem_alpha) {
|
||||
for (auto beta : problem_beta) {
|
||||
|
||||
passed = testbed.run(
|
||||
conv3d_split_k_test_size.reset_split_k_slices(split_k_slice),
|
||||
split_k_mode,
|
||||
cutlass::from_real<typename ImplicitGemm::ElementCompute>(alpha),
|
||||
cutlass::from_real<typename ImplicitGemm::ElementCompute>(beta));
|
||||
|
||||
if (!passed) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return passed;
|
||||
}
|
||||
|
||||
template <typename ImplicitGemm,
|
||||
typename ReferenceOp = Conv3dWithBroadcastReferenceOp<ImplicitGemm>,
|
||||
bool AddBroadcastFirst = false>
|
||||
bool TestSpecificConv3dWithBroadcast(
|
||||
const Conv3dProblemVector & problem_sizes) {
|
||||
|
||||
bool passed = true;
|
||||
|
||||
//
|
||||
// Testbed object
|
||||
//
|
||||
|
||||
TestbedConv3dWithBroadcast<ImplicitGemm, ReferenceOp, AddBroadcastFirst> testbed;
|
||||
|
||||
// Sweep conv3d problem sizes (split-k-mode=kSerial, split-k-slice=1, alpha=1.0, beta=0.0)
|
||||
for(auto conv_problem : problem_sizes) {
|
||||
|
||||
//
|
||||
// Test
|
||||
//
|
||||
|
||||
// test mode = xcross
|
||||
passed = testbed.run(
|
||||
conv_problem,
|
||||
cutlass::conv::SplitKMode::kSerial);
|
||||
|
||||
if (!passed) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// test mode = convolution
|
||||
passed = testbed.run(
|
||||
conv_problem.reset_mode(cutlass::conv::Mode::kConvolution),
|
||||
cutlass::conv::SplitKMode::kSerial);
|
||||
|
||||
if (!passed) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
} // namespace device
|
||||
} // namespace conv
|
||||
} // namespace test
|
||||
@@ -165,7 +165,7 @@ class TestbedDepthwiseDirectConv2d {
|
||||
throw std::runtime_error("cudaGetDeviceProperties() failed");
|
||||
}
|
||||
|
||||
if (properties.sharedMemPerBlockOptin < smem_size) {
|
||||
if (properties.sharedMemPerBlockOptin < static_cast<size_t>(smem_size)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user