我尝试将以下行添加到camera_pipe_generator.cpp 的底部以输出Halide如何编译成.html文件,但我不确定我做错了什么:
processed.compile_to_lowered_stmt("camera_pipe_debugging_trial.html", {}, HTML);
我认为我的第二个论点是错误的,但我应该在这里传递什么?
或者我有不同的方式可视化时间表吗? This post似乎暗示了Halide的可视化器存在。有没有关于如何使用它的资源?
谢谢!
编辑:我尝试过运行命令
../../tools/gengen.sh -c c++ -lcurses -l ../../lib/libHalide.a -o tmp/ -e html -s camera_pipe_generator.cpp target=host
然而,这导致以下错误:
Undefined symbols for architecture x86_64:
"_del_curterm", referenced from:
llvm::sys::Process::FileDescriptorHasColors(int) in libHalide.a(llvm_460_Process.cpp.o)
"_set_curterm", referenced from:
llvm::sys::Process::FileDescriptorHasColors(int) in libHalide.a(llvm_460_Process.cpp.o)
"_setupterm", referenced from:
llvm::sys::Process::FileDescriptorHasColors(int) in libHalide.a(llvm_460_Process.cpp.o)
"_tigetnum", referenced from:
llvm::sys::Process::FileDescriptorHasColors(int) in libHalide.a(llvm_460_Process.cpp.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我认为可能与在mac OSX 10.12.3上运行有关?
最终编辑:在gengen.sh文件中添加了选项'-lcurses',它确实有效!
答案 0 :(得分:4)
要将您的Halide代码可视化为MPEG文件,需要以下内容:
关于第4点,我确信这可以改变,但对于我的试验,这是我能够让事情发挥作用的唯一方法;任何能够在最后一点分享他们意见的人都欢迎这样做。
1:Halide过滤器编译为AOT二进制文件
我使用了halide-lang.org tutorial site上列出的亮度过滤器来创建下面列出的过滤器并将其编译为可用的二进制文件:
http://halide-lang.org/tutorials/tutorial_lesson_10_aot_compilation_generate.html
#include "Halide.h"
#include <iostream>
namespace
{
auto input = Halide::ImageParam(Halide::type_of< uint8_t >(), 2, std::string{"input_image"});
auto offset = Halide::Param< uint8_t >{"offset"};
} // anonymous namespace
auto create_filter() -> Halide::Func
{
auto x = Halide::Var{"x"};
auto y = Halide::Var{"y"};
auto brighten = Halide::Func{"filter_output"};
brighten(x, y) = input(x, y) + offset;
return brighten;
}
auto schedule_filter(Halide::Func filter_ref) { filter_ref.vectorize(x, 16).parallel(y); }
auto create_aot_binary()
{
auto args = std::vector< Halide::Argument >{input, offset};
brighten.compile_to_file("brighten", args);
}
int main(int argc, const char* argv[])
{
printf("brighten filter AOT binary generator\n");
auto brighten = create_filter();
schedule_filter(brighten);
create_aot_binary();
return 0;
}
<强> 2。用于练习AOT二进制文件的源代码
#include "brighten.h" // header file created by aot generator in step 1
#include <cassert>
#include <vector>
namespace
{
constexpr auto width = 16 * 4;
constexpr auto height = 16 * 4;
} // anonymous namespace
auto create_input_image() -> std::vector< uint8_t >
{
auto image = std::vector< uint8_t >(width * height, 0);
for (auto y = 0; y < width; y++)
{
for (auto x = 0; x < height; x++)
{
const auto val = x ^ (y + 1);
const auto index = y * height + x;
image[index] = val;
}
}
return image;
}
auto create_buffer_t_with_data(const std::vector< uint8_t >& image) -> buffer_t
{
auto buff = buffer_t{0};
buff.host = image.data();
buff.stride[0] = 1;
buff.stride[1] = width;
buff.extent[0] = width;
buff.extent[1] = height;
buff.elem_size = 1;
}
int main(int argc, const char* argv[])
{
printf("brighten filter exercise\n");
auto input_image = create_input_image();
assert(input_image.size() != 0);
auto input_buf = create_buffer_t_with_data(input_image);
auto output_image = std::vector< uint8_t >(width * height, 0);
assert(output_image.size() != 0);
auto output_buf = create_buffer_t_with_data(output_image);
const auto offset = 1;
auto error = brighten(&input_buf, offset, &output_buf);
(void)error;
return 0;
}
第3。用于构建和执行HalideTraceViz的Bash shell脚本
现在,这是bash shell脚本,其中我:
#!/bin/bash
set -e
set -u
function build_binaries()
{
printf "${FUNCNAME[0]}\n"
printf "Building HalideTraceViz\n"
xcodebuild -project visualize_brighten.xcodeproj -scheme HalideTraceViz CONFIGURATION_BUILD_DIR=build/Debug -configuration "Debug" clean build
printf "Building generate_brighten_aot\n"
xcodebuild -project visualize_brighten.xcodeproj -scheme generate_brighten_aot CONFIGURATION_BUILD_DIR=build/Debug -configuration "Debug" clean build
printf "Generating AOT in order to build exercise app\n"
cd build/Debug
HL_TRACE=3 ./generate_brighten_aot
cd $CURRENT_PATH
printf "Building app to exercise brighten filter\n"
xcodebuild -project visualize_brighten.xcodeproj -scheme exercise_brighten_aot CONFIGURATION_BUILD_DIR=build/Debug -configuration "Debug" clean build
cd $CURRENT_PATH
}
function copy_binaries()
{
printf "${FUNCNAME[0]}\n"
if [[ -d $CURRENT_PATH/halide_visualizer ]]; then
rm -Rv $CURRENT_PATH/halide_visualizer
fi
mkdir $CURRENT_PATH/halide_visualizer
cp -Rv $CURRENT_PATH/build/Debug $CURRENT_PATH/halide_visualizer/Debug
}
function visualize_function()
{
printf "${FUNCNAME[0]}\n"
local BLANK=0
local DIMENSIONS=1
local ZOOM=8
local COST=4
local STRIDE0="1 0"
local STRIDE1="0 1"
local FFMPEG_BIN_PATH="YOU_HAVE_TO_DOWNLOAD_THIS_BIN_AND_SET_THE_PATH_HERE"
cd $CURRENT_PATH/halide_visualizer/Debug
echo "About to start visualizing brighten filter"
HL_TRACE=3 ./generate_brighten_aot && \
HL_TRACE_FILE=/dev/stdout ./exercise_brighten_aot | \
$CURRENT_PATH/build/Debug/HalideTraceViz -s 1024 516 -t 1 -d 100 \
-f brighten:input_image 0 255 $BLANK $ZOOM $COST 0 0 $STRIDE0 $STRIDE1 |\
$FFMPEG_BIN_PATH/ffmpeg -r 30 -f rawvideo -pix_fmt bgra -s 1024X516 -i - -y -pix_fmt yuv420p $CURRENT_PATH/movies/brighten_schedule.mp4
cd $CURRENT_PATH
}
main()
{
printf "${FUNCNAME[0]}\n"
CURRENT_PATH=$PWD
build_binaries
copy_binaries
visualize_function
printf "All done\n"
}
printf "Starting ${0##*/}\n"
main
有几点需要注意:
希望这可以帮助您入门;如果您有任何疑问,请告诉我。
答案 1 :(得分:2)
to在apps / camera_pipe目录中,以下命令行将HTML stmt文件生成到/tmp/camera_pipe.html:
../../tools/gengen.sh -c c++ -l ../../lib/libHalide.a -o /tmp/ -e html -s camera_pipe_generator.cpp target=host