Skip to content

Commit 9c014f0

Browse files
committed
test
1 parent 51b3686 commit 9c014f0

File tree

6 files changed

+41
-23
lines changed

6 files changed

+41
-23
lines changed

.github/workflows/android-perf.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ jobs:
367367
PYTHON_EXECUTABLE=python bash .ci/scripts/build-qnn-sdk.sh
368368
369369
mkdir -p aar-out
370-
PYTHON_EXECUTABLE=python ANDROID_ABIS="arm64-v8a" BUILD_AAR_DIR=aar-out EXECUTORCH_BUILD_QNN=ON QNN_SDK_ROOT=/tmp/qnn/2.28.0.241029 bash scripts/build_android_library.sh
370+
PYTHON_EXECUTABLE=python ANDROID_ABIS="arm64-v8a" BUILD_AAR_DIR=aar-out EXECUTORCH_BUILD_QNN=ON QNN_SDK_ROOT=/tmp/qnn/2.28.0.241029 EXECUTORCH_ANDROID_PROFILING=ON bash scripts/build_android_library.sh
371371
mkdir -p extension/benchmark/android/benchmark/app/libs
372372
cp aar-out/executorch.aar extension/benchmark/android/benchmark/app/libs
373373
pushd extension/benchmark/android/benchmark

extension/android/executorch_android/src/main/java/org/pytorch/executorch/Module.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ public String[] readLogBuffer() {
137137
return mNativePeer.readLogBuffer();
138138
}
139139

140+
public boolean etdump() {
141+
return mNativePeer.etdump();
142+
}
143+
140144
/**
141145
* Explicitly destroys the native torch::jit::Module. Calling this method is not required, as the
142146
* native object will be destroyed when this object is garbage-collected. However, the timing of

extension/android/executorch_android/src/main/java/org/pytorch/executorch/NativePeer.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,7 @@ public void resetNative() {
5858
/** Retrieve the in-memory log buffer, containing the most recent ExecuTorch log entries. */
5959
@DoNotStrip
6060
public native String[] readLogBuffer();
61+
62+
@DoNotStrip
63+
public native boolean etdump();
6164
}

extension/android/jni/jni_layer.cpp

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -370,28 +370,6 @@ class ExecuTorchJni : public facebook::jni::HybridClass<ExecuTorchJni> {
370370
auto jevalue = JEValue::newJEValueFromEValue(result.get()[i]);
371371
jresult->setElement(i, *jevalue);
372372
}
373-
#ifdef EXECUTORCH_ANDROID_PROFILING
374-
executorch::etdump::ETDumpGen* etdumpgen = (executorch::etdump::ETDumpGen*) module_->event_tracer();
375-
auto etdump_data = etdumpgen->get_etdump_data();
376-
377-
if (etdump_data.buf != nullptr && etdump_data.size > 0) {
378-
int etdump_file = open("/data/local/tmp/result.etdump", O_WRONLY | O_CREAT, 0644);
379-
if (etdump_file == -1) {
380-
ET_LOG(Error, "Cannot create result.etdump error: %d", errno);
381-
}
382-
ssize_t bytes_written = write(etdump_file, (uint8_t*)etdump_data.buf, etdump_data.size);
383-
if (bytes_written == -1) {
384-
ET_LOG(Error, "Cannot write result.etdump error: %d", errno);
385-
} else {
386-
ET_LOG(Info, "ETDump written %d bytes to file.", bytes_written);
387-
}
388-
close(etdump_file);
389-
free(etdump_data.buf);
390-
} else {
391-
ET_LOG(Error, "No ETDump data available!");
392-
}
393-
#endif
394-
395373
return jresult;
396374
}
397375

@@ -425,13 +403,43 @@ class ExecuTorchJni : public facebook::jni::HybridClass<ExecuTorchJni> {
425403
#endif
426404
}
427405

406+
jboolean etdump() {
407+
#ifdef EXECUTORCH_ANDROID_PROFILING
408+
executorch::etdump::ETDumpGen* etdumpgen = (executorch::etdump::ETDumpGen*) module_->event_tracer();
409+
auto etdump_data = etdumpgen->get_etdump_data();
410+
411+
if (etdump_data.buf != nullptr && etdump_data.size > 0) {
412+
int etdump_file = open("/data/local/tmp/result.etdump", O_WRONLY | O_CREAT, 0644);
413+
if (etdump_file == -1) {
414+
ET_LOG(Error, "Cannot create result.etdump error: %d", errno);
415+
return false;
416+
}
417+
ssize_t bytes_written = write(etdump_file, (uint8_t*)etdump_data.buf, etdump_data.size);
418+
if (bytes_written == -1) {
419+
ET_LOG(Error, "Cannot write result.etdump error: %d", errno);
420+
return false;
421+
} else {
422+
ET_LOG(Info, "ETDump written %d bytes to file.", bytes_written);
423+
}
424+
close(etdump_file);
425+
free(etdump_data.buf);
426+
return true;
427+
} else {
428+
ET_LOG(Error, "No ETDump data available!");
429+
}
430+
#endif
431+
return false;
432+
433+
}
434+
428435
static void registerNatives() {
429436
registerHybrid({
430437
makeNativeMethod("initHybrid", ExecuTorchJni::initHybrid),
431438
makeNativeMethod("forward", ExecuTorchJni::forward),
432439
makeNativeMethod("execute", ExecuTorchJni::execute),
433440
makeNativeMethod("loadMethod", ExecuTorchJni::load_method),
434441
makeNativeMethod("readLogBuffer", ExecuTorchJni::readLogBuffer),
442+
makeNativeMethod("etdump", ExecuTorchJni::etdump),
435443
});
436444
}
437445
};

extension/benchmark/android/benchmark/android-llm-device-farm-test-spec.yml.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ phases:
107107

108108
- echo "Run benchmark"
109109
- |
110+
adb -s $DEVICEFARM_DEVICE_UDID shell touch /data/local/tmp/result.etdump
110111
adb -s $DEVICEFARM_DEVICE_UDID shell am force-stop org.pytorch.minibench
111112

112113
adb -s $DEVICEFARM_DEVICE_UDID shell dumpsys deviceidle force-idle

extension/benchmark/android/benchmark/app/src/main/java/org/pytorch/minibench/ModelRunner.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ public void runBenchmark(
4141
latency.add(forwardMs);
4242
}
4343

44+
module.etdump();
45+
4446
final BenchmarkMetric.BenchmarkModel benchmarkModel =
4547
BenchmarkMetric.extractBackendAndQuantization(model.getName().replace(".pte", ""));
4648
// The list of metrics we have atm includes:

0 commit comments

Comments
 (0)