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 #define EIGEN_USE_THREADS 17 18 #include "third_party/eigen3/unsupported/Eigen/CXX11/Tensor" 19 #include "tensorflow/compiler/xla/service/cpu/custom_call_target_registry.h" 20 #include "tensorflow/core/framework/tensor_types.h" 21 #include "tensorflow/core/platform/dynamic_annotations.h" 22 #include "tensorflow/core/platform/macros.h" 23 #include "tensorflow/core/platform/types.h" 24 25 namespace tensorflow { 26 27 EIGEN_STRONG_INLINE void argmax_float_2d_xla_impl(void* out, void** data) { 28 // data is managed by the JIT code so msan can't tell it's initialized. 29 TF_ANNOTATE_MEMORY_IS_INITIALIZED(data, 4 * sizeof(void*)); 30 31 float* in = static_cast<float*>(data[0]); 32 int64* in_sizes = static_cast<int64*>(data[1]); 33 int64* out_sizes = static_cast<int64*>(data[2]); 34 int32 dim = *static_cast<int32*>(data[3]); 35 36 Eigen::DSizes<Eigen::DenseIndex, 2> in_eig_sizes(in_sizes[0], in_sizes[1]); 37 TTypes<float, 2>::ConstTensor in_eig(in, in_eig_sizes); 38 39 int64* out_t = static_cast<int64*>(out); 40 Eigen::DSizes<Eigen::DenseIndex, 1> out_eig_sizes(out_sizes[0]); 41 TTypes<int64, 1>::Tensor out_eig(out_t, out_eig_sizes); 42 43 out_eig = in_eig.argmax(dim).cast<int64>(); 44 } 45 46 } // namespace tensorflow 47 48 // Implements argmax on CPU. This is called by an XLA custom call, set up by 49 // index_ops.cc. 50 extern "C" void TF_EXPORT argmax_float_2d_xla_impl(void* out, void** data) { 51 tensorflow::argmax_float_2d_xla_impl(out, data); 52 } 53 54 REGISTER_CUSTOM_CALL_TARGET(argmax_float_2d_xla_impl); 55