onnxruntime/js/node/src/tensor_helper.h
Yulong Wang bd5dbf86fe
support WebGPU EP in Node.js binding (#22660)
### Description

This change enhances the Node.js binding with the following features:
- support WebGPU EP
- lazy initialization of `OrtEnv`
- being able to initialize ORT with default log level setting from
`ort.env.logLevel`.
- session options:
  - `enableProfiling` and `profileFilePrefix`: support profiling.
  - `externalData`: explicit external data (optional in Node.js binding)
- `optimizedModelFilePath`: allow dumping optimized model for diagnosis
purpose
  - `preferredOutputLocation`: support IO binding.

======================================================
`Tensor.download()` is not implemented in this PR.
Build pipeline update is not included in this PR.
2024-11-04 21:09:07 +00:00

40 lines
1.2 KiB
C++

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#pragma once
#include <napi.h>
#include <vector>
#include "onnxruntime_cxx_api.h"
// convert a Javascript OnnxValue object to an OrtValue object
Ort::Value NapiValueToOrtValue(Napi::Env env, Napi::Value value, OrtMemoryInfo* cpu_memory_info, OrtMemoryInfo* webgpu_memory_info);
// convert an OrtValue object to a Javascript OnnxValue object
Napi::Value OrtValueToNapiValue(Napi::Env env, Ort::Value&& value);
enum DataLocation {
DATA_LOCATION_NONE = 0,
DATA_LOCATION_CPU = 1,
DATA_LOCATION_CPU_PINNED = 2,
DATA_LOCATION_TEXTURE = 3,
DATA_LOCATION_GPU_BUFFER = 4,
DATA_LOCATION_ML_TENSOR = 5
};
inline DataLocation ParseDataLocation(const std::string& location) {
if (location == "cpu") {
return DATA_LOCATION_CPU;
} else if (location == "cpu-pinned") {
return DATA_LOCATION_CPU_PINNED;
} else if (location == "texture") {
return DATA_LOCATION_TEXTURE;
} else if (location == "gpu-buffer") {
return DATA_LOCATION_GPU_BUFFER;
} else if (location == "ml-tensor") {
return DATA_LOCATION_ML_TENSOR;
} else {
return DATA_LOCATION_NONE;
}
}