mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-06-06 00:03:22 +00:00
1. Add support for vstest. 2. Add support for vcpkg. To use it: ```bat vcpkg install zlib:x64-windows benchmark:x64-windows gtest:x64-windows protobuf:x64-windows pybind11:x64-windows re2:x64-windows mkdir build cmake ..\cmake -DCMAKE_BUILD_TYPE=Debug -A x64 -T host=x64 -DCMAKE_TOOLCHAIN_FILE=C:\vcpkg\scripts\buildsystems\vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows -Donnxruntime_PREFER_SYSTEM_LIB=ON ``` 3. New cmake option: onnxruntime_PREFER_SYSTEM_LIB, which allows user using the preinstall libs instead of the things in onnxruntime submodule. 4. New cmake option: onnxruntime_ENABLE_MEMLEAK_CHECKER, which allows user turn on/off the memory leak checker by @RyanUnderhill in Windows Debug Build. The checker doesn't work with vstest. 4. Fix the post merge pipeline(Mainly for test coverage report). 5. Ignore the compile warning from the Featurizer library code 6. Apply "/utf-8" VC compile flag to our code. Without this, you can't build onnxruntime on Chinese Windows. 7. Remove the SingleUnitTestProject cmake option because it's deprecated more than one year and nobody is using it. 8. Move opaque api tests to onnxruntime_test_all 9. Enable "/W4" on CUDA ep's C++ code(Not the *.cu files), and fix some warnings, add some extra checks. 10. Delete the onnxruntime::test::TestEnvironment class. 11. Add a DLLmain for onnxruntime.dll. 12. Allow dynamic link to libprotobuf
75 lines
2.5 KiB
C++
75 lines
2.5 KiB
C++
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
// Licensed under the MIT License.
|
|
|
|
#include "test/framework/TestAllocatorManager.h"
|
|
#include "core/framework/allocatormgr.h"
|
|
#ifdef USE_CUDA
|
|
#include "core/providers/cuda/cuda_allocator.h"
|
|
#endif // USE_CUDA
|
|
|
|
namespace onnxruntime {
|
|
namespace test {
|
|
|
|
static std::string GetAllocatorId(const std::string& name, const int id, const bool isArena) {
|
|
std::ostringstream ss;
|
|
if (isArena)
|
|
ss << "arena_";
|
|
else
|
|
ss << "device_";
|
|
ss << name << "_" << id;
|
|
return ss.str();
|
|
}
|
|
|
|
static Status RegisterAllocator(std::unordered_map<std::string, AllocatorPtr>& map,
|
|
std::unique_ptr<IDeviceAllocator> allocator, size_t /*memory_limit*/,
|
|
bool use_arena) {
|
|
auto& info = allocator->Info();
|
|
auto allocator_id = GetAllocatorId(info.name, info.id, use_arena);
|
|
|
|
auto status = Status::OK();
|
|
if (map.find(allocator_id) != map.end())
|
|
status = Status(common::ONNXRUNTIME, common::FAIL, "allocator already exists");
|
|
else {
|
|
if (use_arena)
|
|
map[allocator_id] = std::make_shared<DummyArena>(std::move(allocator));
|
|
else
|
|
map[allocator_id] = std::move(allocator);
|
|
}
|
|
|
|
return status;
|
|
}
|
|
|
|
AllocatorManager& AllocatorManager::Instance() {
|
|
static AllocatorManager s_instance_;
|
|
return s_instance_;
|
|
}
|
|
|
|
AllocatorManager::AllocatorManager() {
|
|
InitializeAllocators();
|
|
}
|
|
|
|
Status AllocatorManager::InitializeAllocators() {
|
|
auto cpu_alocator = onnxruntime::make_unique<CPUAllocator>();
|
|
ORT_RETURN_IF_ERROR(RegisterAllocator(map_, std::move(cpu_alocator), std::numeric_limits<size_t>::max(), true));
|
|
#ifdef USE_CUDA
|
|
auto cuda_alocator = onnxruntime::make_unique<CUDAAllocator>(static_cast<OrtDevice::DeviceId>(0), CUDA);
|
|
ORT_RETURN_IF_ERROR(RegisterAllocator(map_, std::move(cuda_alocator), std::numeric_limits<size_t>::max(), true));
|
|
|
|
auto cuda_pinned_alocator = onnxruntime::make_unique<CUDAPinnedAllocator>(static_cast<OrtDevice::DeviceId>(0), CUDA_PINNED);
|
|
ORT_RETURN_IF_ERROR(RegisterAllocator(map_, std::move(cuda_pinned_alocator), std::numeric_limits<size_t>::max(), true));
|
|
#endif // USE_CUDA
|
|
|
|
return Status::OK();
|
|
}
|
|
|
|
AllocatorManager::~AllocatorManager() {
|
|
}
|
|
|
|
AllocatorPtr AllocatorManager::GetAllocator(const std::string& name, const int id, bool arena) {
|
|
auto allocator_id = GetAllocatorId(name, id, arena);
|
|
auto entry = map_.find(allocator_id);
|
|
ORT_ENFORCE(entry != map_.end(), "Allocator not found:", allocator_id);
|
|
return entry->second;
|
|
}
|
|
} // namespace test
|
|
} // namespace onnxruntime
|