linear_scaling.h
Go to the documentation of this file.
/***************************************************************************************************
* Copyright (c) 2017-2018, NVIDIA CORPORATION. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
* * 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.
* * Neither the name of the NVIDIA CORPORATION 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 NVIDIA CORPORATION 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 TOR (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
**************************************************************************************************/
#pragma once
#include <cutlass/fragment_multiply_add.h>
namespace cutlass {
namespace gemm {
template <typename Scalar_, typename FragmentMultiplyAdd_ = FragmentMultiplyAdd<Scalar_> >
struct LinearScaling {
// The scalar.
typedef Scalar_ Scalar;
// The adapater.
typedef FragmentMultiplyAdd_ FragmentMultiplyAdd;
struct Params {
Scalar alpha, beta;
template <typename GemmDesc_>
CUTLASS_HOST_DEVICE int initialize(GemmDesc_ const& desc) {
alpha = desc.alpha;
beta = desc.beta;
return 0;
}
};
CUTLASS_DEVICE LinearScaling(Params const& params) : alpha(params.alpha), beta(params.beta) {}
template <typename Fragment_>
CUTLASS_DEVICE void evaluate(Fragment_ const& accum, Fragment_& output) {
FragmentMultiplyAdd mad;
mad.multiply(alpha, accum, output);
}
template <typename Fragment_>
CUTLASS_DEVICE void evaluate(Fragment_ const& accum, Fragment_ const& old, Fragment_& output) {
FragmentMultiplyAdd mad;
Fragment_ tmp;
mad.multiply(beta, old, tmp);
mad.multiply_add(alpha, accum, tmp, output);
}
Scalar alpha, beta;
};
} // namespace gemm
} // namespace cutlass
cutlass
Definition: convert.h:33
cutlass::gemm::LinearScaling::Params::alpha
Scalar alpha
The alpha/beta scaling params.
Definition: linear_scaling.h:49
cutlass::gemm::LinearScaling::alpha
Scalar alpha
The alpha/beta scaling factors.
Definition: linear_scaling.h:80
cutlass::gemm::LinearScaling::LinearScaling
CUTLASS_DEVICE LinearScaling(Params const &params)
Ctor.
Definition: linear_scaling.h:61
cutlass::gemm::LinearScaling::evaluate
CUTLASS_DEVICE void evaluate(Fragment_ const &accum, Fragment_ const &old, Fragment_ &output)
Evaluate the functor.
Definition: linear_scaling.h:72
cutlass::gemm::LinearScaling::Params::beta
Scalar beta
Definition: linear_scaling.h:49
cutlass::gemm::LinearScaling::Params::initialize
CUTLASS_HOST_DEVICE int initialize(GemmDesc_ const &desc)
Initialize the parameters.
Definition: linear_scaling.h:53
cutlass::gemm::LinearScaling::beta
Scalar beta
Definition: linear_scaling.h:80
fragment_multiply_add.h
Defines multiply-add operations on fragments within a thread.
cutlass::gemm::LinearScaling::FragmentMultiplyAdd
FragmentMultiplyAdd_ FragmentMultiplyAdd
Definition: linear_scaling.h:44
CUTLASS_HOST_DEVICE
#define CUTLASS_HOST_DEVICE
Definition: cutlass.h:46
cutlass::gemm::LinearScaling::evaluate
CUTLASS_DEVICE void evaluate(Fragment_ const &accum, Fragment_ &output)
Evaluate the functor.
Definition: linear_scaling.h:65
cutlass::gemm::LinearScaling::Params
The parameters.
Definition: linear_scaling.h:47
cutlass::gemm::LinearScaling
Functor to compute linear combination of fragments.
Definition: linear_scaling.h:40
cutlass::gemm::LinearScaling::Scalar
Scalar_ Scalar
Definition: linear_scaling.h:42