1 /* Copyright 2019 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 #ifndef TENSORFLOW_COMPILER_XLA_SERVICE_GPU_CUDNN_BATCHNORM_RUNNER_H_
16 #define TENSORFLOW_COMPILER_XLA_SERVICE_GPU_CUDNN_BATCHNORM_RUNNER_H_
17 
18 #include "absl/types/optional.h"
19 #include "tensorflow/compiler/xla/service/gpu/ir_emission_utils.h"
20 #include "tensorflow/compiler/xla/service/hlo_instruction.h"
21 #include "tensorflow/compiler/xla/service/hlo_instructions.h"
22 #include "tensorflow/compiler/xla/status.h"
23 #include "tensorflow/compiler/xla/statusor.h"
24 #include "tensorflow/compiler/xla/types.h"
25 #include "tensorflow/compiler/xla/xla_data.pb.h"
26 #include "tensorflow/core/platform/stream_executor_no_cuda.h"
27 
28 namespace xla {
29 namespace gpu {
30 
31 struct CudnnBatchNormConfig {
32   Shape output_shape;
33   PrimitiveType output_type;
34   float epsilon;
35   int64 feature_index;
36 };
37 
38 CudnnBatchNormConfig GetCudnnBatchNormConfig(const HloInstruction *instr,
39                                              float epsilon,
40                                              int64 feature_index);
41 
42 Status RunCudnnBatchNormForwardInference(
43     const CudnnBatchNormConfig &config, se::DeviceMemoryBase operand,
44     se::DeviceMemoryBase output, se::DeviceMemory<float> scale,
45     se::DeviceMemory<float> offset, se::DeviceMemory<float> mean,
46     se::DeviceMemory<float> variance, se::Stream *stream);
47 
48 Status RunCudnnBatchNormForwardTraining(
49     const CudnnBatchNormConfig &config, se::DeviceMemoryBase operand,
50     se::DeviceMemoryBase output_data, se::DeviceMemory<float> output_mean,
51     se::DeviceMemory<float> output_inv_stddev, se::DeviceMemory<float> scale,
52     se::DeviceMemory<float> offset, se::Stream *stream);
53 
54 Status RunCudnnBatchNormBackward(
55     const CudnnBatchNormConfig &config, se::DeviceMemoryBase operand,
56     se::DeviceMemoryBase output_grad_data, se::DeviceMemoryBase grad_output,
57     se::DeviceMemory<float> output_grad_scale,
58     se::DeviceMemory<float> output_grad_offset, se::DeviceMemory<float> scale,
59     se::DeviceMemory<float> mean, se::DeviceMemory<float> inv_stddev,
60     se::Stream *stream);
61 }  // namespace gpu
62 }  // namespace xla
63 #endif  // TENSORFLOW_COMPILER_XLA_SERVICE_GPU_CUDNN_BATCHNORM_RUNNER_H_
64