Skip to content

Commit

Permalink
1.19.0, no static msvc
Browse files Browse the repository at this point in the history
  • Loading branch information
decahedron1 committed Aug 12, 2024
1 parent 5edf5ad commit 59a6e9b
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 23 deletions.
13 changes: 10 additions & 3 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ await new Command()

const onnxruntimeRoot = join(root, 'onnxruntime');
if (!await exists(onnxruntimeRoot)) {
await $`git clone https://github.com/microsoft/onnxruntime --recursive --single-branch --depth 1 --branch v${options.upstreamVersion}`;
await $`git clone https://github.com/microsoft/onnxruntime --recursive --single-branch --depth 1 --branch rel-1.19.0`;
}

$.cd(onnxruntimeRoot);
Expand Down
22 changes: 12 additions & 10 deletions src/patches/wasm/0007-disable-external-initializers.patch
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ index 8a2db6d..c0b6475 100644
}

-#if !defined(__wasm__)
static Status GetFileContent(
const Env& env, const ORTCHAR_T* file_path, FileOffsetType offset, size_t length,
void*& raw_buffer, OrtCallback& deleter) {
static Status GetFileContent(const Env& env, const std::filesystem::path& file_path, FileOffsetType offset,
size_t length, void*& raw_buffer, OrtCallback& deleter) {
// query length if it is 0
@@ -825,69 +825,7 @@ Status GetExtDataFromTensorProto(const Env& env, const ORTCHAR_T* model_path,
ext_data_len = raw_data_safe_len;
ext_data_deleter = OrtCallback{nullptr, nullptr};
} else {
-#if defined(__wasm__)
- ORT_RETURN_IF(file_offset < 0 || file_offset + raw_data_safe_len >= 4294967296,
- "External initializer: ", tensor_proto.name(),
- " offset: ", file_offset, " size to read: ", static_cast<size_t>(raw_data_safe_len),
- "External initializer: ", tensor_proto.name(), " offset: ", file_offset,
- " size to read: ", static_cast<size_t>(raw_data_safe_len),
- " are out of bounds or can not be read in full (>4GB).");
-
- auto buffer = std::make_unique<char[]>(raw_data_safe_len);
Expand Down Expand Up @@ -58,7 +58,8 @@ index 8a2db6d..c0b6475 100644
- }
-
- try {
- // Copy the file data (fileData,offset,length) into WebAssembly memory (HEAPU8,buffer,length).
- // Copy the file data (fileData,offset,length) into WebAssembly memory
- // (HEAPU8,buffer,length).
- HEAPU8.set(fileData.subarray(offset, offset + length), buffer);
- return 0;
- } catch {
Expand All @@ -85,12 +86,13 @@ index 8a2db6d..c0b6475 100644
- default:
- err_msg = "Unknown error occurred in memory copy.";
- }
- return ORT_MAKE_STATUS(ONNXRUNTIME, FAIL, "Failed to load external data file \"", external_data_file_path, "\", error: ", err_msg);
- return ORT_MAKE_STATUS(ONNXRUNTIME, FAIL, "Failed to load external data file \"", external_data_file_path,
- "\", error: ", err_msg);
-#else
+#if !defined(__wasm__)
size_t file_length;
// error reporting is inconsistent across platforms. Make sure the full path we attempted to open is included.
auto status = env.GetFileLength(external_data_file_path.c_str(), file_length);
// The GetFileContent function doesn't report error if the requested data range is invalid. Therefore we need to
// manually check file size first.
std::uintmax_t file_length = std::filesystem::file_size(external_data_file_path);
@@ -905,6 +843,8 @@ Status GetExtDataFromTensorProto(const Env& env, const ORTCHAR_T* model_path,
ORT_RETURN_IF_ERROR(GetFileContent(env, external_data_file_path.c_str(), file_offset, raw_data_safe_len,
ext_data_buf, ext_data_deleter));
Expand Down
14 changes: 8 additions & 6 deletions src/patches/wasm/0008-disable-file-system.patch
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ index b3935e6..b0d1077 100644
- const file_path = UTF8ToString($2);
- const bytes = new Uint8Array(buffer_size);
- bytes.set(HEAPU8.subarray(buffer, buffer + buffer_size));
- if (typeof process == 'object' && typeof process.versions == 'object' && typeof process.versions.node == 'string') {
- if (typeof process == 'object' && typeof process.versions == 'object' &&
- typeof process.versions.node == 'string') {
- // Node.js
- require('fs').writeFileSync(file_path, bytes);
- } else {
Expand Down Expand Up @@ -82,8 +83,9 @@ index b3935e6..b0d1077 100644

Status Model::SaveWithExternalInitializers(Model& model,
@@ -762,6 +742,7 @@ Status Model::SaveWithExternalInitializers(Model& model,
const PathString& file_path,
const std::string& external_file_name,
int fd,
const std::filesystem::path& file_path,
const std::filesystem::path& external_file_name,
size_t initializer_size_threshold) {
+#if !defined(__wasm__)
if (fd < 0) {
Expand Down Expand Up @@ -365,11 +367,11 @@ index c1cd215..d2e440a 100644
@@ -829,6 +829,7 @@ common::Status InferenceSession::RegisterGraphTransformer(
}

common::Status InferenceSession::SaveToOrtFormat(const PathString& filepath) const {
common::Status InferenceSession::SaveToOrtFormat(const std::filesystem::path& filepath) const {
+#if !defined(__wasm__)
ORT_RETURN_IF_NOT(FLATBUFFERS_LITTLEENDIAN, "ort format only supports little-endian machines");

// Get the byte size of the ModelProto and round it to the next MB and use it as flatbuffers' init_size
// TODO: Investigate whether we should set a max size, and clarify the cost of having a buffer smaller than
// what the total flatbuffers serialized size will be.
@@ -872,6 +873,9 @@ common::Status InferenceSession::SaveToOrtFormat(const PathString& filepath) con
}

Expand Down
6 changes: 3 additions & 3 deletions src/static-build/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
cmake_minimum_required(VERSION 3.26)
project(onnxruntime_static_lib)

set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded)
set(ONNX_USE_MSVC_STATIC_RUNTIME ON)
set(protobuf_MSVC_STATIC_RUNTIME ON)
# set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded)
# set(ONNX_USE_MSVC_STATIC_RUNTIME ON)
# set(protobuf_MSVC_STATIC_RUNTIME ON)
set(onnxruntime_BUILD_SHARED_LIB ON)

add_definitions(-D_SILENCE_ALL_CXX23_DEPRECATION_WARNINGS)
Expand Down

0 comments on commit 59a6e9b

Please sign in to comment.