https://github.com/halide/Halide
Raw File
Tip revision: cb6f4a9c3fc8d989965f9eec4067d0f6cb3ba299 authored by Steven Johnson on 31 March 2020, 18:12:43 UTC
Merge pull request #4810 from halide/srj-pr
Tip revision: cb6f4a9
profiler_inlined.cpp
#include "HalideRuntime.h"

extern "C" {

WEAK __attribute__((always_inline)) int halide_profiler_set_current_func(halide_profiler_state *state, int tok, int t) {
    // Use empty volatile asm blocks to prevent code motion. Otherwise
    // llvm reorders or elides the stores.
    volatile int *ptr = &(state->current_func);
    // clang-format off
    asm volatile ("":::);
    *ptr = tok + t;
    asm volatile ("":::);
    // clang-format on
    return 0;
}

WEAK __attribute__((always_inline)) int halide_profiler_incr_active_threads(halide_profiler_state *state) {
    volatile int *ptr = &(state->active_threads);
    // clang-format off
    asm volatile ("":::);
    int ret = __sync_fetch_and_add(ptr, 1);
    asm volatile ("":::);
    // clang-format on
    return ret;
}

WEAK __attribute__((always_inline)) int halide_profiler_decr_active_threads(halide_profiler_state *state) {
    volatile int *ptr = &(state->active_threads);
    // clang-format off
    asm volatile ("":::);
    int ret = __sync_fetch_and_sub(ptr, 1);
    asm volatile ("":::);
    // clang-format on
    return ret;
}
}
back to top