CUTLASS
CUDA Templates for Linear Algebra Subroutines and Solvers
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 {
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 
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 
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) {
117  out << "uniform, min: " << dist.uniform.min << ", max: " << dist.uniform.max;
118  break;
120  out << "gaussian, mean: " << dist.gaussian.mean << ", stddev: " << dist.gaussian.stddev;
121  break;
123  out << "identity";
124  break;
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 
Distribution()
Definition: distribution.h:73
Definition: aligned_buffer.h:35
Definition: distribution.h:40
Definition: distribution.h:40
struct cutlass::Distribution::@18::@20 uniform
Uniform distribution.
double mean
Definition: distribution.h:52
Kind kind
Active variant kind.
Definition: distribution.h:64
struct cutlass::Distribution::@18::@21 gaussian
Gaussian distribution.
Distribution & set_identity()
Sets identity.
Definition: distribution.h:94
Kind
Variant types.
Definition: distribution.h:40
double max
Definition: distribution.h:47
double stddev
Definition: distribution.h:53
Definition: distribution.h:40
double min
Definition: distribution.h:46
Distribution & set_uniform(double _min, double _max, int _int_scale=0)
Configures distribution as uniform random.
Definition: distribution.h:76
double start
Definition: distribution.h:58
double delta
Definition: distribution.h:59
Definition: distribution.h:40
std::ostream & operator<<(std::ostream &out, complex< T > const &z)
Definition: complex.h:291
Distribution type.
Definition: distribution.h:38
struct cutlass::Distribution::@18::@22 sequential
Elements are linear combination of row and column index.
int int_scale
Random values are cast to integer after scaling by this power of two.
Definition: distribution.h:67
Distribution & set_sequential(double start, double delta, int _int_scale=0)
Sets sequential.
Definition: distribution.h:100
Definition: distribution.h:40
Distribution & set_gaussian(double _mean, double _stddev, int _int_scale=0)
Configures distribution as Gaussian distribution.
Definition: distribution.h:85