mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-05-14 20:48:00 +00:00
Support wide char paths in CreateModel (#3835)
* Support wide char paths in CreateModel * Use UTF-8 in WinML adapter API
This commit is contained in:
parent
3bafc096bb
commit
43b87de7d1
4 changed files with 14 additions and 3 deletions
|
|
@ -14,8 +14,10 @@
|
|||
|
||||
#include <io.h>
|
||||
#include <fcntl.h>
|
||||
#include <winrt/base.h>
|
||||
#include "google/protobuf/io/zero_copy_stream_impl.h"
|
||||
#include "core/framework/onnxruntime_typeinfo.h"
|
||||
#include "StringHelpers.h"
|
||||
|
||||
namespace winmla = Windows::AI::MachineLearning::Adapter;
|
||||
|
||||
|
|
@ -118,10 +120,11 @@ OrtModel::OrtModel(std::unique_ptr<onnx::ModelProto> model_proto) : model_proto_
|
|||
// factory methods for creating an ort model from a path
|
||||
static OrtStatus* CreateModelProto(const char* path, std::unique_ptr<onnx::ModelProto>& out) {
|
||||
int file_descriptor;
|
||||
auto wide_path = _winml::Strings::HStringFromUTF8(path);
|
||||
_set_errno(0); // clear errno
|
||||
_sopen_s(
|
||||
_wsopen_s(
|
||||
&file_descriptor,
|
||||
path,
|
||||
wide_path.c_str(),
|
||||
O_RDONLY | _O_SEQUENTIAL | _O_BINARY,
|
||||
_SH_DENYWR,
|
||||
_S_IREAD | _S_IWRITE);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#include "testPch.h"
|
||||
|
|
@ -26,6 +26,11 @@ static void CreateModelFromFilePath() {
|
|||
WINML_EXPECT_NO_THROW(APITest::LoadModel(L"squeezenet_modifiedforruntimestests.onnx", learningModel));
|
||||
}
|
||||
|
||||
static void CreateModelFromUnicodeFilePath() {
|
||||
LearningModel learningModel = nullptr;
|
||||
WINML_EXPECT_NO_THROW(APITest::LoadModel(L"UnicodePath\\こんにちは maçã\\foo.onnx", learningModel));
|
||||
}
|
||||
|
||||
static void CreateModelFileNotFound() {
|
||||
LearningModel learningModel = nullptr;
|
||||
|
||||
|
|
@ -274,6 +279,7 @@ const LearningModelApiTestsApi& getapi() {
|
|||
LearningModelAPITestsClassSetup,
|
||||
LearningModelAPITestsGpuMethodSetup,
|
||||
CreateModelFromFilePath,
|
||||
CreateModelFromUnicodeFilePath,
|
||||
CreateModelFileNotFound,
|
||||
CreateModelFromIStorage,
|
||||
CreateModelFromIStorageOutsideCwd,
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ struct LearningModelApiTestsApi
|
|||
SetupClass LearningModelAPITestsClassSetup;
|
||||
SetupTest LearningModelAPITestsGpuMethodSetup;
|
||||
VoidTest CreateModelFromFilePath;
|
||||
VoidTest CreateModelFromUnicodeFilePath;
|
||||
VoidTest CreateModelFileNotFound;
|
||||
VoidTest CreateModelFromIStorage;
|
||||
VoidTest CreateModelFromIStorageOutsideCwd;
|
||||
|
|
@ -29,6 +30,7 @@ WINML_TEST_CLASS_BEGIN(LearningModelAPITests)
|
|||
WINML_TEST_CLASS_SETUP_CLASS(LearningModelAPITestsClassSetup)
|
||||
WINML_TEST_CLASS_BEGIN_TESTS
|
||||
WINML_TEST(LearningModelAPITests, CreateModelFromFilePath)
|
||||
WINML_TEST(LearningModelAPITests, CreateModelFromUnicodeFilePath)
|
||||
WINML_TEST(LearningModelAPITests, CreateModelFileNotFound)
|
||||
WINML_TEST(LearningModelAPITests, CreateModelFromIStorage)
|
||||
WINML_TEST(LearningModelAPITests, CreateModelFromIStorageOutsideCwd)
|
||||
|
|
|
|||
BIN
winml/test/collateral/models/UnicodePath/こんにちは maçã/foo.onnx
Normal file
BIN
winml/test/collateral/models/UnicodePath/こんにちは maçã/foo.onnx
Normal file
Binary file not shown.
Loading…
Reference in a new issue