* [WIP] GEMM StreamK w/ Fused Epilogue * Adds Gemm Streamk with Fused Epilogue kernel level struct. * Mostly based on Gemm with Fused Epilogue, * Requires a new epilogue * Work in progress * [WIP] StreamK support for GemmUniversalWithBroadcast * Just based off of how StreamK is allowed in GemmUniversal * Untested and a work in progress * Minor fixes * [WIP] It compiles! It is almost certainly incorrect, but we're past getting the templates to match, so checkpointing. * Correction to reference kernel * Fix typo * Added MSE measurement * Switch back to reference kernel + host for loop Still WIP. Now we're getting even a larger MSE, but it's both on basic Split-K and Stream-K. * Fix typos * Fix broadcast vector + requested changes * Comment typo * Small int option and more * Fix incorrect condition on source needed * Requested changes * I think I got it? * Bias vector should be stride 0 * Two source added! * Typos * Merge examples * Bring back vector row offset Just to ensure consistency with universal gemm with fused epilogue * Base arguments and params structs for StreamK * StreamK epilogue with broadcast now inherits the original * undo params_streamk_base.h --------- Co-authored-by: Ali Hassani <ahassanijr@gmail.com> Co-authored-by: Haicheng Wu <haichengw@nvidia.com>
246 lines
7.3 KiB
C++
246 lines
7.3 KiB
C++
/***************************************************************************************************
|
|
* Copyright (c) 2017 - 2023 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 Epilogue for threadblock scoped GEMMs using Tensor Ops.
|
|
|
|
The epilogue rearranges the result of a matrix product through shared memory to match canonical
|
|
tensor layouts in global memory. Epilogues support conversion and reduction operations.
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "cutlass/cutlass.h"
|
|
#include "cutlass/numeric_types.h"
|
|
#include "cutlass/array.h"
|
|
|
|
#include "cutlass/gemm/gemm.h"
|
|
|
|
#include "cutlass/epilogue/threadblock/default_epilogue_tensor_op.h"
|
|
#include "cutlass/epilogue/threadblock/default_epilogue_volta_tensor_op.h"
|
|
#include "cutlass/epilogue/threadblock/epilogue.h"
|
|
#include "cutlass/epilogue/threadblock/epilogue_with_broadcast.h"
|
|
#include "cutlass/epilogue/threadblock/epilogue_streamk_with_broadcast.h"
|
|
|
|
#include "cutlass/layout/permute.h"
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
namespace cutlass {
|
|
namespace epilogue {
|
|
namespace threadblock {
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
/// Defines sensible defaults for epilogues for TensorOps.
|
|
template <
|
|
typename Shape,
|
|
typename WarpMmaTensorOp,
|
|
int PartitionsK,
|
|
typename ElementOutput,
|
|
typename ElementTensor,
|
|
typename ElementVector,
|
|
typename OutputOp,
|
|
int ElementsPerAccess,
|
|
bool ScatterD = false,
|
|
typename PermuteDLayout = layout::NoPermute
|
|
>
|
|
struct DefaultEpilogueWithBroadcastTensorOp {
|
|
|
|
/// Use defaults related to the existing epilogue
|
|
using Base = DefaultEpilogueTensorOp<
|
|
Shape,
|
|
WarpMmaTensorOp,
|
|
PartitionsK,
|
|
OutputOp,
|
|
ElementsPerAccess
|
|
>;
|
|
|
|
//
|
|
// Stores the result z = (y = GEMM(A, B, C), broadcast)
|
|
//
|
|
using OutputTileIterator = cutlass::epilogue::threadblock::PredicatedTileIterator<
|
|
typename Base::OutputTileThreadMap,
|
|
ElementOutput,
|
|
ScatterD,
|
|
PermuteDLayout
|
|
>;
|
|
|
|
//
|
|
// Additional tensor tile iterator - stores t = Elementwise(z)
|
|
//
|
|
using TensorTileIterator = cutlass::epilogue::threadblock::PredicatedTileIterator<
|
|
typename Base::OutputTileThreadMap,
|
|
ElementTensor
|
|
>;
|
|
|
|
/// Define the epilogue
|
|
using Epilogue = EpilogueWithBroadcast<
|
|
Shape,
|
|
WarpMmaTensorOp,
|
|
PartitionsK,
|
|
OutputTileIterator,
|
|
TensorTileIterator,
|
|
ElementVector,
|
|
typename Base::AccumulatorFragmentIterator,
|
|
typename Base::WarpTileIterator,
|
|
typename Base::SharedLoadIterator,
|
|
OutputOp,
|
|
typename Base::Padding,
|
|
Base::kFragmentsPerIteration
|
|
>;
|
|
};
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
/// Defines sensible defaults for streamk epilogues for TensorOps.
|
|
template <
|
|
typename Shape,
|
|
typename WarpMmaTensorOp,
|
|
int PartitionsK,
|
|
typename ElementOutput,
|
|
typename ElementTensor,
|
|
typename ElementVector,
|
|
typename OutputOp,
|
|
int ElementsPerAccess,
|
|
bool ScatterD = false,
|
|
typename PermuteDLayout = layout::NoPermute
|
|
>
|
|
struct DefaultStreamkEpilogueWithBroadcastTensorOp {
|
|
|
|
/// Use defaults related to the existing epilogue
|
|
using Base = DefaultEpilogueTensorOp<
|
|
Shape,
|
|
WarpMmaTensorOp,
|
|
PartitionsK,
|
|
OutputOp,
|
|
ElementsPerAccess
|
|
>;
|
|
|
|
//
|
|
// Stores the result z = (y = GEMM(A, B, C), broadcast)
|
|
//
|
|
using OutputTileIterator = cutlass::epilogue::threadblock::PredicatedTileIterator<
|
|
typename Base::OutputTileThreadMap,
|
|
ElementOutput,
|
|
ScatterD,
|
|
PermuteDLayout
|
|
>;
|
|
|
|
//
|
|
// Additional tensor tile iterator - stores t = Elementwise(z)
|
|
//
|
|
using TensorTileIterator = cutlass::epilogue::threadblock::PredicatedTileIterator<
|
|
typename Base::OutputTileThreadMap,
|
|
ElementTensor
|
|
>;
|
|
|
|
/// Define the epilogue
|
|
using Epilogue = EpilogueStreamkWithBroadcast<
|
|
Shape,
|
|
WarpMmaTensorOp,
|
|
PartitionsK,
|
|
OutputTileIterator,
|
|
TensorTileIterator,
|
|
ElementVector,
|
|
typename Base::AccumulatorFragmentIterator,
|
|
typename Base::WarpTileIterator,
|
|
typename Base::SharedLoadIterator,
|
|
OutputOp,
|
|
typename Base::Padding,
|
|
Base::kFragmentsPerIteration
|
|
>;
|
|
};
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
/// Defines sensible defaults for epilogues for VoltaTensorOps.
|
|
template <
|
|
typename Shape,
|
|
typename WarpMmaTensorOp,
|
|
int PartitionsK,
|
|
typename ElementOutput,
|
|
typename ElementTensor,
|
|
typename ElementVector,
|
|
typename OutputOp,
|
|
int ElementsPerAccess
|
|
>
|
|
struct DefaultEpilogueWithBroadcastVoltaTensorOp {
|
|
|
|
/// Use defaults related to the existing epilogue
|
|
using Base = DefaultEpilogueVoltaTensorOp<
|
|
Shape,
|
|
WarpMmaTensorOp,
|
|
PartitionsK,
|
|
OutputOp,
|
|
ElementsPerAccess
|
|
>;
|
|
|
|
//
|
|
// Stores the result z = (y = GEMM(A, B, C), broadcast)
|
|
//
|
|
using OutputTileIterator = cutlass::epilogue::threadblock::PredicatedTileIterator<
|
|
typename Base::OutputTileThreadMap,
|
|
ElementOutput
|
|
>;
|
|
|
|
//
|
|
// Additional tensor tile iterator - stores t = Elementwise(z)
|
|
//
|
|
using TensorTileIterator = cutlass::epilogue::threadblock::PredicatedTileIterator<
|
|
typename Base::OutputTileThreadMap,
|
|
ElementTensor
|
|
>;
|
|
|
|
/// Define the epilogue
|
|
using Epilogue = EpilogueWithBroadcast<
|
|
Shape,
|
|
WarpMmaTensorOp,
|
|
PartitionsK,
|
|
OutputTileIterator,
|
|
TensorTileIterator,
|
|
ElementVector,
|
|
typename Base::AccumulatorFragmentIterator,
|
|
typename Base::WarpTileIterator,
|
|
typename Base::SharedLoadIterator,
|
|
OutputOp,
|
|
typename Base::Padding
|
|
>;
|
|
};
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
} // namespace threadblock
|
|
} // namespace epilogue
|
|
} // namespace cutlass
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|