Skip to content

Commit

Permalink
Move ShouldCpuAllocatorUseArena to allocator_utils.h/cc.
Browse files Browse the repository at this point in the history
  • Loading branch information
edgchen1 committed Oct 16, 2024
1 parent 09d3aa6 commit 13c77d7
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 42 deletions.
19 changes: 19 additions & 0 deletions onnxruntime/core/framework/allocator_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <sstream>
#include <unordered_map>

#include <absl/base/config.h>

Check warning on line 11 in onnxruntime/core/framework/allocator_utils.cc

View workflow job for this annotation

GitHub Actions / Optional Lint C++

[cpplint] reported by reviewdog 🐶 Found C system header after C++ system header. Should be: allocator_utils.h, c system, c++ system, other. [build/include_order] [4] Raw Output: onnxruntime/core/framework/allocator_utils.cc:11: Found C system header after C++ system header. Should be: allocator_utils.h, c system, c++ system, other. [build/include_order] [4]

#include "core/common/logging/logging.h"
#include "core/common/narrow.h"
#include "core/framework/bfc_arena.h"
Expand Down Expand Up @@ -75,4 +77,21 @@ AllocatorPtr CreateAllocator(const AllocatorCreationInfo& info) {
}
}

bool ShouldCpuAllocatorUseArena([[maybe_unused]] bool is_arena_requested) {

Check warning

Code scanning / PREfast

You can attempt to make 'onnxruntime::ShouldCpuAllocatorUseArena' constexpr unless it contains any undefined behavior (f.4). Warning

You can attempt to make 'onnxruntime::ShouldCpuAllocatorUseArena' constexpr unless it contains any undefined behavior (f.4).
#if defined(USE_JEMALLOC) || defined(USE_MIMALLOC)
// We use these allocators instead of the arena.
return false;
#elif defined(ABSL_HAVE_ADDRESS_SANITIZER)
// Using the arena may hide memory issues. Disable it in an ASan build.
return false;
#else
// Disable the arena for 32-bit builds because it may run into an infinite loop on integer overflow.
if constexpr (sizeof(void*) == 4) {
return false;
} else {
return is_arena_requested;
}
#endif
}

} // namespace onnxruntime
5 changes: 5 additions & 0 deletions onnxruntime/core/framework/allocator_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,9 @@ struct AllocatorCreationInfo {
// Valid values can be found in onnxruntime_c_api.h.
AllocatorPtr CreateAllocator(const AllocatorCreationInfo& info);

/**
* Gets whether a CPU allocator should use an arena or not.
*/
bool ShouldCpuAllocatorUseArena(bool is_arena_requested);

} // namespace onnxruntime
27 changes: 0 additions & 27 deletions onnxruntime/core/framework/cpu_allocator_utils.cc

This file was deleted.

13 changes: 0 additions & 13 deletions onnxruntime/core/framework/cpu_allocator_utils.h

This file was deleted.

2 changes: 1 addition & 1 deletion onnxruntime/core/providers/cpu/cpu_execution_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "core/providers/cpu/cpu_execution_provider.h"

#include "core/framework/cpu_allocator_utils.h"
#include "core/framework/allocator_utils.h"
#include "core/framework/op_kernel.h"
#include "core/framework/kernel_registry.h"
#include "core/framework/int4.h"
Expand Down
1 change: 0 additions & 1 deletion onnxruntime/core/session/environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "core/session/environment.h"
#include "core/session/allocator_adapters.h"
#include "core/framework/allocator_utils.h"
#include "core/framework/cpu_allocator_utils.h"
#include "core/graph/constants.h"
#include "core/graph/op.h"

Expand Down

0 comments on commit 13c77d7

Please sign in to comment.