Thanks to visit codestin.com
Credit goes to github.com

Skip to content

New onnx custom allocator API#827

Merged
alonre24 merged 39 commits into
masterfrom
onnx_custom_allocator
Oct 13, 2021
Merged

New onnx custom allocator API#827
alonre24 merged 39 commits into
masterfrom
onnx_custom_allocator

Conversation

@alonre24

@alonre24 alonre24 commented Aug 4, 2021

Copy link
Copy Markdown
Collaborator

Use the new ONNX RegisterAllocator API in 1.9.0 version so that onnx sessions will use Redis allocator (in CPU models only) for memory management.

This include a new load time configuration that sets the memory limit for ONNX (default is to have no limit)
We return an appropriate error and exit gracefully if the memory limit has exceeded.

@alonre24 alonre24 mentioned this pull request Oct 5, 2021
@alonre24 alonre24 marked this pull request as ready for review October 12, 2021 09:37
@alonre24 alonre24 requested a review from DvirDukhan October 12, 2021 09:37
…emory consumption between jemalloc and libc allocators) + remove bert model that served for benchmark only
@codecov

codecov Bot commented Oct 12, 2021

Copy link
Copy Markdown

Codecov Report

Merging #827 (4a13924) into master (de0f302) will increase coverage by 1.35%.
The diff coverage is 91.73%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #827      +/-   ##
==========================================
+ Coverage   79.97%   81.32%   +1.35%     
==========================================
  Files          53       56       +3     
  Lines        8009     8182     +173     
==========================================
+ Hits         6405     6654     +249     
+ Misses       1604     1528      -76     
Impacted Files Coverage Δ
src/serialization/AOF/rai_aof_rewrite.c 0.00% <0.00%> (ø)
.../serialization/RDB/decoder/previous/v2/decode_v2.c 46.56% <0.00%> (+9.81%) ⬆️
src/execution/parsing/deprecated.c 81.18% <66.66%> (+1.48%) ⬆️
...c/serialization/RDB/decoder/current/v4/decode_v4.c 71.42% <71.42%> (ø)
.../serialization/RDB/decoder/previous/v0/decode_v0.c 63.33% <72.72%> (+1.69%) ⬆️
tests/module/LLAPI.c 75.91% <79.06%> (+1.44%) ⬆️
src/serialization/RDB/encoder/v4/encode_v4.c 85.96% <81.81%> (ø)
src/config/config.c 62.60% <90.90%> (+2.78%) ⬆️
src/backends/tensorflow.c 72.16% <91.00%> (+3.12%) ⬆️
src/backends/onnxruntime.c 77.97% <92.22%> (+0.58%) ⬆️
... and 23 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dddc7d0...4a13924. Read the comment docs.

@DvirDukhan DvirDukhan left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very nice
few comments

Comment thread src/util/arr.h
* array_new instead */
static array_t array_new_sz(uint32_t elem_sz, uint32_t cap, uint32_t len) {
array_hdr_t *hdr = array_alloc_fn(sizeof(array_hdr_t) + cap * elem_sz);
array_hdr_t *hdr = (array_hdr_t *)array_alloc_fn(sizeof(array_hdr_t) + cap * elem_sz);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this change?

@alonre24 alonre24 Oct 13, 2021

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C++ compiler raising an error if we don't have this conversion explicitly (it is used form onnx_allocator.cpp)

Comment thread src/backends/onnx_allocator/CMakeLists.txt
OrtAllocator::Alloc = [](OrtAllocator* this_, size_t size) { return static_cast<RAIOrtAllocator*>(this_)->Alloc(size); };
OrtAllocator::Free = [](OrtAllocator* this_, void* p) { static_cast<RAIOrtAllocator*>(this_)->Free(p); };
OrtAllocator::Info = [](const OrtAllocator* this_) { return static_cast<const RAIOrtAllocator*>(this_)->Info(); };
Ort::ThrowOnError(Ort::GetApi().CreateCpuMemoryInfo(OrtDeviceAllocator, OrtMemTypeDefault, &cpu_memory_info));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this is wrapped with ThrowOnError?

@alonre24 alonre24 Oct 13, 2021

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied it from ONNX test. Even thought there is no obvious reason for CreateCpuMemoryInfo to fail, I guess that every API call should be wrapped in case that the return status is not NULL (which means invalid).

Comment thread tests/flow/tests_onnx.py
Comment thread tests/flow/tests_onnx.py
'AI.MODELEXECUTE', 'mnist_0{1}', 'INPUTS', 1, 'a{1}', 'OUTPUTS', 1, 'b{1}',
error_msg_is_substr=True)

def run_parallel_onnx_sessions(con):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can avoid running in parallel if all you need is one session

@alonre24 alonre24 Oct 13, 2021

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is here to see that our allocator is "thread-safe" (we have multiple RedisAI workers executing sessions and access the allocator).

@alonre24 alonre24 added ci-test and removed ci-test labels Oct 13, 2021
@alonre24 alonre24 merged commit cdab22e into master Oct 13, 2021
@alonre24 alonre24 deleted the onnx_custom_allocator branch October 13, 2021 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants