halide / Halide

a language for fast, portable data-parallel computation
https://halide-lang.org
Other
5.8k stars 1.07k forks source link

Data race in Halide profiler #4579

Open steven-johnson opened 4 years ago

steven-johnson commented 4 years ago

From running with TSAN locally, I get a data race reported for access to halide_profiler_get_state():

WARNING: ThreadSanitizer: data race (pid=51457)
  Read of size 4 at 0x7ff87234c548 by thread T5:
    #0 Halide::Runtime::Internal::sampling_profiler_thread(void*) <null> (libthird_Uparty_Shalide_Slibhalide_Ulibrary_Uruntime.so+0x19bc6)
    #1 Halide::Runtime::Internal::spawn_thread_helper(void*) <null> (libthird_Uparty_Shalide_Slibhalide_Ulibrary_Uruntime.so+0xe1cd)

  Previous write of size 4 at 0x7ff87234c548 by main thread:
    #0 halide_profiler_pipeline_end <null> (libthird_Uparty_Shalide_Slibhalide_Ulibrary_Uruntime.so+0x1a2fa)
    #1 <user-provided halide code>

  Location is global 'halide_profiler_get_state::s' of size 48 at 0x7ff87234c538 (libthird_Uparty_Shalide_Slibhalide_Ulibrary_Uruntime.so+0x00000001d548)

  Thread T5 (tid=51474, running) created by main thread at:
    #0 pthread_create third_party/llvm/llvm-project/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp:962:3 (halide_target_map_test+0xf828a)
    #1 halide_spawn_thread <null> (libthird_Uparty_Shalide_Slibhalide_Ulibrary_Uruntime.so+0xe185)
    #2 halide_profiler_pipeline_start <null> (libthird_Uparty_Shalide_Slibhalide_Ulibrary_Uruntime.so+0x19df0)
    #3 <user-provided halide code>
abadams commented 4 years ago

The profiler works by seeing who wins a race condition on average, so this is WAI.