mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-06-22 02:30:26 +00:00
* add ortdevice class * add data transfer manager for copying tensors. * update * add data trasnfer for gpu * fix constexpr build break. * update * remove unnecessary header files. * remove unnecessary header files. * add dependency * add dependency * add dependency * add dependency * fix linux build break. * update * fix build break * fix build break * fix build break * update * update * update c api. * update to not use OrtCreateAllocatorInfo * change to all eps . * fix linux build break * remove useless codes. * update * move datatransfermanager in session state * update * fix cuda build break. * fix comments * fix windows GPU build. * fix comments * fix build break * fix comments * fix test failure * update * fix comments * fix onnx runtime server. * update * fix test failure. * fix comments * fix comment
42 lines
1.4 KiB
C++
42 lines
1.4 KiB
C++
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
// Licensed under the MIT License.
|
|
|
|
#include "test_allocator.h"
|
|
|
|
MockedOrtAllocator::MockedOrtAllocator() {
|
|
OrtAllocator::version = ORT_API_VERSION;
|
|
OrtAllocator::Alloc = [](OrtAllocator* this_, size_t size) { return static_cast<MockedOrtAllocator*>(this_)->Alloc(size); };
|
|
OrtAllocator::Free = [](OrtAllocator* this_, void* p) { static_cast<MockedOrtAllocator*>(this_)->Free(p); };
|
|
OrtAllocator::Info = [](const OrtAllocator* this_) { return static_cast<const MockedOrtAllocator*>(this_)->Info(); };
|
|
ORT_THROW_ON_ERROR(OrtCreateCpuAllocatorInfo(OrtDeviceAllocator, OrtMemTypeDefault, &cpuAllocatorInfo));
|
|
}
|
|
|
|
MockedOrtAllocator::~MockedOrtAllocator() {
|
|
OrtReleaseAllocatorInfo(cpuAllocatorInfo);
|
|
}
|
|
|
|
void* MockedOrtAllocator::Alloc(size_t size) {
|
|
constexpr size_t extra_len = sizeof(size_t);
|
|
memory_inuse.fetch_add(size += extra_len);
|
|
void* p = ::malloc(size);
|
|
*(size_t*)p = size;
|
|
return (char*)p + extra_len;
|
|
}
|
|
|
|
void MockedOrtAllocator::Free(void* p) {
|
|
constexpr size_t extra_len = sizeof(size_t);
|
|
if (!p) return;
|
|
p = (char*)p - extra_len;
|
|
size_t len = *(size_t*)p;
|
|
memory_inuse.fetch_sub(len);
|
|
return ::free(p);
|
|
}
|
|
|
|
const OrtAllocatorInfo* MockedOrtAllocator::Info() const {
|
|
return cpuAllocatorInfo;
|
|
}
|
|
|
|
void MockedOrtAllocator::LeakCheck() {
|
|
if (memory_inuse.load())
|
|
throw std::runtime_error("memory leak!!!");
|
|
}
|