Skip to content

Commit c7cdd97

Browse files
committed
samples: hello_ei: Increase accuracy of timing results
- Measure time in microseconds instead of milliseconds. - Use microsecond precision measurements from EI SDK. Jira: NCSDK-36946 Signed-off-by: Bartosz Meus <bartosz.meus@nordicsemi.no>
1 parent 9ae89db commit c7cdd97

2 files changed

Lines changed: 33 additions & 33 deletions

File tree

samples/edge_impulse/hello_ei/sample.yaml

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,60 +15,60 @@ tests:
1515
- "triangle => 0\\.0\\d+"
1616
- "anomaly: (-\\d+\\.\\d+)|(0\\.0\\d+)"
1717
- "=== Inference time profiling ==="
18-
- "Full inference completed in \\d+ ms"
19-
- "Classification completed in \\d+ ms"
20-
- "DSP operations completed in \\d+ ms"
21-
- "Anomaly detection completed in \\d+ ms"
18+
- "Full inference completed in \\d+ us"
19+
- "Classification completed in \\d+ us"
20+
- "DSP operations completed in \\d+ us"
21+
- "Anomaly detection completed in \\d+ us"
2222
- "=== Inference result ==="
2323
- "idle => 0\\.0\\d+"
2424
- "sine => (1\\.0\\d+)|(0\\.9\\d+)"
2525
- "triangle => 0\\.0\\d+"
2626
- "anomaly: (-\\d+\\.\\d+)|(0\\.0\\d+)"
2727
- "=== Inference time profiling ==="
28-
- "Full inference completed in \\d+ ms"
29-
- "Classification completed in \\d+ ms"
30-
- "DSP operations completed in \\d+ ms"
31-
- "Anomaly detection completed in \\d+ ms"
28+
- "Full inference completed in \\d+ us"
29+
- "Classification completed in \\d+ us"
30+
- "DSP operations completed in \\d+ us"
31+
- "Anomaly detection completed in \\d+ us"
3232
- "=== Inference result ==="
3333
- "idle => 0\\.0\\d+"
3434
- "sine => (1\\.0\\d+)|(0\\.9\\d+)"
3535
- "triangle => 0\\.0\\d+"
3636
- "anomaly: (-\\d+\\.\\d+)|(0\\.0\\d+)"
3737
- "=== Inference time profiling ==="
38-
- "Full inference completed in \\d+ ms"
39-
- "Classification completed in \\d+ ms"
40-
- "DSP operations completed in \\d+ ms"
41-
- "Anomaly detection completed in \\d+ ms"
38+
- "Full inference completed in \\d+ us"
39+
- "Classification completed in \\d+ us"
40+
- "DSP operations completed in \\d+ us"
41+
- "Anomaly detection completed in \\d+ us"
4242
- "=== Inference result ==="
4343
- "idle => 0\\.0\\d+"
4444
- "sine => 0\\.0\\d+"
4545
- "triangle => (1\\.0\\d+)|(0\\.9\\d+)"
4646
- "anomaly: (-\\d+\\.\\d+)|(0\\.0\\d+)"
4747
- "=== Inference time profiling ==="
48-
- "Full inference completed in \\d+ ms"
49-
- "Classification completed in \\d+ ms"
50-
- "DSP operations completed in \\d+ ms"
51-
- "Anomaly detection completed in \\d+ ms"
48+
- "Full inference completed in \\d+ us"
49+
- "Classification completed in \\d+ us"
50+
- "DSP operations completed in \\d+ us"
51+
- "Anomaly detection completed in \\d+ us"
5252
- "=== Inference result ==="
5353
- "idle => 0\\.0\\d+"
5454
- "sine => 0\\.0\\d+"
5555
- "triangle => (1\\.0\\d+)|(0\\.9\\d+)"
5656
- "anomaly: (-\\d+\\.\\d+)|(0\\.0\\d+)"
5757
- "=== Inference time profiling ==="
58-
- "Full inference completed in \\d+ ms"
59-
- "Classification completed in \\d+ ms"
60-
- "DSP operations completed in \\d+ ms"
61-
- "Anomaly detection completed in \\d+ ms"
58+
- "Full inference completed in \\d+ us"
59+
- "Classification completed in \\d+ us"
60+
- "DSP operations completed in \\d+ us"
61+
- "Anomaly detection completed in \\d+ us"
6262
- "=== Inference result ==="
6363
- "idle => 0\\.0\\d+"
6464
- "sine => 0\\.0\\d+"
6565
- "triangle => (1\\.0\\d+)|(0\\.9\\d+)"
6666
- "anomaly: (-\\d+\\.\\d+)|(0\\.0\\d+)"
6767
- "=== Inference time profiling ==="
68-
- "Full inference completed in \\d+ ms"
69-
- "Classification completed in \\d+ ms"
70-
- "DSP operations completed in \\d+ ms"
71-
- "Anomaly detection completed in \\d+ ms"
68+
- "Full inference completed in \\d+ us"
69+
- "Classification completed in \\d+ us"
70+
- "DSP operations completed in \\d+ us"
71+
- "Anomaly detection completed in \\d+ us"
7272
type: multi_line
7373
platform_allow:
7474
- nrf54l15dk/nrf54l15/cpuapp

samples/edge_impulse/hello_ei/src/main.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static size_t inference_cnt;
3333
*/
3434
extern EI_IMPULSE_ERROR run_classifier(signal_t *signal, ei_impulse_result_t *result, bool debug);
3535

36-
static void print_inference_result(const ei_impulse_result_t *result, int64_t duration)
36+
static void print_inference_result(const ei_impulse_result_t *result, uint32_t duration_us)
3737
{
3838
LOG_INF("=== Inference result ===");
3939

@@ -47,12 +47,12 @@ static void print_inference_result(const ei_impulse_result_t *result, int64_t du
4747
#endif
4848

4949
LOG_INF("=== Inference time profiling ===");
50-
LOG_INF("Full inference completed in %lld ms", duration);
51-
LOG_INF("Classification completed in %d ms", result->timing.classification);
52-
LOG_INF("DSP operations completed in %d ms", result->timing.dsp);
50+
LOG_INF("Full inference completed in %u us", duration_us);
51+
LOG_INF("Classification completed in %lld us", result->timing.classification_us);
52+
LOG_INF("DSP operations completed in %lld us", result->timing.dsp_us);
5353

5454
#if EI_CLASSIFIER_HAS_ANOMALY
55-
LOG_INF("Anomaly detection completed in %d ms", result->timing.anomaly);
55+
LOG_INF("Anomaly detection completed in %lld us", result->timing.anomaly_us);
5656
#endif
5757

5858
LOG_SEPARATOR();
@@ -132,7 +132,7 @@ static int run_model(const float *input_data, size_t input_data_size)
132132
__ASSERT_NO_MSG(input_data_size >= EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE);
133133

134134
size_t sample_cnt = 0;
135-
int64_t start_time, delta;
135+
uint32_t start_cycles, delta_us;
136136
ei_impulse_result_t inference_result;
137137
EI_IMPULSE_ERROR err;
138138

@@ -148,16 +148,16 @@ static int run_model(const float *input_data, size_t input_data_size)
148148
* in a sliding window fashion.
149149
*/
150150
if (sample_cnt >= EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE) {
151-
start_time = k_uptime_get();
151+
start_cycles = k_cycle_get_32();
152152
err = run_ei_classification(&inference_result, EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE);
153-
delta = k_uptime_delta(&start_time);
153+
delta_us = k_cyc_to_us_floor32(k_cycle_get_32() - start_cycles);
154154

155155
if (err != EI_IMPULSE_OK) {
156156
LOG_ERR("Classification failed with error code: %d", err);
157157
return -1;
158158
}
159159

160-
print_inference_result(&inference_result, delta);
160+
print_inference_result(&inference_result, delta_us);
161161

162162
/* Keep track of how many inferences have been performed
163163
* to know the offset in the buffered data.

0 commit comments

Comments
 (0)