Skip to content

Commit

Permalink
[JSEP] allow JsCustomAllocator to deal with zero sized input (microso…
Browse files Browse the repository at this point in the history
…ft#17660)

### Description
allow JsCustomAllocator to deal with zero sized input.

This is a standalone fix for zero-sized tensor handling for
JsCustomAllocator. There are other components in JSEP not supporting
zero-sized tensors need to be fixed.
  • Loading branch information
fs-eire authored Sep 25, 2023
1 parent 905faea commit fcfc239
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions onnxruntime/core/providers/js/allocator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,21 @@ namespace onnxruntime {
namespace js {

void* JsCustomAllocator::Alloc(size_t size) {
if (size == 0) {
return nullptr;
}

void* p = EM_ASM_PTR({ return Module.jsepAlloc($0); }, size);
stats_.num_allocs++;
stats_.bytes_in_use += size;
return p;
}

void JsCustomAllocator::Free(void* p) {
size_t size = (size_t)(void*)EM_ASM_PTR({ return Module.jsepFree($0); }, p);
stats_.bytes_in_use -= size;
if (p != nullptr) {
size_t size = (size_t)(void*)EM_ASM_PTR({ return Module.jsepFree($0); }, p);
stats_.bytes_in_use -= size;
}
}

void JsCustomAllocator::GetStats(AllocatorStats* stats) {
Expand Down

0 comments on commit fcfc239

Please sign in to comment.