| CUTLASS CUDA Templates for Linear Algebra Subroutines and Solvers

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

distribution.h
Go to the documentation of this file.
1 /***************************************************************************************************
2 * Copyright (c) 2017-2019, 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 **************************************************************************************************/
25 #pragma once
26
31 #include <fstream>
32
33 namespace cutlass {
34
36
38 struct Distribution {
40 enum Kind { Invalid, Uniform, Gaussian, Identity, Sequential };
41
43 union {
45 struct {
46 double min;
47 double max;
48 } uniform;
49
51 struct {
52 double mean;
53 double stddev;
54 } gaussian;
55
57 struct {
58 double start;
59 double delta;
60 } sequential;
61 };
62
64 Kind kind;
65
67 int int_scale;
68
69 //
70 // Methods
71 //
72
73 Distribution() : kind(Invalid), int_scale(0) {}
74
76 Distribution &set_uniform(double _min, double _max, int _int_scale = 0) {
77 kind = Uniform;
78 uniform.min = _min;
79 uniform.max = _max;
80 int_scale = _int_scale;
81 return *this;
82 }
83
85 Distribution &set_gaussian(double _mean, double _stddev, int _int_scale = 0) {
86 kind = Gaussian;
87 gaussian.mean = _mean;
88 gaussian.stddev = _stddev;
89 int_scale = _int_scale;
90 return *this;
91 }
92
94 Distribution &set_identity() {
95 kind = Identity;
96 return *this;
97 }
98
100 Distribution &set_sequential(double start, double delta, int _int_scale = 0) {
101 kind = Sequential;
102 sequential.start = start;
103 sequential.delta = delta;
104 int_scale = _int_scale;
105 return *this;
106 }
107 };
108
109 } // namespace cutlass
110
112
114 inline std::ostream &operator<<(std::ostream &out, cutlass::Distribution const &dist) {
115 switch (dist.kind) {
116 case cutlass::Distribution::Uniform:
117 out << "uniform, min: " << dist.uniform.min << ", max: " << dist.uniform.max;
118 break;
119 case cutlass::Distribution::Gaussian:
120 out << "gaussian, mean: " << dist.gaussian.mean << ", stddev: " << dist.gaussian.stddev;
121 break;
122 case cutlass::Distribution::Identity:
123 out << "identity";
124 break;
125 case cutlass::Distribution::Sequential:
126 out << "sequential";
127 break;
128 default:
129 out << "unknown";
130 }
131
132 out << ", int_scale: " << dist.int_scale;
133
134 return out;
135 }
136
cutlass::Distribution::Distribution
Distribution()
Definition: distribution.h:73
cutlass
Definition: aligned_buffer.h:35
cutlass::Distribution::Uniform
Definition: distribution.h:40
cutlass::Distribution::Gaussian
Definition: distribution.h:40
cutlass::Distribution::uniform
struct cutlass::Distribution::@18::@20 uniform
Uniform distribution.
cutlass::Distribution::mean
double mean
Definition: distribution.h:52
cutlass::Distribution::kind
Kind kind
Active variant kind.
Definition: distribution.h:64
cutlass::Distribution::gaussian
struct cutlass::Distribution::@18::@21 gaussian
Gaussian distribution.
cutlass::Distribution::set_identity
Distribution & set_identity()
Sets identity.
Definition: distribution.h:94
cutlass::Distribution::Kind
Kind
Variant types.
Definition: distribution.h:40
cutlass::Distribution::max
double max
Definition: distribution.h:47
cutlass::Distribution::stddev
double stddev
Definition: distribution.h:53
cutlass::Distribution::Identity
Definition: distribution.h:40
cutlass::Distribution::min
double min
Definition: distribution.h:46
cutlass::Distribution::set_uniform
Distribution & set_uniform(double _min, double _max, int _int_scale=0)
Configures distribution as uniform random.
Definition: distribution.h:76
cutlass::Distribution::start
double start
Definition: distribution.h:58
cutlass::Distribution::delta
double delta
Definition: distribution.h:59
cutlass::Distribution::Sequential
Definition: distribution.h:40
cutlass::operator<<
std::ostream & operator<<(std::ostream &out, complex< T > const &z)
Definition: complex.h:291
cutlass::Distribution
Distribution type.
Definition: distribution.h:38
cutlass::Distribution::sequential
struct cutlass::Distribution::@18::@22 sequential
Elements are linear combination of row and column index.
cutlass::Distribution::int_scale
int int_scale
Random values are cast to integer after scaling by this power of two.
Definition: distribution.h:67
cutlass::Distribution::set_sequential
Distribution & set_sequential(double start, double delta, int _int_scale=0)
Sets sequential.
Definition: distribution.h:100
cutlass::Distribution::Invalid
Definition: distribution.h:40
cutlass::Distribution::set_gaussian
Distribution & set_gaussian(double _mean, double _stddev, int _int_scale=0)
Configures distribution as Gaussian distribution.
Definition: distribution.h:85