Cutlass CUDA Templates for Linear Algebra Subroutines and Solvers

zip_fragment.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 <assert.h>
31
32 #include "cutlass/cutlass.h"
33 #include "cutlass/shape.h"
34 #include "cutlass/util/cutlass_math.h"
35 #include "cutlass/vector.h"
36
37 namespace cutlass {
38
40
45 template <typename First_, typename Second_>
46 struct ZipFragment {
48 typedef First_ First;
49
51 typedef Second_ Second;
52
54 typedef ZipFragment<First, Second> This_;
55
56 //
57 // Data members
58 //
59
61 First first;
62
64 Second second;
65
66 //
67 // Methods
68 //
69
71 CUTLASS_DEVICE
72 ZipFragment() { }
73
75 CUTLASS_DEVICE
76 ZipFragment(First const &_first, Second const &_second): first(_first), second(_second) { }
77
79 CUTLASS_DEVICE void clear() {
80 first.clear();
81 second.clear();
82 }
83 };
84
86
88 template <typename First, typename Second>
89 CUTLASS_HOST_DEVICE
90 ZipFragment<First, Second> make_ZipFragment(First const &first, Second const &second) {
91 return ZipFragment<First, Second>(first, second);
92 }
93
95
97 template <typename First_, typename Second_>
98 struct ZipConvert {
100 typedef First_ First;
101
103 typedef Second_ Second;
104
106 typedef ZipFragment<typename First::InputFragment, typename Second::InputFragment> InputFragment;
107
109 typedef ZipFragment<typename First::OutputFragment, typename Second::OutputFragment>
110 OutputFragment;
111
112 //
113 //
114 //
115
117 First first;
118
120 Second second;
121
122 //
123 //
124 //
125
127 CUTLASS_DEVICE ZipConvert() {}
128
130 CUTLASS_DEVICE ZipConvert(First const &_first, Second const &_second): first(_first), second(_second) { }
131
133 CUTLASS_DEVICE void transform(InputFragment const& src, OutputFragment& dst) {
134 first.transform(src.first, dst.first);
135 second.transform(src.second, dst.second);
136 }
137 };
138
140
142 template <typename First, typename Second>
143 CUTLASS_HOST_DEVICE
144 ZipConvert<First, Second> make_ZipConvert(First const &first, Second const &second) {
145 return ZipConvert<First, Second>(first, second);
146 }
147
149
150 } // namespace cutlass
cutlass::ZipConvert::second
Second second
Second transformer.
Definition: zip_fragment.h:120
cutlass
Definition: convert.h:33
cutlass::ZipFragment
A template defining Fragment Concept.
Definition: zip_fragment.h:46
cutlass::ZipFragment::Second
Second_ Second
Second fragment object.
Definition: zip_fragment.h:51
cutlass::ZipFragment::First
First_ First
First fragment object.
Definition: zip_fragment.h:48
cutlass::ZipConvert::transform
CUTLASS_DEVICE void transform(InputFragment const &src, OutputFragment &dst)
Transform a fragment.
Definition: zip_fragment.h:133
cutlass_math.h
Math utilities.
cutlass::ZipFragment::ZipFragment
CUTLASS_DEVICE ZipFragment()
Default ctor.
Definition: zip_fragment.h:72
cutlass::ZipConvert::first
First first
First transformer.
Definition: zip_fragment.h:117
cutlass::ZipConvert::ZipConvert
CUTLASS_DEVICE ZipConvert(First const &_first, Second const &_second)
Ctor.
Definition: zip_fragment.h:130
cutlass::ZipFragment::first
First first
First fragment object.
Definition: zip_fragment.h:61
cutlass::ZipFragment::clear
CUTLASS_DEVICE void clear()
Clear a fragment.
Definition: zip_fragment.h:79
cutlass::ZipConvert::First
First_ First
First convert operator.
Definition: zip_fragment.h:100
cutlass::ZipFragment::second
Second second
Second fragment object.
Definition: zip_fragment.h:64
CUTLASS_HOST_DEVICE
#define CUTLASS_HOST_DEVICE
Definition: cutlass.h:46
cutlass::ZipConvert::InputFragment
ZipFragment< typename First::InputFragment, typename Second::InputFragment > InputFragment
Defines the input zip fragment.
Definition: zip_fragment.h:106
cutlass::ZipConvert::Second
Second_ Second
Second convert operator.
Definition: zip_fragment.h:103
cutlass::ZipConvert::OutputFragment
ZipFragment< typename First::OutputFragment, typename Second::OutputFragment > OutputFragment
Defines the output zip fragment.
Definition: zip_fragment.h:110
vector.h
Defines a 1D vector of elements held in the registers of each thread.
cutlass::ZipConvert
Zips two convert operations.
Definition: zip_fragment.h:98
cutlass::ZipFragment::This_
ZipFragment< First, Second > This_
This class.
Definition: zip_fragment.h:54
shape.h
Defines Shape implementing the Layout concept for representing a 4D hypercube of objects.
cutlass::ZipFragment::ZipFragment
CUTLASS_DEVICE ZipFragment(First const &_first, Second const &_second)
Copy ctor.
Definition: zip_fragment.h:76
cutlass::make_ZipConvert
CUTLASS_HOST_DEVICE ZipConvert< First, Second > make_ZipConvert(First const &first, Second const &second)
Helper to construct a ZipConvert object.
Definition: zip_fragment.h:144
cutlass.h
Basic include for CUTLASS macros.
cutlass::ZipConvert::ZipConvert
CUTLASS_DEVICE ZipConvert()
Ctor.
Definition: zip_fragment.h:127
cutlass::make_ZipFragment
CUTLASS_HOST_DEVICE ZipFragment< First, Second > make_ZipFragment(First const &first, Second const &second)
Helper to construct a ZipFragment object.
Definition: zip_fragment.h:90