From ab2e3b16f666577395d2a75dd8edbf92715ed21c Mon Sep 17 00:00:00 2001 From: Satya Jandhyala Date: Thu, 18 Jul 2024 13:47:24 -0700 Subject: [PATCH] Miscellaneous edits. --- js/web/lib/wasm/jsep/init.ts | 2 +- onnxruntime/core/framework/tensorprotoutils.cc | 8 ++++---- onnxruntime/core/graph/model.cc | 9 +++++---- onnxruntime/core/providers/js/js_kernel.h | 2 +- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/js/web/lib/wasm/jsep/init.ts b/js/web/lib/wasm/jsep/init.ts index d237bb850c054..11fa9dd62b8ec 100644 --- a/js/web/lib/wasm/jsep/init.ts +++ b/js/web/lib/wasm/jsep/init.ts @@ -217,7 +217,7 @@ export const init = await backend.download( Number(gpuDataId), - () => module.HEAPU8.subarray(Number(dataOffset) >>> 0, Number(dataOffset + size) >>> 0)); + () => module.HEAPU8.subarray(Number(dataOffset) >>> 0, Number(dataOffset) >>> 0 + Number(size))); }, // jsepCreateKernel diff --git a/onnxruntime/core/framework/tensorprotoutils.cc b/onnxruntime/core/framework/tensorprotoutils.cc index 6777e3948bf7f..7d8bfede96ba8 100644 --- a/onnxruntime/core/framework/tensorprotoutils.cc +++ b/onnxruntime/core/framework/tensorprotoutils.cc @@ -947,9 +947,9 @@ Status GetExtDataFromTensorProto(const Env& env, const std::filesystem::path& mo if (!fileData) { return 2; // File not found in preloaded files. } - const offset = $1 >>> 0; - const length = $2 >>> 0; - const buffer = $3 >>> 0; + const offset = Number($1 >>> 0); + const length = Number($2 >>> 0); + const buffer = Number($3 >>> 0); if (offset + length > fileData.byteLength) { return 3; // Out of bounds. @@ -958,7 +958,7 @@ Status GetExtDataFromTensorProto(const Env& env, const std::filesystem::path& mo try { // Copy the file data (fileData,offset,length) into WebAssembly memory // (HEAPU8,buffer,length). - HEAPU8.set(fileData.subarray(Number(offset), Number(offset) + length), buffer); + HEAPU8.set(fileData.subarray(offset, offset + length), buffer); return 0; } catch { return 4; diff --git a/onnxruntime/core/graph/model.cc b/onnxruntime/core/graph/model.cc index b90ac73ef1e34..280c9f77dea79 100644 --- a/onnxruntime/core/graph/model.cc +++ b/onnxruntime/core/graph/model.cc @@ -552,12 +552,13 @@ static Status SaveModel(Model& model, const T& file_path) { model_proto.SerializeToArray(buffer, buffer_size); EM_ASM(({ - const buffer = $0; - const buffer_size = $1; + const buffer = Number($0); + const buffer_size = Number($1); const file_path = UTF8ToString($2); const bytes = new Uint8Array(buffer_size); - bytes.set(HEAPU8.subarray(Number(buffer), Number(buffer) + buffer_size)); - if (typeof process == 'object' && typeof process.versions == 'object' && typeof process.versions.node == 'string') { + bytes.set(HEAPU8.subarray(buffer, buffer + buffer_size)); + if (typeof process == 'object' && typeof process.versions == 'object' && + typeof process.versions.node == 'string') { // Node.js require('fs').writeFileSync(file_path, bytes); } else { diff --git a/onnxruntime/core/providers/js/js_kernel.h b/onnxruntime/core/providers/js/js_kernel.h index aeaf40f957c70..25809811acd0c 100644 --- a/onnxruntime/core/providers/js/js_kernel.h +++ b/onnxruntime/core/providers/js/js_kernel.h @@ -200,7 +200,7 @@ class JsKernel : public OpKernel { return status; } - intptr_t status_code = EM_ASM_INT( + int status_code = EM_ASM_INT( { return Module.jsepRunKernel($0, $1, Module.jsepSessionState.sessionHandle, Module.jsepSessionState.errors); }, this, reinterpret_cast(p_serialized_kernel_context));