Cutlass
CUDA Templates for Linear Algebra Subroutines and Solvers
linear_scaling.h
Go to the documentation of this file.
1 
2 /***************************************************************************************************
3  * Copyright (c) 2017-2018, NVIDIA CORPORATION. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification, are permitted
6  * provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright notice, this list of
8  * conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright notice, this list of
10  * conditions and the following disclaimer in the documentation and/or other materials
11  * provided with the distribution.
12  * * Neither the name of the NVIDIA CORPORATION nor the names of its contributors may be used
13  * to endorse or promote products derived from this software without specific prior written
14  * permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
18  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
20  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
22  * STRICT LIABILITY, OR TOR (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  *
25  **************************************************************************************************/
29 #pragma once
30 
32 
33 namespace cutlass {
34 namespace gemm {
35 
37 
39 template <typename Scalar_, typename FragmentMultiplyAdd_ = FragmentMultiplyAdd<Scalar_> >
40 struct LinearScaling {
41  // The scalar.
42  typedef Scalar_ Scalar;
43  // The adapater.
44  typedef FragmentMultiplyAdd_ FragmentMultiplyAdd;
45 
47  struct Params {
50 
52  template <typename GemmDesc_>
53  CUTLASS_HOST_DEVICE int initialize(GemmDesc_ const& desc) {
54  alpha = desc.alpha;
55  beta = desc.beta;
56  return 0;
57  }
58  };
59 
61  CUTLASS_DEVICE LinearScaling(Params const& params) : alpha(params.alpha), beta(params.beta) {}
62 
64  template <typename Fragment_>
65  CUTLASS_DEVICE void evaluate(Fragment_ const& accum, Fragment_& output) {
67  mad.multiply(alpha, accum, output);
68  }
69 
71  template <typename Fragment_>
72  CUTLASS_DEVICE void evaluate(Fragment_ const& accum, Fragment_ const& old, Fragment_& output) {
74  Fragment_ tmp;
75  mad.multiply(beta, old, tmp);
76  mad.multiply_add(alpha, accum, tmp, output);
77  }
78 
81 };
82 
84 
85 } // namespace gemm
86 } // namespace cutlass
Definition: convert.h:33
Scalar alpha
The alpha/beta scaling params.
Definition: linear_scaling.h:49
Scalar alpha
The alpha/beta scaling factors.
Definition: linear_scaling.h:80
CUTLASS_DEVICE LinearScaling(Params const &params)
Ctor.
Definition: linear_scaling.h:61
CUTLASS_DEVICE void evaluate(Fragment_ const &accum, Fragment_ const &old, Fragment_ &output)
Evaluate the functor.
Definition: linear_scaling.h:72
Scalar beta
Definition: linear_scaling.h:49
CUTLASS_HOST_DEVICE int initialize(GemmDesc_ const &desc)
Initialize the parameters.
Definition: linear_scaling.h:53
Scalar beta
Definition: linear_scaling.h:80
Defines multiply-add operations on fragments within a thread.
FragmentMultiplyAdd_ FragmentMultiplyAdd
Definition: linear_scaling.h:44
#define CUTLASS_HOST_DEVICE
Definition: cutlass.h:46
CUTLASS_DEVICE void evaluate(Fragment_ const &accum, Fragment_ &output)
Evaluate the functor.
Definition: linear_scaling.h:65
The parameters.
Definition: linear_scaling.h:47
Functor to compute linear combination of fragments.
Definition: linear_scaling.h:40
Scalar_ Scalar
Definition: linear_scaling.h:42