• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2015 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #ifndef TENSORFLOW_CORE_KERNELS_BIAS_OP_GPU_H_
17 #define TENSORFLOW_CORE_KERNELS_BIAS_OP_GPU_H_
18 
19 #define EIGEN_USE_GPU
20 
21 #include "third_party/eigen3/unsupported/Eigen/CXX11/Tensor"
22 #include "tensorflow/core/framework/op_kernel.h"
23 #include "tensorflow/core/framework/tensor_types.h"
24 #include "tensorflow/core/kernels/gpu_utils.h"
25 #include "tensorflow/core/util/tensor_format.h"
26 
27 namespace tensorflow {
28 
29 typedef Eigen::GpuDevice GPUDevice;
30 
31 template <typename T>
32 struct BiasGPU {
33   static void compute(const GPUDevice& d, const T* input, const T* bias,
34                       T* output, int32_t batch, int32_t height, int32_t width,
35                       int32_t depth, int32_t channel, TensorFormat data_format);
36 };
37 
38 template <typename T>
39 struct BiasGradGPU {
40   static void compute(const GPUDevice& device, const T* output_backprop,
41                       T* bias_backprop, int32_t batch, int32_t height,
42                       int32_t width, int32_t depth, int32_t channel,
43                       TensorFormat data_format);
44 
45   static void DoRowReduction(OpKernelContext* context, T* output,
46                              const T* input, int rows, int cols);
47 
48   static void DoColReduction(OpKernelContext* context, T* output,
49                              const T* input, int rows, int cols);
50 };
51 
52 enum class BiasAddGradGPUMode {
53   kInvalid = 0,
54   kNative = 1,
55   kReduction = 2,
56 };
57 
58 // Describe the BiasGradGPU result from a perf experiment.
59 //
60 // Arguments:
61 // algorithm: returns the method to use for bias add grad.
62 // elapsed_time; returns the measured elapsed time in microseconds.
63 class BiasGradGPUProfileResult {
64  public:
is_valid()65   bool is_valid() const {
66     return (algorithm_ != BiasAddGradGPUMode::kInvalid &&
67             elapsed_time_ != std::numeric_limits<float>::max());
68   }
algorithm()69   BiasAddGradGPUMode algorithm() const { return algorithm_; }
set_algorithm(BiasAddGradGPUMode val)70   void set_algorithm(BiasAddGradGPUMode val) { algorithm_ = val; }
elapsed_time()71   uint64 elapsed_time() const { return elapsed_time_; }
set_elapsed_time(uint64 val)72   void set_elapsed_time(uint64 val) { elapsed_time_ = val; }
73 
74  private:
75   BiasAddGradGPUMode algorithm_ = BiasAddGradGPUMode::kInvalid;
76   uint64 elapsed_time_ = std::numeric_limits<uint64>::max();
77 };
78 
79 }  // namespace tensorflow
80 
81 #endif  // TENSORFLOW_CORE_KERNELS_BIAS_OP_GPU_H_
82