Home | History | Annotate | Download | only in tf2xla
      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 #include "tensorflow/compiler/tf2xla/type_util.h"
     17 
     18 #include "tensorflow/core/framework/types.h"
     19 #include "tensorflow/core/lib/core/errors.h"
     20 
     21 namespace tensorflow {
     22 
     23 Status DataTypeToPrimitiveType(DataType data_type, xla::PrimitiveType* type) {
     24   switch (data_type) {
     25     case tensorflow::DT_BOOL:
     26       *type = xla::PRED;
     27       return Status::OK();
     28     case tensorflow::DT_INT8:
     29       *type = xla::S8;
     30       return Status::OK();
     31     case tensorflow::DT_INT16:
     32       *type = xla::S16;
     33       return Status::OK();
     34     case tensorflow::DT_INT32:
     35       *type = xla::S32;
     36       return Status::OK();
     37     case tensorflow::DT_INT64:
     38       *type = xla::S64;
     39       return Status::OK();
     40     case tensorflow::DT_UINT8:
     41       *type = xla::U8;
     42       return Status::OK();
     43     case tensorflow::DT_UINT16:
     44       *type = xla::U16;
     45       return Status::OK();
     46     case tensorflow::DT_UINT32:
     47       *type = xla::U32;
     48       return Status::OK();
     49     case tensorflow::DT_UINT64:
     50       *type = xla::U64;
     51       return Status::OK();
     52     case tensorflow::DT_BFLOAT16:
     53       *type = xla::BF16;
     54       return Status::OK();
     55     case tensorflow::DT_HALF:
     56       *type = xla::F16;
     57       return Status::OK();
     58     case tensorflow::DT_FLOAT:
     59       *type = xla::F32;
     60       return Status::OK();
     61     case tensorflow::DT_DOUBLE:
     62       *type = xla::F64;
     63       return Status::OK();
     64     case tensorflow::DT_COMPLEX64:
     65       *type = xla::C64;
     66       return Status::OK();
     67     case tensorflow::DT_QUINT8:
     68       *type = xla::U8;
     69       return Status::OK();
     70     case tensorflow::DT_QINT32:
     71       *type = xla::S32;
     72       return Status::OK();
     73     default:
     74       return errors::InvalidArgument(
     75           "Unsupported type in DataTypeToPrimitiveType ",
     76           DataTypeString(data_type));
     77   }
     78 }
     79 
     80 }  // namespace tensorflow
     81