Cutlass CUDA Templates for Linear Algebra Subroutines and Solvers

linear_scaling_device_ptr.h
Go to the documentation of this file.
1 /***************************************************************************************************
2 * Copyright (c) 2017-2018, NVIDIA CORPORATION. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are permitted
5 * provided that the following conditions are met:
6 * * Redistributions of source code must retain the above copyright notice, this list of
7 * conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above copyright notice, this list of
9 * conditions and the following disclaimer in the documentation and/or other materials
10 * provided with the distribution.
11 * * Neither the name of the NVIDIA CORPORATION nor the names of its contributors may be used
12 * to endorse or promote products derived from this software without specific prior written
13 * permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
21 * STRICT LIABILITY, OR TOR (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 **************************************************************************************************/
28 #pragma once
29
30 #include "cutlass/cutlass.h"
31 #include "cutlass/gemm/scalar_or_pointer.h"
32 #include "cutlass/gemm/linear_scaling.h"
33
34 namespace cutlass {
35
37
38 namespace gemm {
39
41
45 template <typename Scalar_, typename FragmentMultiplyAdd_ = FragmentMultiplyAdd<Scalar_, Scalar_> >
46 struct LinearScalingDevicePtr : public LinearScaling<Scalar_, FragmentMultiplyAdd_> {
47
49 typedef LinearScaling<Scalar_, FragmentMultiplyAdd_> Base;
50
51 // The scalar.
52 typedef typename Base::Scalar Scalar;
53
55 class Params {
56 private:
58 detail::ScalarOrPointer<Scalar> alpha_;
59
61 detail::ScalarOrPointer<Scalar> beta_;
62
63 public:
64 //
65 // Methods
66 //
67
68 // Constructor
69 CUTLASS_HOST_DEVICE
70 Params() {}
71
72 // Constructor
73 CUTLASS_HOST_DEVICE
74 Params(
75 Scalar alpha,
76 Scalar beta
77 ):
78 alpha_(alpha),
79 beta_(beta) {}
80
81 // Constructor
82 CUTLASS_HOST_DEVICE
83 Params(
84 Scalar const *alpha_ptr,
85 Scalar const *beta_ptr
86 ):
87 alpha_(alpha_ptr),
88 beta_(alpha_ptr) {}
89
91 CUTLASS_HOST_DEVICE int initialize(
92 Scalar alpha,
93 Scalar beta) {
94
95 alpha_ = alpha;
96 beta_ = beta;
97
98 return 0;
99 }
100
102 CUTLASS_HOST_DEVICE int initialize(
103 Scalar const *alpha,
104 Scalar const *beta) {
105
106 alpha_ = alpha;
107 beta_= beta;
108
109 return 0;
110 }
111
113 template <typename GemmDesc_>
114 CUTLASS_HOST_DEVICE int initialize(GemmDesc_ const& desc) {
115
116 alpha_ = desc.alpha;
117 beta_ = desc.beta;
118
119 return 0;
120 }
121
123 CUTLASS_HOST_DEVICE
124 Scalar alpha() const {
125 return alpha_;
126 }
127
129 CUTLASS_HOST_DEVICE
130 Scalar beta() const {
131 return beta_;
132 }
133 };
134
135 //
136 // Methods
137 //
138
140 CUTLASS_HOST_DEVICE LinearScalingDevicePtr(Params const& _params) {
141 this->params.alpha = _params.alpha();
142 this->params.beta = _params.beta();
143 }
144 };
145
147
148 } // namespace gemm
149 } // namespace cutlass
cutlass::gemm::LinearScalingDevicePtr::Params::initialize
CUTLASS_HOST_DEVICE int initialize(Scalar const *alpha, Scalar const *beta)
Initialize the parameters.
Definition: linear_scaling_device_ptr.h:102
cutlass::gemm::LinearScalingDevicePtr::Params
The parameters.
Definition: linear_scaling_device_ptr.h:55
cutlass
Definition: convert.h:33
cutlass::gemm::LinearScalingDevicePtr::Params::Params
CUTLASS_HOST_DEVICE Params(Scalar const *alpha_ptr, Scalar const *beta_ptr)
Definition: linear_scaling_device_ptr.h:83
linear_scaling.h
Implements the BLAS linear scaling function alpha*AB + beta*C.
scalar_or_pointer.h
Implements the BLAS linear scaling function alpha*AB + beta*C.
cutlass::gemm::LinearScalingDevicePtr::Params::initialize
CUTLASS_HOST_DEVICE int initialize(Scalar alpha, Scalar beta)
Initialize the parameters.
Definition: linear_scaling_device_ptr.h:91
cutlass::gemm::LinearScaling::params
Params params
Definition: linear_scaling.h:92
cutlass::gemm::LinearScalingDevicePtr::Base
LinearScaling< Scalar_, FragmentMultiplyAdd_ > Base
Linear Scaling class used.
Definition: linear_scaling_device_ptr.h:49
cutlass::gemm::LinearScalingDevicePtr::Params::Params
CUTLASS_HOST_DEVICE Params()
Definition: linear_scaling_device_ptr.h:70
CUTLASS_HOST_DEVICE
#define CUTLASS_HOST_DEVICE
Definition: cutlass.h:46
cutlass::gemm::LinearScalingDevicePtr::Params::Params
CUTLASS_HOST_DEVICE Params(Scalar alpha, Scalar beta)
Definition: linear_scaling_device_ptr.h:74
cutlass::gemm::LinearScalingDevicePtr::Params::beta
CUTLASS_HOST_DEVICE Scalar beta() const
Gets the beta scalar.
Definition: linear_scaling_device_ptr.h:130
cutlass::gemm::LinearScalingDevicePtr::LinearScalingDevicePtr
CUTLASS_HOST_DEVICE LinearScalingDevicePtr(Params const &_params)
Ctor.
Definition: linear_scaling_device_ptr.h:140
cutlass::gemm::LinearScalingDevicePtr::Params::alpha
CUTLASS_HOST_DEVICE Scalar alpha() const
Gets the alpha scalar.
Definition: linear_scaling_device_ptr.h:124
cutlass::gemm::LinearScalingDevicePtr
Definition: linear_scaling_device_ptr.h:46
cutlass::gemm::LinearScaling
Functor to compute linear combination of fragments.
Definition: linear_scaling.h:51
cutlass::gemm::LinearScaling::Scalar
Scalar_ Scalar
Definition: linear_scaling.h:53
cutlass::gemm::LinearScalingDevicePtr::Scalar
Base::Scalar Scalar
Definition: linear_scaling_device_ptr.h:52
cutlass.h
Basic include for CUTLASS macros.
cutlass::gemm::LinearScalingDevicePtr::Params::initialize
CUTLASS_HOST_DEVICE int initialize(GemmDesc_ const &desc)
Initialize the parameters.
Definition: linear_scaling_device_ptr.h:114
cutlass::detail::ScalarOrPointer< Scalar >