1 /* Copyright 2017 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_CONTRIB_FUSED_CONV_KERNELS_FUSED_CONV_OPS_GPU_H_ 17 #define TENSORFLOW_CONTRIB_FUSED_CONV_KERNELS_FUSED_CONV_OPS_GPU_H_ 18 19 #if GOOGLE_CUDA 20 21 #include "tensorflow/core/kernels/conv_ops_gpu.h" 22 #include "tensorflow/core/util/activation_mode.h" 23 24 // TODO(pauldonnelly): Merge this file into core/kernels/conv_ops_gpu.h. 25 26 namespace tensorflow { 27 28 // Add additional parameters specific to fused convolutions. 29 class FusedConvParameters : public ConvParameters { 30 public: FusedConvParameters(int64 batch,int64 in_depths,const SpatialArray & in,TensorFormat data_format,int64 out_depths,const SpatialArray & filter,const SpatialArray & dilation,const SpatialArray & stride,const SpatialArray & padding,DataType dtype,int device_id,bool has_side_input,ActivationMode activation_mode)31 FusedConvParameters(int64 batch, int64 in_depths, const SpatialArray& in, 32 TensorFormat data_format, int64 out_depths, 33 const SpatialArray& filter, const SpatialArray& dilation, 34 const SpatialArray& stride, const SpatialArray& padding, 35 DataType dtype, int device_id, bool has_side_input, 36 ActivationMode activation_mode) 37 : ConvParameters(batch, in_depths, in, data_format, out_depths, filter, 38 dilation, stride, padding, dtype, device_id), 39 activation_mode_(activation_mode), 40 has_side_input_(has_side_input) { 41 hash_code_ = Hash64Combine(hash_code_, has_side_input); 42 hash_code_ = Hash64Combine(hash_code_, activation_mode); 43 } 44 45 bool operator==(const FusedConvParameters& other) const { 46 return this->get_data_as_tuple() == other.get_data_as_tuple(); 47 } 48 49 bool operator!=(const FusedConvParameters& other) const { 50 return !(*this == other); 51 } 52 ToString()53 string ToString() const { 54 return strings::StrCat(ConvParameters::ToString(), ", ", has_side_input_, 55 ", ", activation_mode_, ", "); 56 } 57 58 private: 59 using ParameterDataType = 60 std::tuple<ConvParameters::ParameterDataType, bool, ActivationMode>; 61 get_data_as_tuple()62 ParameterDataType get_data_as_tuple() const { 63 return std::make_tuple(ConvParameters::get_data_as_tuple(), has_side_input_, 64 activation_mode_); 65 } 66 67 ActivationMode activation_mode_; 68 bool has_side_input_; 69 }; 70 71 } // namespace tensorflow 72 73 #endif // GOOGLE_CUDA 74 75 #endif // TENSORFLOW_CONTRIB_FUSED_CONV_KERNELS_FUSED_CONV_OPS_GPU_H_ 76