Cutlass CUDA Templates for Linear Algebra Subroutines and Solvers

core_io.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 **************************************************************************************************/
29 #pragma once
30
31 #include <iosfwd>
32 #include <typeinfo>
33
34 #include "cutlass/coord.h"
35 #include "cutlass/vector.h"
36
37 namespace cutlass {
38
40
41 template <int Rank>
42 std::ostream& operator<<(std::ostream& out, Coord<Rank> const& coord) {
43 for (int i = 0; i < Rank; ++i) {
44 out << (i ? ", " : "") << coord.idx[i];
45 }
46 return out;
47 }
48
50
52 template <typename T>
53 struct ScalarIO {
54
56 T value;
57
59 ScalarIO() { }
60
62 ScalarIO(T value): value(value) {}
63 };
64
66
68 template <typename T>
69 inline std::ostream &operator<<(std::ostream &out, ScalarIO<T> const &scalar) {
70 return out << scalar.value;
71 }
72
74 template <>
75 inline std::ostream &operator<<(std::ostream &out, ScalarIO<int8_t> const &scalar) {
76 return out << int(scalar.value);
77 }
78
80 template <>
81 inline std::ostream &operator<<(std::ostream &out, ScalarIO<uint8_t> const &scalar) {
82 return out << unsigned(scalar.value);
83 }
84
86 template <>
87 inline std::ostream &operator<<(
88 std::ostream &out,
89 ScalarIO<cutlass::Vector<cutlass::bin1_t, 32> > const &scalar) {
90
91 for (int i = 0; i < 32; i++) {
92 out << int(scalar.value[i]);
93 out << ((i != 31) ? ", " : "");
94 }
95 return out;
96 }
97
99 template <>
100 inline std::ostream &operator<<(
101 std::ostream &out,
102 ScalarIO<cutlass::Vector<cutlass::int4_t, 8> > const &scalar) {
103
104 for (int i = 0; i < 8; i++) {
105 out << int(scalar.value[i]);
106 out << ((i != 7) ? ", " : "");
107 }
108 return out;
109 }
110
112 template <>
113 inline std::ostream &operator<<(
114 std::ostream &out,
115 ScalarIO<cutlass::Vector<cutlass::uint4_t, 8> > const &scalar) {
116
117 for (int i = 0; i < 8; i++) {
118 out << unsigned(scalar.value[i]);
119 out << ((i != 7) ? ", " : "");
120 }
121 return out;
122 }
123
125
126 } // namespace cutlass
cutlass
Definition: convert.h:33
coord.h
A Coord is a coordinate of arbitrary rank into a tensor or matrix.
cutlass::ScalarIO::ScalarIO
ScalarIO(T value)
Constructs from a value.
Definition: core_io.h:62
cutlass::ScalarIO::ScalarIO
ScalarIO()
Default ctor.
Definition: core_io.h:59
cutlass::operator<<
std::ostream & operator<<(std::ostream &out, Coord< Rank > const &coord)
Definition: core_io.h:42
cutlass::ScalarIO
Helper to enable formatted printing of CUTLASS scalar types to an ostream.
Definition: core_io.h:53
cutlass::Vector
Definition: vector.h:62
cutlass::ScalarIO::value
T value
Value to print.
Definition: core_io.h:56
vector.h
Defines a 1D vector of elements held in the registers of each thread.