Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backends/mediatek/runtime/NeuronBufferAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ BufferAllocator& BufferAllocator::GetInstance() {
return instance;
};

void* BufferAllocator::Allocate(size_t size) {
void* BufferAllocator::Allocate(size_t size, bool is_cached) {
std::scoped_lock Guard(mMutex);
return allocate_func(allocatorHandle, size);
}
Expand Down
2 changes: 1 addition & 1 deletion backends/mediatek/runtime/include/NeuronBackend.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class NeuronSharedWeights {
explicit NeuronSharedWeights(const FreeableBuffer& shared_weights_buffer) {
auto& buffer_allocator = GET_NEURON_ALLOCATOR;
nbytes_ = shared_weights_buffer.size();
data_ = buffer_allocator.Allocate(nbytes_);
data_ = buffer_allocator.Allocate(nbytes_, /* cacheable */ false);
ET_CHECK_MSG(
data_ != nullptr,
"Error: Failed to allocate memory for shared weights of size %zu",
Expand Down
14 changes: 10 additions & 4 deletions backends/mediatek/runtime/include/NeuronBufferAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ struct BufferDeleter {

class MemoryUnit {
public:
static std::unique_ptr<MemoryUnit> Create(size_t size) {
auto obj = std::unique_ptr<MemoryUnit>(new (std::nothrow) MemoryUnit(size));
static std::unique_ptr<MemoryUnit> Create(size_t size, bool is_cached = true) {
auto obj = std::unique_ptr<MemoryUnit>(
new (std::nothrow) MemoryUnit(size, is_cached));
return (obj && (obj->Allocate() == NEURON_NO_ERROR)) ? std::move(obj)
: nullptr;
}
Expand All @@ -80,7 +81,12 @@ class MemoryUnit {
}

private:
explicit MemoryUnit(size_t size) : mSize(size) {}
explicit MemoryUnit(size_t size, bool is_cached) : mSize(size) {
if (!is_cached) {
mAhwbType = AHARDWAREBUFFER_USAGE_CPU_READ_RARELY |
AHARDWAREBUFFER_USAGE_CPU_WRITE_RARELY;
}
}

int Allocate() {
AHardwareBuffer_Desc iDesc{
Expand Down Expand Up @@ -126,7 +132,7 @@ class BufferAllocator : public executorch::runtime::MemoryAllocator {
public:
static BufferAllocator& GetInstance();

void* Allocate(size_t size);
void* Allocate(size_t size, bool is_cached = true);

void* allocate(size_t size, size_t alignment = kDefaultAlignment) override {
return Allocate(size);
Expand Down
1 change: 1 addition & 0 deletions backends/mediatek/scripts/mtk_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ cmake -DCMAKE_INSTALL_PREFIX="${build_dir}" \
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
-DEXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR=ON \
-DEXECUTORCH_BUILD_EXTENSION_NAMED_DATA_MAP=ON \
-DEXECUTORCH_BUILD_NEURON_BUFFER_ALLOCATOR=OFF \
-DEXECUTORCH_BUILD_NEURON=ON \
-B"${build_dir}"

Expand Down
Loading