Home | History | Annotate | Download | only in kernels
      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_1d_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, 2 * sizeof(void*));
     30 
     31   float* input = static_cast<float*>(data[0]);
     32   int64 input_size = *static_cast<int64*>(data[1]);
     33 
     34   Eigen::DSizes<Eigen::DenseIndex, 1> in_eig_sizes(input_size);
     35   TTypes<float, 1>::ConstTensor in_eig(input, in_eig_sizes);
     36 
     37   Eigen::DSizes<Eigen::DenseIndex, 0> out_eig_sizes;
     38   int64* out_t = static_cast<int64*>(out);
     39   TTypes<int64, 0>::Tensor out_eig(out_t, out_eig_sizes);
     40 
     41   out_eig = in_eig.argmax(0).cast<int64>();
     42 }
     43 
     44 }  // namespace tensorflow
     45 
     46 // Implements argmax on CPU. This is called by an XLA custom call, set up by
     47 // index_ops.cc.
     48 extern "C" void TF_EXPORT argmax_float_1d_xla_impl(void* out, void** data) {
     49   tensorflow::argmax_float_1d_xla_impl(out, data);
     50 }
     51 
     52 REGISTER_CUSTOM_CALL_TARGET(argmax_float_1d_xla_impl);
     53