1

The tutorial generates 3 functions with different target and pack into a single static library along with halide runtime.

The question is, how do I call it ?
To my understanding, I should check the cpu feature before calling the functions. What is the best way the dispatch these functions ?

./lesson_15_generate \
    -g my_first_generator \
    -f my_first_generator_basic \
    -e object,c_header\
    -o . \
    target=host-x86-64-no_runtime

./lesson_15_generate \
    -g my_first_generator \
    -f my_first_generator_sse41 \
    -e object,c_header\
    -o . \
    target=host-x86-64-sse41-no_runtime

./lesson_15_generate \
    -g my_first_generator \
    -f my_first_generator_avx \
    -e object,c_header\
    -o . \
    target=host-x86-64-avx-no_runtime
prgbenz
  • 1,129
  • 4
  • 13
  • 27

1 Answers1

0

You can get Halide to do the dispatch for you at runtime using a comma-separated list of targets:

./lesson_15_generate \
    -g my_first_generator \
    -f my_first_generator \
    -e static_library,c_header\
    -o . \
    target=x86-64-avx-no_runtime,x86-64-sse41-no_runtime,x86-64-no_runtime

That makes it compile three different pieces of code for the three targets. Calling "my_first_generator" will then automatically dispatch to the first thing in the list that it thinks it can run, based on checking the CPU ID on the first call.

Andrew Adams
  • 1,396
  • 7
  • 3
  • Error: (at ../tools/GenGen.cpp:4) Cannot request object for compile_multitarget. Aborted (core dumped), the method doesn't work on my system. my git HEAD is de5428ffc367 and compiled with llvm-1:11~++20200705063810 , [https://stackoverflow.com/users/3874652/andrew-adams] – prgbenz Jul 07 '20 at 06:29
  • Oops, edited my reply to say "static_library" instead of "object" – Andrew Adams Jul 07 '20 at 17:06