CUTLASS
CUDA Templates for Linear Algebra Subroutines and Solvers
conversion_op.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  **************************************************************************************************/
29 #pragma once
30 
31 #include "cutlass/cutlass.h"
32 #include "cutlass/numeric_types.h"
33 #include "cutlass/array.h"
34 #include "cutlass/functional.h"
36 
38 
39 namespace cutlass {
40 namespace epilogue {
41 namespace thread {
42 
44 
47 template <
48  typename ElementOutput_,
49  int Count,
50  typename ElementAccumulator_ = ElementOutput_,
52 >
53 class Convert {
54 public:
55 
56  using ElementOutput = ElementOutput_;
57  using ElementAccumulator = ElementAccumulator_;
58  using ElementCompute = ElementAccumulator_;
59 
60  static int const kCount = Count;
61 
62  using FragmentOutput = Array<ElementOutput, kCount>;
63  using FragmentAccumulator = Array<ElementAccumulator, kCount>;
65 
66  static FloatRoundStyle const kRound = Round;
67 
69  struct Params {
70 
71  //
72  // Methods
73  //
74 
76  Params() {}
77  };
78 
79 public:
80 
83  Convert(Params const &params = Params()) {
84 
85  }
86 
89  constexpr bool is_source_needed() const {
90  return false;
91  }
92 
97  return false;
98  }
99 
103  FragmentAccumulator const &accumulator,
104  FragmentOutput const &source,
105  ElementCompute uniform = ElementCompute(0)) const {
106 
107  // Convert to destination numeric type
109 
110  return destination_converter(accumulator);
111  }
112 };
113 
115 
116 } // namespace thread
117 } // namespace epilogue
118 } // namespace cutlass
Definition: conversion_op.h:53
CUTLASS_HOST_DEVICE Convert(Params const &params=Params())
Constructs the function object, possibly loading from pointers in host memory.
Definition: conversion_op.h:83
FragmentAccumulator ComputeFragment
Definition: conversion_op.h:64
Definition: aligned_buffer.h:35
#define constexpr
Definition: platform.h:137
CUTLASS_HOST_DEVICE constexpr bool is_source_needed() const
Returns true if source is needed based on state of runtime arguments.
Definition: conversion_op.h:89
static FloatRoundStyle const kRound
Definition: conversion_op.h:66
ElementAccumulator_ ElementAccumulator
Definition: conversion_op.h:57
Statically sized array of elements that accommodates all CUTLASS-supported numeric types and is safe ...
CUTLASS_HOST_DEVICE FragmentOutput operator()(FragmentAccumulator const &accumulator, FragmentOutput const &source, ElementCompute uniform=ElementCompute(0)) const
Computes linear scaling: D = alpha * accumulator + beta * source.
Definition: conversion_op.h:102
Boost-like numeric conversion operator for CUTLASS numeric types.
static int const kCount
Definition: conversion_op.h:60
#define CUTLASS_HOST_DEVICE
Definition: cutlass.h:89
Top-level include for all CUTLASS numeric types.
CUTLASS_HOST_DEVICE Params()
Definition: conversion_op.h:76
ElementOutput_ ElementOutput
Definition: conversion_op.h:56
Array< ElementAccumulator, kCount > FragmentAccumulator
Definition: conversion_op.h:63
ElementAccumulator_ ElementCompute
Definition: conversion_op.h:58
FloatRoundStyle
Definition: numeric_conversion.h:43
CUTLASS_HOST_DEVICE constexpr bool is_source_ever_needed() const
Definition: conversion_op.h:96
Conversion operator for Array.
Definition: numeric_conversion.h:294
Array< ElementOutput, kCount > FragmentOutput
Definition: conversion_op.h:62
Basic include for CUTLASS.
Host-constructable parameters structure.
Definition: conversion_op.h:69
Define basic numeric operators with specializations for Array<T, N>. SIMD-ize where possible...