distribution.h
Go to the documentation of this file.
/***************************************************************************************************
* Copyright (c) 2017-2019, NVIDIA CORPORATION. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
* * Neither the name of the NVIDIA CORPORATION nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TOR (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
**************************************************************************************************/
#pragma once
#include <fstream>
namespace cutlass {
struct Distribution {
enum Kind { Invalid, Uniform, Gaussian, Identity, Sequential };
union {
struct {
double min;
double max;
} uniform;
struct {
double mean;
double stddev;
} gaussian;
struct {
double start;
double delta;
} sequential;
};
Kind kind;
int int_scale;
//
// Methods
//
Distribution() : kind(Invalid), int_scale(0) {}
Distribution &set_uniform(double _min, double _max, int _int_scale = 0) {
kind = Uniform;
uniform.min = _min;
uniform.max = _max;
int_scale = _int_scale;
return *this;
}
Distribution &set_gaussian(double _mean, double _stddev, int _int_scale = 0) {
kind = Gaussian;
gaussian.mean = _mean;
gaussian.stddev = _stddev;
int_scale = _int_scale;
return *this;
}
Distribution &set_identity() {
kind = Identity;
return *this;
}
Distribution &set_sequential(double start, double delta, int _int_scale = 0) {
kind = Sequential;
sequential.start = start;
sequential.delta = delta;
int_scale = _int_scale;
return *this;
}
};
} // namespace cutlass
inline std::ostream &operator<<(std::ostream &out, cutlass::Distribution const &dist) {
switch (dist.kind) {
case cutlass::Distribution::Uniform:
out << "uniform, min: " << dist.uniform.min << ", max: " << dist.uniform.max;
break;
case cutlass::Distribution::Gaussian:
out << "gaussian, mean: " << dist.gaussian.mean << ", stddev: " << dist.gaussian.stddev;
break;
case cutlass::Distribution::Identity:
out << "identity";
break;
case cutlass::Distribution::Sequential:
out << "sequential";
break;
default:
out << "unknown";
}
out << ", int_scale: " << dist.int_scale;
return out;
}
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