Skip to content

Commit

Permalink
replace assert with CHECK
Browse files Browse the repository at this point in the history
  • Loading branch information
okdshin committed Aug 27, 2019
1 parent b24c4dd commit bacce56
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions menoh/menoh_chainer_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ onnx::TensorProto::DataType menoh_dtype_to_xtensor_dtype(menoh_dtype mdtype) {
} else if (mdtype == menoh_dtype_bool) {
return onnx::TensorProto::BOOL;
} else {
assert(!"Not Implemeneted");
CHECK(false) << "Not Implemeneted menoh_dtype: " << mdtype;
}
return onnx::TensorProto::UNDEFINED;
}
Expand Down Expand Up @@ -602,7 +602,7 @@ menoh_error_code menoh_build_model(
auto xgraph = *(builder->xgraph);

// Set initializer
assert(xgraph.initializer().empty());
CHECK(xgraph.initializer().empty());
for (onnx::TensorProto const& xtensor : model_data->xgraph.initializer()) {
*(xgraph.add_initializer()) = xtensor;
}
Expand All @@ -626,7 +626,7 @@ menoh_error_code menoh_build_model(
for (const chainer_compiler::Value* input : graph.input_values()) {
if (!input->initializer()) { // user input is input which doesn't have initializer
auto p = builder->input_profile_table.find(input->name());
assert(p != builder->input_profile_table.end());
CHECK(p != builder->input_profile_table.end()) << input->name() << " is not found in input_profile_table";
void* datap = nullptr;
auto found = builder->external_buffer_handle_table.find(input->name());
if (found != builder->external_buffer_handle_table.end()) {
Expand All @@ -652,7 +652,7 @@ menoh_error_code menoh_build_model(
datap = found->second;
} else {
auto p = builder->output_profile_table.find(output->name());
assert(p != builder->output_profile_table.end());
CHECK(p != builder->output_profile_table.end()) << output->name() << " is not found in output_profile_table";
auto data = allocate_buffer(p->second);
buffer_holder.push_back(data);
datap = data.get();
Expand Down Expand Up @@ -755,13 +755,14 @@ menoh_error_code menoh_model_run(menoh_model_handle model) {
auto outputs = model->chxvm->Run(model->inputs, model->chxvm_options);
for (auto output : outputs) {
auto found = model->outputs.find(output.first);
assert(found != model->outputs.end() && "output buffer not found");
CHECK(found != model->outputs.end()) << "output buffer for " << output.first << " is not found";
auto const& array = chainerx::AsContiguous(output.second->GetArray());
auto const& shape = array.shape();
auto bytesize = shape.GetTotalSize() * chainerx::GetItemSize(array.dtype());
assert(model->variable_profiles.find(output.first) != model->variable_profiles.end());
assert(bytesize == menoh_impl::total_size_in_bytes(variable_profiles.find(output.first)->second) &&
"allocated output buffer size is not same to cc's output buffer size");
CHECK(model->variable_profiles.find(output.first) != model->variable_profiles.end())
<< output.first << " is not found in variable_profiles";
CHECK_EQ(bytesize, menoh_impl::total_size_in_bytes(model->variable_profiles.find(output.first)->second))
<< "allocated output buffer size is not equal to cc's output buffer size";
std::copy(
static_cast<uint8_t*>(array.raw_data()),
static_cast<uint8_t*>(array.raw_data()) + bytesize,
Expand Down

0 comments on commit bacce56

Please sign in to comment.