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
35 changes: 33 additions & 2 deletions backends/arm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,36 @@ if(EXECUTORCH_BUILD_VGF)
set(LIBVGF_PATH "${_vgf_site_pure}")
endif()

if(EXECUTORCH_BUILD_TESTS)
add_executable(
vgf_neural_statistics_test
${EXECUTORCH_ROOT}/backends/arm/test/vgf_neural_statistics_test.cpp
${EXECUTORCH_ROOT}/backends/arm/runtime/VGFNeuralStatistics.cpp
)
target_include_directories(
vgf_neural_statistics_test
PRIVATE ${_common_include_directories} ${VULKAN_HEADERS_PATH}
${VOLK_HEADERS_PATH}
)
target_compile_options(
vgf_neural_statistics_test PRIVATE -DUSE_VULKAN_WRAPPER
-DUSE_VULKAN_VOLK
)
target_link_libraries(vgf_neural_statistics_test PRIVATE executorch_core)
if(TARGET GTest::gtest_main)
target_link_libraries(
vgf_neural_statistics_test PRIVATE GTest::gtest_main
)
else()
target_link_libraries(
vgf_neural_statistics_test PRIVATE gtest gtest_main
)
endif()
add_test(NAME vgf_neural_statistics_test
COMMAND vgf_neural_statistics_test
)
endif()

set(LIBVGF_STATIC "${LIBVGF_PATH}/lib/libvgf.a")
endif()

Expand All @@ -194,8 +224,9 @@ if(EXECUTORCH_BUILD_VGF)
target_include_directories(vgf INTERFACE "${LIBVGF_INCLUDE}")

# Add backend delegate for VGF
set(_vgf_backend_sources backends/arm/runtime/VGFBackend.cpp
backends/arm/runtime/VGFSetup.cpp
set(_vgf_backend_sources
backends/arm/runtime/VGFBackend.cpp backends/arm/runtime/VGFSetup.cpp
backends/arm/runtime/VGFNeuralStatistics.cpp
)
if(NOT EXECUTORCH_BUILD_VULKAN)
list(APPEND _vgf_backend_sources backends/vulkan/third-party/volk/volk.c)
Expand Down
36 changes: 36 additions & 0 deletions backends/arm/runtime/VGFBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
*/

#include <cinttypes>
#include <cstdlib>
#include <cstring>
#include <list>
#include <numeric>
#include <string>

using namespace std;

Expand Down Expand Up @@ -101,6 +104,17 @@ void vkml_free_basics(
// vkDestroyInstance(*instance, nullptr);
}

bool vgf_neural_statistics_profiling_enabled() {
const char* value = std::getenv("EXECUTORCH_VGF_ENABLE_NEURAL_STATISTICS");
if (value == nullptr || value[0] == '\0') {
return false;
}

return std::strcmp(value, "0") != 0 && std::strcmp(value, "false") != 0 &&
std::strcmp(value, "FALSE") != 0 && std::strcmp(value, "off") != 0 &&
std::strcmp(value, "OFF") != 0;
}

class VGFBackend final : public ::executorch::runtime::BackendInterface {
public:
VGFBackend() = default;
Expand Down Expand Up @@ -365,6 +379,28 @@ class VGFBackend final : public ::executorch::runtime::BackendInterface {
#ifdef ET_EVENT_TRACER_ENABLED
event_tracer_end_profiling_delegate(event_tracer, dispatch_event);

if (event_tracer != nullptr && vgf_neural_statistics_profiling_enabled()) {
// We attach the neural statistics JSON blob to ETDump as delegate
// metadata, when event tracer is active.

// This is “synthetic” event, which we use as a carrier for metadata
EventTracerEntry neural_statistics_event =
event_tracer_start_profiling_delegate(
event_tracer,
kVgfNeuralStatisticsDelegateEventName,
/*delegate_debug_id=*/-1);

// Ask VGF representation for neural accelerator diagnostics
std::string neural_statistics_metadata =
repr->collect_neural_statistics_metadata();

event_tracer_end_profiling_delegate(
event_tracer,
neural_statistics_event,
neural_statistics_metadata.data(),
neural_statistics_metadata.size());
}

EventTracerEntry copy_outputs_event = event_tracer_start_profiling_delegate(
event_tracer,
"VGF_COPY_OUTPUTS",
Expand Down
Loading
Loading