onnxruntime/nodejs/src/run_options_helper.cc
Yulong Wang 5dfc91db51
Node.js binding for ONNX Runtime (#3613)
* initial commit for Node.js binding

* add c++ code

* add inference session impl

* e2e working

* add settings.json

* add test data

* adjust binding declaration

* refine tensor constructor declaration

* update tests

* enable onnx tests

* simply refine readme

* refine cpp impl

* refine tests

* formatting

* add linting

* move bin folder

* fix linux build

* manually update test filter list

* update C++ API headers: fix crash in release build

* make (manually) prebuild work

* add test into prepack script

* specify prebuild runtime type (N-API)

* build.ts: update rebuild and include regex

* fix lazy load on electron.js

* update dev version, git link and binary host

* support session options and run options

* bump dev version

* update README

* add 1 example

* move folder

* adjust path

* update document for examples

* rename example 01

* add example 02

* add session option: log severity level

* add example 04

* resolve comments

* fix typo

* remove double guard in header files

* add copyright banner

* move BUILD outside from README

* consume test filter list from onnxruntime
2020-05-05 11:45:12 -07:00

33 lines
1.3 KiB
C++

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#include "onnxruntime_cxx_api.h"
#include <napi.h>
#include <cmath>
#include "common.h"
#include "run_options_helper.h"
void ParseRunOptions(const Napi::Object options, Ort::RunOptions &runOptions) {
// Log severity level
if (options.Has("logSeverityLevel")) {
auto logLevelValue = options.Get("logSeverityLevel");
ORT_NAPI_THROW_TYPEERROR_IF(!logLevelValue.IsNumber(), options.Env(),
"Invalid argument: runOptions.logSeverityLevel must be a number.");
double logLevelNumber = logLevelValue.As<Napi::Number>().DoubleValue();
ORT_NAPI_THROW_RANGEERROR_IF(
std::floor(logLevelNumber) != logLevelNumber || logLevelNumber < 0 || logLevelNumber > 4, options.Env(),
"Invalid argument: runOptions.logSeverityLevel must be one of the following: 0, 1, 2, 3, 4.");
runOptions.SetRunLogSeverityLevel(static_cast<int>(logLevelNumber));
}
// Tag
if (options.Has("tag")) {
auto tagValue = options.Get("tag");
ORT_NAPI_THROW_TYPEERROR_IF(!tagValue.IsString(), options.Env(),
"Invalid argument: runOptions.tag must be a string.");
runOptions.SetRunTag(tagValue.As<Napi::String>().Utf8Value().c_str());
}
}