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"
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 
55 
56  //
57  // Data members
58  //
59 
62 
65 
66  //
67  // Methods
68  //
69 
71  CUTLASS_DEVICE
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>
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 
107 
111 
112  //
113  //
114  //
115 
118 
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>
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
Second second
Second transformer.
Definition: zip_fragment.h:120
Definition: convert.h:33
A template defining Fragment Concept.
Definition: zip_fragment.h:46
Second_ Second
Second fragment object.
Definition: zip_fragment.h:51
First_ First
First fragment object.
Definition: zip_fragment.h:48
CUTLASS_DEVICE void transform(InputFragment const &src, OutputFragment &dst)
Transform a fragment.
Definition: zip_fragment.h:133
Math utilities.
CUTLASS_DEVICE ZipFragment()
Default ctor.
Definition: zip_fragment.h:72
First first
First transformer.
Definition: zip_fragment.h:117
CUTLASS_DEVICE ZipConvert(First const &_first, Second const &_second)
Ctor.
Definition: zip_fragment.h:130
First first
First fragment object.
Definition: zip_fragment.h:61
CUTLASS_DEVICE void clear()
Clear a fragment.
Definition: zip_fragment.h:79
First_ First
First convert operator.
Definition: zip_fragment.h:100
Second second
Second fragment object.
Definition: zip_fragment.h:64
#define CUTLASS_HOST_DEVICE
Definition: cutlass.h:46
ZipFragment< typename First::InputFragment, typename Second::InputFragment > InputFragment
Defines the input zip fragment.
Definition: zip_fragment.h:106
Second_ Second
Second convert operator.
Definition: zip_fragment.h:103
ZipFragment< typename First::OutputFragment, typename Second::OutputFragment > OutputFragment
Defines the output zip fragment.
Definition: zip_fragment.h:110
Defines a 1D vector of elements held in the registers of each thread.
Zips two convert operations.
Definition: zip_fragment.h:98
ZipFragment< First, Second > This_
This class.
Definition: zip_fragment.h:54
Defines Shape implementing the Layout concept for representing a 4D hypercube of objects.
CUTLASS_DEVICE ZipFragment(First const &_first, Second const &_second)
Copy ctor.
Definition: zip_fragment.h:76
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
Basic include for CUTLASS macros.
CUTLASS_DEVICE ZipConvert()
Ctor.
Definition: zip_fragment.h:127
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