2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "luci/Import/Nodes/CircleCast.h"
19 #include <luci/IR/Nodes/CircleCast.h>
21 #include <luci/UserSettings.h>
29 bool CircleCastGraphBuilder::validate(const ValidateArgs &args) const
33 auto settings = luci::UserSettings::settings();
35 const auto &inputs = args.op.inputs;
36 const auto &outputs = args.op.outputs;
37 if (inputs.size() != 1)
39 if (outputs.size() != 1)
42 // NOTE real models do have type mismatch
43 const auto *options = args.op.builtin_options.AsCastOptions();
44 if (options != nullptr)
46 const auto &tensors = args.reader.tensors();
47 const circle::TensorT &output_tensor = *tensors[outputs[0]];
48 auto name = tensor_name(output_tensor);
50 const auto &tensor_in = tensors.at(inputs.at(0));
51 if (tensor_in->type != options->in_data_type)
53 if (settings->get(luci::UserSettings::Key::DisableValidation))
55 WARN(l) << "Warning: import Cast(" << name << ") dtype mismatch";
60 const auto &tensor_out = tensors.at(outputs[0]);
61 if (tensor_out->type != options->out_data_type)
63 if (settings->get(luci::UserSettings::Key::DisableValidation))
65 WARN(l) << "Warning: import Cast(" << name << ") dtype mismatch";
75 CircleNode *CircleCastGraphBuilder::build_node(const circle::OperatorT &op,
76 const std::vector<CircleNode *> &inputs,
77 loco::Graph *graph) const
79 auto *node = graph->nodes()->create<CircleCast>();
80 node->x(inputs.at(0));
82 const auto *options = op.builtin_options.AsCastOptions();
83 if (options != nullptr)
85 node->in_data_type(luci_datatype(options->in_data_type));
86 node->out_data_type(luci_datatype(options->out_data_type));
90 node->in_data_type(inputs.at(0)->dtype());
91 node->out_data_type(loco::DataType::Unknown);
92 // type inference should use node->dtype() for Unknown
93 // export should use BuiltinOptions_NONE for Unknown