Open egormcobakaster opened 2 months ago
You will get different execution times on the same OS based on which CPU cores the program is running on. The RK3588 has 4 fast Cortex-A76 cores at 2.4Ghz and 4 efficient Cortex-A55 cores at 1.8Ghz, so depending on how the OS has scheduled the execution of your program this will effect your inference timing.
To avoid this variation you need to set the CPU affinity of the program to run on the fast A76 cores only, eg:
#define _GNU_SOURCE
#include <stdio.h>
#include <sched.h>
#include <unistd.h>
#include <pthread.h>
int main() {
cpu_set_t cpuset;
pid_t pid;
// Initialize the CPU set to zero
CPU_ZERO(&cpuset);
// Add the A76 cores (typically core 4, 5, 6, 7) to the CPU set
CPU_SET(4, &cpuset); // Add core 4
CPU_SET(5, &cpuset); // Add core 5
CPU_SET(6, &cpuset); // Add core 6
CPU_SET(7, &cpuset); // Add core 7
// Get the process ID (0 means the calling process)
pid = getpid();
// Set the CPU affinity for the process
if (sched_setaffinity(pid, sizeof(cpu_set_t), &cpuset) == -1) {
perror("sched_setaffinity");
return -1;
}
// Print confirmation
printf("CPU affinity set to A76 cores only (4, 5, 6, 7)\n");
// Your program logic here...
return 0;
}
Have you set the CPU/NPU/DDR frequency? This script helps to do this https://github.com/airockchip/rknn_model_zoo/blob/main/scaling_frequency.sh
I slightly modified the code in examples/resnet/cpp/main to measure execution time. measurements showed different results on linux and android, with the first run out of 100 showing approximately the same time on android and linux.
linux output: Inference - First run: 25.00 ms, Last run: 21.00 ms, Average: 21.88 ms [155] score=0.879479 class=n02086240 Shih-Tzu [154] score=0.113574 class=n02086079 Pekinese, Pekingese, Peke [204] score=0.002490 class=n02098413 Lhasa, Lhasa apso [262] score=0.001698 class=n02112706 Brabancon griffon [254] score=0.000742 class=n02110958 pug, pug-dog
android output: Inference - First run: 22.00 ms, Last run: 37.00 ms, Average: 32.86 ms [155] score=0.879479 class=n02086240 Shih-Tzu [154] score=0.113574 class=n02086079 Pekinese, Pekingese, Peke [204] score=0.002490 class=n02098413 Lhasa, Lhasa apso [262] score=0.001698 class=n02112706 Brabancon griffon [254] score=0.000742 class=n02110958 pug, pug-dog