host/tensor_fill.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.
*
**************************************************************************************************/
/* \file
\brief Provides several functions for filling tensors with data.
*/
#pragma once
// Standard Library includes
#include <utility>
#include <cstdlib>
#include <cmath>
// Cutlass includes
#include "cutlass/cutlass.h"
#include "cutlass/complex.h"
#include "cutlass/array.h"
#include "cutlass/numeric_types.h"
#include "cutlass/util/distribution.h"
#include "tensor_foreach.h"
namespace cutlass {
namespace reference {
namespace host {
namespace detail {
template <
typename Element,
typename Layout>
struct TensorFillFunc {
using TensorView = TensorView<Element, Layout>;
//
// Data members
//
TensorView view;
Element value;
//
// Methods
//
TensorFillFunc(
TensorView const &view_ = TensorView(),
Element value_ = Element(0)
): view(view_), value(value_) { }
void operator()(Coord<Layout::kRank> const & coord) const {
view.at(coord) = value;
}
};
} // namespace detail
template <
typename Element,
typename Layout>
void TensorFill(
TensorView<Element, Layout> dst,
Element val = Element(0)) {
detail::TensorFillFunc<Element, Layout> func(dst, val);
TensorForEach(
dst.extent(),
func
);
}
namespace detail {
template <typename Element>
struct RandomGaussianFunc {
uint64_t seed;
double mean;
double stddev;
int int_scale;
double pi;
//
// Methods
//
RandomGaussianFunc(
uint64_t seed_ = 0,
double mean_ = 0,
double stddev_ = 1,
int int_scale_ = -1
):
seed(seed_), mean(mean_), stddev(stddev_), int_scale(int_scale_), pi(std::acos(-1)) {
std::srand((unsigned)seed);
}
Element operator()() const {
// Box-Muller transform to generate random numbers with Normal distribution
double u1 = double(std::rand()) / double(RAND_MAX);
double u2 = double(std::rand()) / double(RAND_MAX);
// Compute Gaussian random value
double rnd = std::sqrt(-2 * std::log(u1)) * std::cos(2 * pi * u2);
rnd = mean + stddev * rnd;
// Scale and convert final result
Element result;
if (int_scale >= 0) {
rnd = double(int64_t(rnd * double(1 << int_scale))) / double(1 << int_scale);
result = static_cast<Element>(rnd);
}
else {
result = static_cast<Element>(rnd);
}
return result;
}
};
template <typename Element>
struct RandomGaussianFunc<complex<Element> > {
uint64_t seed;
double mean;
double stddev;
int int_scale;
double pi;
//
// Methods
//
RandomGaussianFunc(
uint64_t seed_ = 0,
double mean_ = 0,
double stddev_ = 1,
int int_scale_ = -1
):
seed(seed_), mean(mean_), stddev(stddev_), int_scale(int_scale_), pi(std::acos(-1)) {
std::srand((unsigned)seed);
}
complex<Element> operator()() const {
Element reals[2];
for (int i = 0; i < 2; ++i) {
// Box-Muller transform to generate random numbers with Normal distribution
double u1 = double(std::rand()) / double(RAND_MAX);
double u2 = double(std::rand()) / double(RAND_MAX);
// Compute Gaussian random value
double rnd = std::sqrt(-2 * std::log(u1)) * std::cos(2 * pi * u2);
rnd = mean + stddev * rnd;
if (int_scale >= 0) {
rnd = double(int(rnd * double(1 << int_scale)));
reals[i] = from_real<Element>(rnd / double(1 << int_scale));
}
else {
reals[i] = from_real<Element>(rnd);
}
}
return complex<Element>(reals[0], reals[1]);
}
};
template <
typename Element,
typename Layout>
struct TensorFillGaussianFunc {
using TensorView = TensorView<Element, Layout>;
//
// Data members
//
TensorView view;
RandomGaussianFunc<Element> func;
//
// Methods
//
TensorFillGaussianFunc(
TensorView view_ = TensorView(),
RandomGaussianFunc<Element> func_ = RandomGaussianFunc<Element>()
):
view(view_), func(func_) {
}
void operator()(Coord<Layout::kRank> const &coord) const {
view.at(coord) = func();
}
};
} // namespace detail
template <
typename Element,
typename Layout>
void TensorFillRandomGaussian(
TensorView<Element, Layout> dst,
uint64_t seed,
double mean = 0,
double stddev = 1,
int bits = -1) {
detail::RandomGaussianFunc<Element> random_func(seed, mean, stddev, bits);
detail::TensorFillGaussianFunc<Element, Layout> func(
dst,
random_func
);
TensorForEach(
dst.extent(),
func
);
}
template <
typename Element
>
void BlockFillRandomGaussian(
Element *ptr,
size_t capacity,
uint64_t seed,
double mean = 0,
double stddev = 1,
int bits = -1) {
detail::RandomGaussianFunc<Element> random_func(seed, mean, stddev, bits);
for (size_t i = 0; i < capacity; ++i) {
ptr[i] = random_func();
}
}
namespace detail {
template <typename Element>
struct RandomUniformFunc {
using Real = typename RealType<Element>::Type;
uint64_t seed;
double range;
double min;
int int_scale;
//
// Methods
//
RandomUniformFunc(
uint64_t seed_ = 0,
double max = 1,
double min_ = 0,
int int_scale_ = -1
):
seed(seed_), range(max - min_), min(min_), int_scale(int_scale_) {
std::srand((unsigned)seed);
}
Element operator()() const {
double rnd = double(std::rand()) / double(RAND_MAX);
rnd = min + range * rnd;
// Random values are cast to integer after scaling by a power of two to facilitate error
// testing
Element result;
if (int_scale >= 0) {
rnd = double(int64_t(rnd * double(1 << int_scale))) / double(1 << int_scale);
result = static_cast<Element>(Real(rnd));
}
else {
result = static_cast<Element>(Real(rnd));
}
return result;
}
};
template <typename Element>
struct RandomUniformFunc<complex<Element> > {
using Real = typename RealType<Element>::Type;
uint64_t seed;
double range;
double min;
int int_scale;
//
// Methods
//
RandomUniformFunc(
uint64_t seed_ = 0,
double max = 1,
double min_ = 0,
int int_scale_ = -1
):
seed(seed_), range(max - min_), min(min_), int_scale(int_scale_) {
std::srand((unsigned)seed);
}
complex<Element> operator()() const {
Element reals[2];
for (int i = 0; i < 2; ++i) {
double rnd = double(std::rand()) / double(RAND_MAX);
rnd = min + range * rnd;
// Random values are cast to integer after scaling by a power of two to facilitate error
// testing
if (int_scale >= 0) {
rnd = double(int(rnd * double(1 << int_scale)));
reals[i] = from_real<Element>(Real(rnd / double(1 << int_scale)));
}
else {
reals[i] = from_real<Element>(Real(rnd));
}
}
return complex<Element>(reals[0], reals[1]);
}
};
template <
typename Element,
typename Layout>
struct TensorFillRandomUniformFunc {
using TensorView = TensorView<Element, Layout>;
//
// Data members
//
TensorView view;
RandomUniformFunc<Element> func;
//
// Methods
//
TensorFillRandomUniformFunc(
TensorView view_ = TensorView(),
RandomUniformFunc<Element> func_ = RandomUniformFunc<Element>()
):
view(view_), func(func_) {
}
void operator()(Coord<Layout::kRank> const &coord) const {
view.at(coord) = func();
}
};
} // namespace detail
template <
typename Element,
typename Layout>
void TensorFillRandomUniform(
TensorView<Element, Layout> dst,
uint64_t seed,
double max = 1,
double min = 0,
int bits = -1) {
detail::RandomUniformFunc<Element> random_func(seed, max, min, bits);
detail::TensorFillRandomUniformFunc<Element, Layout> func(
dst,
random_func
);
TensorForEach(
dst.extent(),
func
);
}
template <
typename Element
>
void BlockFillRandomUniform(
Element *ptr,
size_t capacity,
uint64_t seed,
double max = 1,
double min = 0,
int bits = -1) {
detail::RandomUniformFunc<Element> random_func(seed, max, min, bits);
for (size_t i = 0; i < capacity; ++i) {
ptr[i] = random_func();
}
}
namespace detail {
template <
typename Element,
typename Layout>
struct TensorFillDiagonalFunc {
using TensorView = TensorView<Element, Layout>;
//
// Data members
//
TensorView view;
Element diag;
Element other;
//
// Methods
//
TensorFillDiagonalFunc(
TensorView const &view_ = TensorView(),
Element diag_ = Element(1),
Element other_ = Element(0)
):
view(view_), diag(diag_), other(other_) { }
void operator()(Coord<Layout::kRank> const & coord) const {
bool is_diag = true;
CUTLASS_PRAGMA_UNROLL
for (int i = 1; i < Layout::kRank; ++i) {
if (coord[i] != coord[i - 1]) {
is_diag = false;
break;
}
}
view.at(coord) = (is_diag ? diag : other);
}
};
} // namespace detail
template <
typename Element,
typename Layout>
void TensorFillDiagonal(
TensorView<Element, Layout> dst,
Element diag = Element(1),
Element other = Element(0)) {
detail::TensorFillDiagonalFunc<Element, Layout> func(
dst,
diag,
other
);
TensorForEach(
dst.extent(),
func
);
}
template <
typename Element,
typename Layout>
void TensorFillIdentity(
TensorView<Element, Layout> dst) {
TensorFillDiagonal(dst, Element(1), Element(0));
}
template <
typename Element,
typename Layout>
void TensorUpdateDiagonal(
TensorView<Element, Layout> dst,
Element val = Element(1)) {
typename Layout::Index extent = dst.extent().min();
for (typename Layout::Index i = 0; i < extent; ++i) {
Coord<Layout::kRank> coord(i);
dst.at(coord) = val;
}
}
namespace detail {
template <
typename Element,
typename Layout>
struct TensorUpdateOffDiagonalFunc {
using TensorView = TensorView<Element, Layout>;
//
// Data members
//
TensorView view;
Element other;
//
// Methods
//
TensorUpdateOffDiagonalFunc(
TensorView const &view_ = TensorView(),
Element other_ = Element(0)
):
view(view_), other(other_) { }
void operator()(Coord<Layout::kRank> const & coord) const {
bool is_diag = true;
CUTLASS_PRAGMA_UNROLL
for (int i = 1; i < Layout::kRank; ++i) {
if (coord[i] != coord[i - 1]) {
is_diag = false;
break;
}
}
if (!is_diag) {
view.at(coord) = other;
}
}
};
} // namespace detail
template <
typename Element,
typename Layout>
void TensorUpdateOffDiagonal(
TensorView<Element, Layout> dst,
Element other = Element(1)) {
detail::TensorUpdateOffDiagonalFunc<Element, Layout> func(
dst,
other
);
TensorForEach(
dst.extent(),
func
);
}
namespace detail {
template <
typename Element,
typename Layout>
struct TensorFillLinearFunc {
using TensorView = TensorView<Element, Layout>;
//
// Data members
//
TensorView view;
Array<Element, Layout::kRank> v;
Element s;
//
// Methods
//
TensorFillLinearFunc() { }
TensorFillLinearFunc(
TensorView const &view_,
Array<Element, Layout::kRank> const & v_,
Element s_ = Element(0)
):
view(view_), v(v_), s(s_) { }
void operator()(Coord<Layout::kRank> const & coord) const {
Element sum(s);
CUTLASS_PRAGMA_UNROLL
for (int i = 0; i < Layout::kRank; ++i) {
sum += Element(coord[i]) * v[i];
}
view.at(coord) = sum;
}
};
} // namespace detail
template <
typename Element,
typename Layout>
void TensorFillLinear(
TensorView<Element, Layout> dst,
Array<Element, Layout::kRank> const & v,
Element s = Element(0)) {
detail::TensorFillLinearFunc<Element, Layout> func(
dst,
v,
s
);
TensorForEach(
dst.extent(),
func
);
}
template <
typename Element,
typename Layout>
void TensorFillSequential(
TensorView<Element, Layout> dst,
Element s = Element(0)) {
Array<Element, Layout::kRank> stride;
stride[0] = Element(1);
CUTLASS_PRAGMA_UNROLL
for (int i = 1; i < Layout::kRank; ++i) {
stride[i] = stride[i - 1] * Element(dst.extent()[i - 1]);
}
TensorFillLinear(dst, stride, s);
}
template <
typename Element
>
void BlockFillSequential(
Element *ptr,
int64_t capacity,
Element v = Element(1),
Element s = Element(0)) {
int i = 0;
while (i < capacity) {
cutlass::ReferenceFactory<Element, (cutlass::sizeof_bits<Element>::value <
8)>::get(ptr, i) = s;
s = Element(s + v);
++i;
}
}
template <
typename Element
>
void BlockFillRandom(
Element *ptr,
size_t capacity,
uint64_t seed,
Distribution dist) {
if (dist.kind == Distribution::Gaussian) {
BlockFillRandomGaussian<Element>(
ptr,
capacity,
seed,
dist.gaussian.mean,
dist.gaussian.stddev,
dist.int_scale);
}
else if (dist.kind == Distribution::Uniform) {
BlockFillRandomUniform<Element>(
ptr,
capacity,
seed,
dist.uniform.max,
dist.uniform.min,
dist.int_scale);
}
}
template <
typename Element,
typename Layout>
void TensorCopyDiagonalIn(
TensorView<Element, Layout> dst,
Element const *ptr) {
typename Layout::Index extent = dst.extent().min();
for (typename Layout::Index i = 0; i < extent; ++i) {
Coord<Layout::kRank> coord(i);
dst.at(coord) = ptr[i];
}
}
template <
typename Element,
typename Layout>
void TensorCopyDiagonalOut(
Element *ptr,
TensorView<Element, Layout> src) {
typename Layout::Index extent = src.extent().min();
for (typename Layout::Index i = 0; i < extent; ++i) {
Coord<Layout::kRank> coord(i);
ptr[i] = src.at(coord);
}
}
} // namespace host
} // namespace reference
} // namespace cutlass
cutlass::reference::host::detail::RandomGaussianFunc::seed
uint64_t seed
Definition: host/tensor_fill.h:112
cutlass::reference::host::detail::TensorFillRandomUniformFunc::operator()
void operator()(Coord< Layout::kRank > const &coord) const
Compute random value and update RNG state.
Definition: host/tensor_fill.h:429
cutlass::cos
CUTLASS_HOST_DEVICE complex< T > cos(complex< T > const &z)
Computes the cosine of complex z.
Definition: complex.h:401
cutlass::reference::host::detail::RandomUniformFunc< complex< Element > >::min
double min
Definition: host/tensor_fill.h:356
cutlass::platform::max
CUTLASS_HOST_DEVICE constexpr const T & max(const T &a, const T &b)
std::max
Definition: platform.h:189
cutlass::reference::host::detail::RandomUniformFunc::Real
typename RealType< Element >::Type Real
Definition: host/tensor_fill.h:303
cutlass::reference::host::TensorCopyDiagonalOut
void TensorCopyDiagonalOut(Element *ptr, TensorView< Element, Layout > src)
Copies the diagonal of a tensor into a dense buffer in host memory.
Definition: host/tensor_fill.h:836
cutlass
Definition: aligned_buffer.h:35
cutlass::Distribution::Uniform
Definition: distribution.h:40
cutlass::reference::host::detail::TensorFillDiagonalFunc
< Layout function
Definition: host/tensor_fill.h:494
cutlass::reference::host::detail::RandomUniformFunc< complex< Element > >::RandomUniformFunc
RandomUniformFunc(uint64_t seed_=0, double max=1, double min_=0, int int_scale_=-1)
Definition: host/tensor_fill.h:363
complex.h
cutlass::Distribution::Gaussian
Definition: distribution.h:40
cutlass::Distribution::uniform
struct cutlass::Distribution::@18::@20 uniform
Uniform distribution.
cutlass::reference::host::detail::TensorFillFunc::TensorView
TensorView< Element, Layout > TensorView
Definition: host/tensor_fill.h:61
cutlass::reference::host::detail::TensorFillDiagonalFunc::operator()
void operator()(Coord< Layout::kRank > const &coord) const
Definition: host/tensor_fill.h:517
cutlass::reference::host::detail::TensorFillDiagonalFunc::diag
Element diag
Definition: host/tensor_fill.h:503
cutlass::reference::host::detail::RandomGaussianFunc::operator()
Element operator()() const
Compute random value and update RNG state.
Definition: host/tensor_fill.h:132
cutlass::RealType::Type
T Type
Definition: real.h:32
cutlass::Distribution::kind
Kind kind
Active variant kind.
Definition: distribution.h:64
cutlass::reference::host::TensorFill
void TensorFill(TensorView< Element, Layout > dst, Element val=Element(0))
Fills a tensor with a uniform value.
Definition: host/tensor_fill.h:92
cutlass::TensorView::extent
CUTLASS_HOST_DEVICE TensorCoord const & extent() const
Returns the extent of the view (the size along each logical dimension).
Definition: tensor_view.h:167
cutlass::reference::host::detail::RandomUniformFunc::RandomUniformFunc
RandomUniformFunc(uint64_t seed_=0, double max=1, double min_=0, int int_scale_=-1)
Definition: host/tensor_fill.h:314
cutlass::reference::host::detail::RandomGaussianFunc< complex< Element > >::RandomGaussianFunc
RandomGaussianFunc(uint64_t seed_=0, double mean_=0, double stddev_=1, int int_scale_=-1)
Definition: host/tensor_fill.h:170
cutlass::Distribution::gaussian
struct cutlass::Distribution::@18::@21 gaussian
Gaussian distribution.
cutlass::reference::host::detail::RandomGaussianFunc< complex< Element > >::int_scale
int int_scale
Definition: host/tensor_fill.h:164
cutlass::reference::host::detail::TensorFillFunc::operator()
void operator()(Coord< Layout::kRank > const &coord) const
Definition: host/tensor_fill.h:79
std
STL namespace.
cutlass::reference::host::detail::TensorUpdateOffDiagonalFunc::view
TensorView view
Definition: host/tensor_fill.h:605
cutlass::reference::host::TensorFillDiagonal
void TensorFillDiagonal(TensorView< Element, Layout > dst, Element diag=Element(1), Element other=Element(0))
Fills a tensor everywhere with a unique value for its diagonal.
Definition: host/tensor_fill.h:540
cutlass::reference::host::detail::TensorFillLinearFunc
< Layout function
Definition: host/tensor_fill.h:667
cutlass::reference::host::detail::RandomGaussianFunc::int_scale
int int_scale
Definition: host/tensor_fill.h:115
cutlass::reference::host::detail::TensorUpdateOffDiagonalFunc
< Layout function
Definition: host/tensor_fill.h:597
cutlass::reference::host::detail::RandomUniformFunc< complex< Element > >::int_scale
int int_scale
Definition: host/tensor_fill.h:357
cutlass::reference::host::TensorFillIdentity
void TensorFillIdentity(TensorView< Element, Layout > dst)
Helper to fill a tensor&#39;s diagonal with 1 and 0 everywhere else.
Definition: host/tensor_fill.h:564
cutlass::reference::host::detail::RandomUniformFunc< complex< Element > >::operator()
complex< Element > operator()() const
Compute random value and update RNG state.
Definition: host/tensor_fill.h:375
cutlass::log
CUTLASS_HOST_DEVICE complex< T > log(complex< T > const &z)
Computes the complex exponential of z.
Definition: complex.h:381
cutlass::reference::host::detail::TensorFillGaussianFunc::operator()
void operator()(Coord< Layout::kRank > const &coord) const
Compute random value and update RNG state.
Definition: host/tensor_fill.h:236
array.h
Statically sized array of elements that accommodates all CUTLASS-supported numeric types and is safe ...
CUTLASS_PRAGMA_UNROLL
#define CUTLASS_PRAGMA_UNROLL
Definition: cutlass.h:110
cutlass::reference::host::detail::RandomGaussianFunc::mean
double mean
Definition: host/tensor_fill.h:113
cutlass::reference::host::TensorUpdateOffDiagonal
void TensorUpdateOffDiagonal(TensorView< Element, Layout > dst, Element other=Element(1))
Writes a uniform value to all elements in the tensor without modifying diagonal elements.
Definition: host/tensor_fill.h:643
cutlass::reference::host::detail::TensorFillLinearFunc::s
Element s
Definition: host/tensor_fill.h:677
cutlass::reference::host::detail::TensorFillLinearFunc::v
Array< Element, Layout::kRank > v
Definition: host/tensor_fill.h:676
cutlass::TensorView< Element, Layout >
cutlass::reference::host::detail::RandomUniformFunc< complex< Element > >::Real
typename RealType< Element >::Type Real
Definition: host/tensor_fill.h:352
cutlass::reference::host::detail::TensorFillGaussianFunc::view
TensorView view
Definition: host/tensor_fill.h:219
cutlass::reference::host::TensorFillRandomGaussian
void TensorFillRandomGaussian(TensorView< Element, Layout > dst, uint64_t seed, double mean=0, double stddev=1, int bits=-1)
Fills a tensor with random values with a Gaussian distribution.
Definition: host/tensor_fill.h:249
cutlass::reference::host::detail::RandomGaussianFunc< complex< Element > >::stddev
double stddev
Definition: host/tensor_fill.h:163
cutlass::reference::host::detail::RandomGaussianFunc< complex< Element > >::operator()
complex< Element > operator()() const
Compute random value and update RNG state.
Definition: host/tensor_fill.h:181
cutlass::reference::host::TensorFillLinear
void TensorFillLinear(TensorView< Element, Layout > dst, Array< Element, Layout::kRank > const &v, Element s=Element(0))
Fills tensor with a linear combination of its coordinate and another vector.
Definition: host/tensor_fill.h:715
cutlass::reference::host::detail::TensorFillGaussianFunc
Computes a random Gaussian distribution.
Definition: host/tensor_fill.h:211
cutlass::reference::host::TensorUpdateDiagonal
void TensorUpdateDiagonal(TensorView< Element, Layout > dst, Element val=Element(1))
Writes a uniform value to the diagonal of a tensor without modifying off-diagonal elements...
Definition: host/tensor_fill.h:577
cutlass::reference::host::detail::TensorFillRandomUniformFunc::view
TensorView view
Definition: host/tensor_fill.h:412
cutlass::ReferenceFactory
Definition: subbyte_reference.h:557
cutlass::reference::host::detail::TensorFillLinearFunc::operator()
void operator()(Coord< Layout::kRank > const &coord) const
Updates the tensor.
Definition: host/tensor_fill.h:694
cutlass::reference::host::BlockFillRandomGaussian
void BlockFillRandomGaussian(Element *ptr, size_t capacity, uint64_t seed, double mean=0, double stddev=1, int bits=-1)
Fills a tensor with random values with a Gaussian distribution.
Definition: host/tensor_fill.h:277
distribution.h
This header contains a class to parametrize a statistical distribution function.
cutlass::reference::host::detail::TensorFillDiagonalFunc::view
TensorView view
Definition: host/tensor_fill.h:502
cutlass::reference::host::detail::TensorFillFunc::value
Element value
Definition: host/tensor_fill.h:68
cutlass::reference::host::detail::RandomUniformFunc::operator()
Element operator()() const
Compute random value and update RNG state.
Definition: host/tensor_fill.h:326
cutlass::reference::host::detail::RandomUniformFunc
Definition: host/tensor_fill.h:301
numeric_types.h
Top-level include for all CUTLASS numeric types.
cutlass::reference::host::detail::TensorFillLinearFunc::TensorFillLinearFunc
TensorFillLinearFunc(TensorView const &view_, Array< Element, Layout::kRank > const &v_, Element s_=Element(0))
Constructs functor.
Definition: host/tensor_fill.h:686
cutlass::platform::min
CUTLASS_HOST_DEVICE constexpr const T & min(const T &a, const T &b)
std::min
Definition: platform.h:183
cutlass::reference::host::detail::RandomGaussianFunc::pi
double pi
Definition: host/tensor_fill.h:116
cutlass::reference::host::detail::TensorUpdateOffDiagonalFunc::operator()
void operator()(Coord< Layout::kRank > const &coord) const
Definition: host/tensor_fill.h:618
cutlass::reference::host::detail::RandomUniformFunc< complex< Element > >::range
double range
Definition: host/tensor_fill.h:355
cutlass::reference::host::BlockFillSequential
void BlockFillSequential(Element *ptr, int64_t capacity, Element v=Element(1), Element s=Element(0))
Fills a block of data with sequential elements.
Definition: host/tensor_fill.h:761
cutlass::reference::host::detail::RandomGaussianFunc::stddev
double stddev
Definition: host/tensor_fill.h:114
cutlass::reference::host::detail::RandomGaussianFunc< complex< Element > >::pi
double pi
Definition: host/tensor_fill.h:165
cutlass::reference::host::detail::TensorUpdateOffDiagonalFunc::TensorUpdateOffDiagonalFunc
TensorUpdateOffDiagonalFunc(TensorView const &view_=TensorView(), Element other_=Element(0))
Definition: host/tensor_fill.h:612
cutlass::reference::host::detail::RandomGaussianFunc
Definition: host/tensor_fill.h:110
cutlass::reference::host::detail::RandomGaussianFunc< complex< Element > >::seed
uint64_t seed
Definition: host/tensor_fill.h:161
cutlass::Coord< Layout::kRank >
cutlass::reference::host::detail::TensorFillGaussianFunc::TensorFillGaussianFunc
TensorFillGaussianFunc(TensorView view_=TensorView(), RandomGaussianFunc< Element > func_=RandomGaussianFunc< Element >())
Construction of Gaussian RNG functor.
Definition: host/tensor_fill.h:227
cutlass::reference::host::detail::TensorUpdateOffDiagonalFunc::other
Element other
Definition: host/tensor_fill.h:606
cutlass::reference::host::detail::TensorFillDiagonalFunc::TensorFillDiagonalFunc
TensorFillDiagonalFunc(TensorView const &view_=TensorView(), Element diag_=Element(1), Element other_=Element(0))
Definition: host/tensor_fill.h:510
cutlass::reference::host::detail::RandomGaussianFunc::RandomGaussianFunc
RandomGaussianFunc(uint64_t seed_=0, double mean_=0, double stddev_=1, int int_scale_=-1)
Definition: host/tensor_fill.h:121
cutlass::reference::host::detail::TensorFillFunc::view
TensorView view
Definition: host/tensor_fill.h:67
cutlass::complex
Definition: complex.h:92
cutlass::reference::host::detail::RandomUniformFunc< complex< Element > >::seed
uint64_t seed
Definition: host/tensor_fill.h:354
cutlass::TensorRef::at
CUTLASS_HOST_DEVICE Reference at(TensorCoord const &coord) const
Returns a reference to the element at a given Coord.
Definition: tensor_ref.h:307
cutlass::reference::host::detail::RandomUniformFunc::range
double range
Definition: host/tensor_fill.h:306
cutlass::reference::host::detail::TensorFillLinearFunc::TensorFillLinearFunc
TensorFillLinearFunc()
Definition: host/tensor_fill.h:683
cutlass::reference::host::BlockFillRandomUniform
void BlockFillRandomUniform(Element *ptr, size_t capacity, uint64_t seed, double max=1, double min=0, int bits=-1)
Fills a tensor with random values with a uniform random distribution.
Definition: host/tensor_fill.h:470
cutlass::reference::host::detail::TensorFillRandomUniformFunc::func
RandomUniformFunc< Element > func
Definition: host/tensor_fill.h:413
cutlass::reference::host::TensorForEach
void TensorForEach(Coord< Rank > extent, Func &func)
Iterates over the index space of a tensor.
Definition: host/tensor_foreach.h:87
cutlass::reference::host::TensorFillRandomUniform
void TensorFillRandomUniform(TensorView< Element, Layout > dst, uint64_t seed, double max=1, double min=0, int bits=-1)
Fills a tensor with random values with a uniform random distribution.
Definition: host/tensor_fill.h:443
cutlass::reference::host::TensorCopyDiagonalIn
void TensorCopyDiagonalIn(TensorView< Element, Layout > dst, Element const *ptr)
Copies a diagonal in from host memory without modifying off-diagonal elements.
Definition: host/tensor_fill.h:817
cutlass::reference::host::detail::RandomUniformFunc::min
double min
Definition: host/tensor_fill.h:307
cutlass::Distribution
Distribution type.
Definition: distribution.h:38
cutlass::reference::host::detail::TensorFillGaussianFunc::func
RandomGaussianFunc< Element > func
Definition: host/tensor_fill.h:220
cutlass::reference::host::TensorFillSequential
void TensorFillSequential(TensorView< Element, Layout > dst, Element s=Element(0))
Fills tensor with a linear combination of its coordinate and another vector.
Definition: host/tensor_fill.h:738
cutlass::reference::host::detail::TensorFillFunc
< Layout function
Definition: host/tensor_fill.h:59
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::reference::host::detail::TensorFillFunc::TensorFillFunc
TensorFillFunc(TensorView const &view_=TensorView(), Element value_=Element(0))
Definition: host/tensor_fill.h:74
cutlass::reference::host::detail::TensorFillRandomUniformFunc
Computes a random Gaussian distribution.
Definition: host/tensor_fill.h:404
cutlass.h
Basic include for CUTLASS.
cutlass::reference::host::detail::RandomGaussianFunc< complex< Element > >::mean
double mean
Definition: host/tensor_fill.h:162
cutlass::reference::host::detail::TensorFillLinearFunc::view
TensorView view
Definition: host/tensor_fill.h:675
cutlass::reference::host::detail::RandomUniformFunc::seed
uint64_t seed
Definition: host/tensor_fill.h:305
cutlass::reference::host::detail::TensorFillRandomUniformFunc::TensorFillRandomUniformFunc
TensorFillRandomUniformFunc(TensorView view_=TensorView(), RandomUniformFunc< Element > func_=RandomUniformFunc< Element >())
Construction of Gaussian RNG functor.
Definition: host/tensor_fill.h:420
cutlass::sqrt
CUTLASS_HOST_DEVICE complex< T > sqrt(complex< T > const &z)
Computes the square root of complex number z.
Definition: complex.h:393
cutlass::reference::host::detail::RandomUniformFunc::int_scale
int int_scale
Definition: host/tensor_fill.h:308
cutlass::reference::host::detail::TensorFillDiagonalFunc::other
Element other
Definition: host/tensor_fill.h:504
cutlass::reference::host::BlockFillRandom
void BlockFillRandom(Element *ptr, size_t capacity, uint64_t seed, Distribution dist)
Fills a block of data with sequential elements.
Definition: host/tensor_fill.h:784
tensor_foreach.h