/* Copyright 2015 The TensorFlow Authors. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ #if GOOGLE_CUDA #define EIGEN_USE_GPU #include "tensorflow/core/framework/register_types.h" #include "tensorflow/core/framework/tensor_types.h" #include "tensorflow/core/kernels/fill_functor.h" #include "tensorflow/core/platform/types.h" namespace Eigen { namespace internal { template struct scalar_const_op { typedef typename packet_traits::type Packet; const T* val; EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE scalar_const_op(const scalar_const_op& x) : val(x.val) {} EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE scalar_const_op(const T* v) : val(v) {} EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const T operator()() const { return *val; } template EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const PacketType packetOp() const { return internal::pset1(*val); } }; template struct functor_traits > { enum { Cost = 1, PacketAccess = packet_traits::Vectorizable, IsRepeatable = true }; }; } // end namespace internal } // end namespace Eigen namespace tensorflow { namespace functor { typedef Eigen::GpuDevice GPUDevice; // Partial specialization FillFunctor template struct FillFunctor { void operator()(const GPUDevice& d, typename TTypes::Flat out, typename TTypes::ConstScalar in) { Eigen::internal::scalar_const_op f(in.data()); To32Bit(out).device(d) = To32Bit(out).nullaryExpr(f); } }; #define DEFINE_FILL_GPU(T) template struct FillFunctor; TF_CALL_NUMBER_TYPES(DEFINE_FILL_GPU); TF_CALL_bool(DEFINE_FILL_GPU); #undef DEFINE_FILL_GPU // Partial specialization of FillFunctor. template struct SetZeroFunctor { void operator()(const GPUDevice& d, typename TTypes::Flat out) { To32Bit(out).device(d) = To32Bit(out).constant(T(0)); } }; #define DEFINE_SETZERO_GPU(T) template struct SetZeroFunctor; TF_CALL_NUMBER_TYPES(DEFINE_SETZERO_GPU); TF_CALL_bool(DEFINE_SETZERO_GPU); #undef DEFINE_SETZERO_GPU // Partial specialization of FillFunctor. template struct SetOneFunctor { void operator()(const GPUDevice& d, typename TTypes::Flat out) { To32Bit(out).device(d) = To32Bit(out).constant(T(1)); } }; #define DEFINE_SETONE_GPU(T) template struct SetOneFunctor; TF_CALL_NUMBER_TYPES(DEFINE_SETONE_GPU); TF_CALL_bool(DEFINE_SETONE_GPU); #undef DEFINE_SETONE_GPU } // end namespace functor } // end namespace tensorflow #endif // GOOGLE_CUDA