Skip to content

Commit

Permalink
Merge branch 'master' into d3d12
Browse files Browse the repository at this point in the history
  • Loading branch information
slomp committed Apr 25, 2018
2 parents 9f59d9a + 8d92748 commit c2950c4
Show file tree
Hide file tree
Showing 49 changed files with 2,986 additions and 2,126 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Expand Up @@ -429,7 +429,8 @@ foreach(F mex_halide.m
halide_benchmark.h
halide_image.h
halide_image_io.h
halide_image_info.h)
halide_image_info.h
halide_trace_config.h)
install(FILES "${HALIDE_BASE_DIR}/tools/${F}"
DESTINATION tools)
endforeach()
Expand Down
21 changes: 17 additions & 4 deletions Makefile
Expand Up @@ -164,6 +164,11 @@ LLVM_LIBS_FOR_SHARED_LIBHALIDE=$(if $(WITH_LLVM_INSIDE_SHARED_LIBHALIDE),$(LLVM_

LLVM_LD_FLAGS = $(shell $(LLVM_CONFIG) --ldflags --system-libs | sed -e 's/\\/\//g' -e 's/\([a-zA-Z]\):/\/\1/g')

ifeq ($(UNAME), Linux)
# llvm-config doesn't always report -ltinfo in the system-libs. Detect it by seeing if llvm-config links to it.
LLVM_LD_FLAGS += $(shell ldd `which $(LLVM_CONFIG)` | grep libtinfo > /dev/null && echo -ltinfo)
endif

TUTORIAL_CXX_FLAGS ?= -std=c++11 -g -fno-omit-frame-pointer -fno-rtti -I $(ROOT_DIR)/tools
# The tutorials contain example code with warnings that we don't want
# to be flagged as errors, so the test flags are the tutorial flags
Expand Down Expand Up @@ -735,7 +740,7 @@ $(BUILD_DIR)/llvm_objects/list: $(OBJECTS) $(INITIAL_MODULES)
# object files in which archives it uses to resolve
# symbols. We only care about the libLLVM ones.
@mkdir -p $(@D)
$(CXX) -o /dev/null -shared $(OBJECTS) $(INITIAL_MODULES) -Wl,-t $(LLVM_STATIC_LIBS) $(COMMON_LD_FLAGS) | egrep "libLLVM" > $(BUILD_DIR)/llvm_objects/list.new
$(CXX) -o /dev/null -shared $(OBJECTS) $(INITIAL_MODULES) -Wl,-t $(LLVM_STATIC_LIBS) $(COMMON_LD_FLAGS) 2>&1 | egrep "libLLVM" > $(BUILD_DIR)/llvm_objects/list.new
# if the list has changed since the previous build, or there
# is no list from a previous build, then delete any old object
# files and re-extract the required object files
Expand Down Expand Up @@ -1144,7 +1149,13 @@ $(FILTERS_DIR)/cxx_mangling_define_extern.a: $(BIN_DIR)/cxx_mangling_define_exte
$(CURDIR)/$< -g cxx_mangling_define_extern $(GEN_AOT_OUTPUTS) -o $(CURDIR)/$(FILTERS_DIR) target=$(TARGET)-no_runtime-c_plus_plus_name_mangling-user_context -f "HalideTest::cxx_mangling_define_extern"
$(ROOT_DIR)/tools/makelib.sh $@ $@ $(FILTERS_DIR)/cxx_mangling_define_extern_externs.o

# pyramid needs a custom arg
# This tests the specific features gated by the legacy_buffer_wrappers flag, thus
# we need to enable it for this Generator.
$(FILTERS_DIR)/old_buffer_t.a: $(BIN_DIR)/old_buffer_t.generator
@mkdir -p $(@D)
$(CURDIR)/$< -g old_buffer_t -f old_buffer_t $(GEN_AOT_OUTPUTS) -o $(CURDIR)/$(FILTERS_DIR) target=$(TARGET)-no_runtime-legacy_buffer_wrappers

# pyramid needs a custom arg.
$(FILTERS_DIR)/pyramid.a: $(BIN_DIR)/pyramid.generator
@mkdir -p $(@D)
$(CURDIR)/$< -g pyramid -f pyramid $(GEN_AOT_OUTPUTS) -o $(CURDIR)/$(FILTERS_DIR) target=$(TARGET)-no_runtime levels=10
Expand Down Expand Up @@ -1774,6 +1785,7 @@ $(DISTRIB_DIR)/halide.tgz: $(LIB_DIR)/libHalide.a \
cp $(ROOT_DIR)/tools/halide_image.h $(DISTRIB_DIR)/tools
cp $(ROOT_DIR)/tools/halide_image_io.h $(DISTRIB_DIR)/tools
cp $(ROOT_DIR)/tools/halide_image_info.h $(DISTRIB_DIR)/tools
cp $(ROOT_DIR)/tools/halide_trace_config.h $(DISTRIB_DIR)/tools
cp $(ROOT_DIR)/README*.md $(DISTRIB_DIR)
cp $(ROOT_DIR)/bazel/BUILD $(DISTRIB_DIR)
cp $(ROOT_DIR)/bazel/halide.bzl $(DISTRIB_DIR)
Expand All @@ -1798,13 +1810,14 @@ $(DISTRIB_DIR)/halide.tgz: $(LIB_DIR)/libHalide.a \
halide/tools/halide_benchmark.h \
halide/tools/halide_image.h \
halide/tools/halide_image_io.h \
halide/tools/halide_image_info.h
halide/tools/halide_image_info.h \
halide/tools/halide_trace_config.h
rm -rf halide

.PHONY: distrib
distrib: $(DISTRIB_DIR)/halide.tgz

$(BIN_DIR)/HalideTraceViz: $(ROOT_DIR)/util/HalideTraceViz.cpp $(ROOT_DIR)/util/HalideTraceUtils.cpp $(INCLUDE_DIR)/HalideRuntime.h $(ROOT_DIR)/tools/halide_image_io.h
$(BIN_DIR)/HalideTraceViz: $(ROOT_DIR)/util/HalideTraceViz.cpp $(ROOT_DIR)/util/HalideTraceUtils.cpp $(INCLUDE_DIR)/HalideRuntime.h $(ROOT_DIR)/tools/halide_image_io.h $(ROOT_DIR)/tools/halide_trace_config.h
$(CXX) $(OPTIMIZE) -std=c++11 $(filter %.cpp,$^) -I$(INCLUDE_DIR) -I$(ROOT_DIR)/tools -L$(BIN_DIR) -o $@

$(BIN_DIR)/HalideTraceDump: $(ROOT_DIR)/util/HalideTraceDump.cpp $(ROOT_DIR)/util/HalideTraceUtils.cpp $(INCLUDE_DIR)/HalideRuntime.h $(ROOT_DIR)/tools/halide_image_io.h
Expand Down
18 changes: 9 additions & 9 deletions README.md
Expand Up @@ -33,26 +33,26 @@ Building Halide

#### TL;DR

Have llvm-4.0 or greater installed and run 'make' in the root
Have llvm-5.0 or greater installed and run 'make' in the root
directory of the repository (where this README is).

#### Acquiring LLVM

Building halide requires at least llvm 4.0, along with the matching
Building halide requires at least llvm 5.0, along with the matching
version of clang. llvm-config and clang must be somewhere in the
path. If your OS does not have packages for llvm-4.0, you can find
path. If your OS does not have packages for llvm-5.0, you can find
binaries for it at http://llvm.org/releases/download.html. Download an
appropriate package and then either install it, or at least put the
bin subdirectory in your path. (This works well on OS X and Ubuntu.)

If you want to build it yourself, first check it out from subversion:

% svn co https://llvm.org/svn/llvm-project/llvm/branches/release_40 llvm4.0
% svn co https://llvm.org/svn/llvm-project/cfe/branches/release_40 llvm4.0/tools/clang
% svn co https://llvm.org/svn/llvm-project/llvm/branches/release_50 llvm5.0
% svn co https://llvm.org/svn/llvm-project/cfe/branches/release_50 llvm5.0/tools/clang

Then build it like so:

% cd llvm4.0
% cd llvm5.0
% mkdir build
% cd build
% cmake -DLLVM_ENABLE_TERMINFO=OFF -DLLVM_TARGETS_TO_BUILD="X86;ARM;NVPTX;AArch64;Mips;PowerPC" -DLLVM_ENABLE_ASSERTIONS=ON -DCMAKE_BUILD_TYPE=Release ..
Expand Down Expand Up @@ -329,14 +329,14 @@ For examples of using the `hexagon` scheduling directive on both the simulator a
Hexagon DSP, see the blur example app.

To build and run an example app using the Hexagon target,
1. Obtain and build LLVM and Clang v4.0 or later from llvm.org
1. Obtain and build LLVM and Clang v5.0 or later from llvm.org
2. Download and install the Hexagon SDK and version 8.0 Hexagon Tools
3. Build and run an example for Hexagon HVX

#### 1. Obtain and build LLVM and clang v4.0 or later from llvm.org
#### 1. Obtain and build LLVM and clang v5.0 or later from llvm.org
The Hexagon backend is currently under development. So it's best to use trunk llvm.
These are the same instructions as above for building Clang/LLVM, but for trunk
Clang/LLVM instead of 4.0.
Clang/LLVM instead of 5.0.

cd <path to llvm>
svn co http://llvm.org/svn/llvm-project/llvm/trunk .
Expand Down
48 changes: 48 additions & 0 deletions apps/bilateral_grid/bilateral_grid_generator.cpp
@@ -1,4 +1,5 @@
#include "Halide.h"
#include "halide_trace_config.h"

namespace {

Expand Down Expand Up @@ -114,6 +115,53 @@ class BilateralGrid : public Halide::Generator<BilateralGrid> {
blury.compute_root().reorder(c, x, y, z).parallel(z).vectorize(x, 8).unroll(c);
bilateral_grid.compute_root().parallel(y).vectorize(x, 8);
}

/* Optional tags to specify layout for HalideTraceViz */
{
Halide::Trace::FuncConfig cfg;
cfg.pos.x = 100;
cfg.pos.y = 300;
input.add_trace_tag(cfg.to_trace_tag());

cfg.pos.x = 1564;
bilateral_grid.add_trace_tag(cfg.to_trace_tag());
}
{
Halide::Trace::FuncConfig cfg;
cfg.strides = {{1, 0}, {0, 1}, {40, 0}};
cfg.zoom = 3;

cfg.max = 32;
cfg.pos.x = 550;
cfg.pos.y = 100;
histogram.add_trace_tag(cfg.to_trace_tag());

cfg.max = 512;
cfg.pos.y = 300;
blurz.add_trace_tag(cfg.to_trace_tag());

cfg.max = 8192;
cfg.pos.y = 500;
blurx.add_trace_tag(cfg.to_trace_tag());

cfg.max = 131072;
cfg.pos.y = 700;
blury.add_trace_tag(cfg.to_trace_tag());
}
{
// GlobalConfig applies to the entire visualization pipeline;
// you can set this tag on any Func that is realized, but only
// the last one seen will be used. (Since the tags are emitted in
// an arbitrary order, emitting only one such tag is the best practice).
// Note also that since the global settings are often context-dependent
// (eg the output size and timestep may vary depending on the
// input data), it's often more useful to specify these on the
// command line.
Halide::Trace::GlobalConfig global_cfg;
global_cfg.timestep = 1000;

bilateral_grid.add_trace_tag(global_cfg.to_trace_tag());
}
}
};

Expand Down
11 changes: 1 addition & 10 deletions apps/bilateral_grid/viz.sh
Expand Up @@ -4,15 +4,6 @@ export HL_NUMTHREADS=4
rm -f $1/bilateral_grid.mp4
make $1/filter_viz && \
$1/filter_viz ../images/gray_small.png $1/out_small.png 0.2 0 | \
../../bin/HalideTraceViz --timestep 1000 --size 1920 1080 \
--gray --strides 1 0 0 1 \
--max 1 --move 100 300 --func input \
--strides 1 0 0 1 40 0 --zoom 3 \
--max 32 --move 550 100 --func histogram \
--max 512 --down 200 --func blurz \
--max 8192 --down 200 --func blurx \
--max 131072 --down 200 --func blury \
--strides 1 0 0 1 --zoom 1 \
--max 1 --move 1564 300 --func bilateral_grid | \
../../bin/HalideTraceViz --size 1920 1080 | \
avconv -f rawvideo -pix_fmt bgr32 -s 1920x1080 -i /dev/stdin -c:v h264 $1/bilateral_grid.mp4
#mplayer -demuxer rawvideo -rawvideo w=1920:h=1080:format=rgba:fps=30 -idle -fixed-vo -
69 changes: 69 additions & 0 deletions apps/camera_pipe/camera_pipe_generator.cpp
@@ -1,5 +1,6 @@
#include "Halide.h"
#include <stdint.h>
#include "halide_trace_config.h"

namespace {

Expand Down Expand Up @@ -181,6 +182,18 @@ class Demosaic : public Halide::Generator<Demosaic> {
}
}
}

/* Optional tags to specify layout for HalideTraceViz */
Halide::Trace::FuncConfig cfg;
cfg.pos = { 860, 340 - 220 };
cfg.max = 1024;
for (Func f : intermediates) {
std::string label = f.name();
std::replace(label.begin(), label.end(), '_', '@');
cfg.pos.y += 220;
cfg.labels = {{label}};
f.add_trace_tag(cfg.to_trace_tag());
}
}

private:
Expand Down Expand Up @@ -316,6 +329,14 @@ Func CameraPipe::apply_curve(Func input) {
curve.compute_root();
}

/* Optional tags to specify layout for HalideTraceViz */
{
Halide::Trace::FuncConfig cfg;
cfg.labels = {{"tone curve"}};
cfg.pos = { 580, 1000 };
curve.add_trace_tag(cfg.to_trace_tag());
}

Func curved;

if (lutResample == 1) {
Expand All @@ -342,6 +363,14 @@ Func CameraPipe::sharpen(Func input) {
sharpen_strength_x32.compute_root();
}

/* Optional tags to specify layout for HalideTraceViz */
{
Halide::Trace::FuncConfig cfg;
cfg.labels = {{"sharpen strength"}};
cfg.pos = { 10, 1000 };
sharpen_strength_x32.add_trace_tag(cfg.to_trace_tag());
}

// Make an unsharp mask by blurring in y, then in x.
Func unsharp_y("unsharp_y");
unsharp_y(x, y, c) = blur121(input(x, y - 1, c), input(x, y, c), input(x, y + 1, c));
Expand Down Expand Up @@ -468,6 +497,46 @@ void CameraPipe::generate() {
.bound(c, 0, 3)
.bound(x, 0, ((out_width)/(2*vec))*(2*vec))
.bound(y, 0, (out_height/strip_size)*strip_size);

/* Optional tags to specify layout for HalideTraceViz */
{
Halide::Trace::FuncConfig cfg;
cfg.max = 1024;
cfg.pos = { 10, 348 };
cfg.labels = {{"input"}};
input.add_trace_tag(cfg.to_trace_tag());

cfg.pos = { 305, 360 };
cfg.labels = {{"denoised"}};
denoised.add_trace_tag(cfg.to_trace_tag());

cfg.pos = { 580, 120 };
const int y_offset = 220;
cfg.strides = {{1, 0}, {0, 1}, {0, y_offset}};
cfg.labels = {
{ "gr", { 0, 0 * y_offset } },
{ "r", { 0, 1 * y_offset }},
{ "b", { 0, 2 * y_offset }},
{ "gb", { 0, 3 * y_offset }},
};
deinterleaved.add_trace_tag(cfg.to_trace_tag());

cfg.color_dim = 2;
cfg.strides = {{1, 0}, {0, 1}, {0, 0}};
cfg.pos = { 1140, 360 };
cfg.labels = {{"demosaiced"}};
processed.add_trace_tag(cfg.to_trace_tag());

cfg.pos = { 1400, 360 };
cfg.labels = {{"color-corrected"}};
corrected.add_trace_tag(cfg.to_trace_tag());

cfg.max = 256;
cfg.pos = { 1660, 360 };
cfg.labels = {{"gamma-corrected"}};
curved.add_trace_tag(cfg.to_trace_tag());

}
}
};

Expand Down
33 changes: 5 additions & 28 deletions apps/camera_pipe/viz.sh
Expand Up @@ -2,35 +2,12 @@
export HL_TRACE_FILE=/dev/stdout
export HL_NUMTHREADS=4
rm -f $1/camera_pipe.mp4
# Do trivial partial-overrides of trace settings via flags
# (--zoom and --rlabel) just to demonstrate that it works.
$1/viz/process ../images/bayer_small.png 3700 1.8 50 1 1 $1/out.png |
../../bin/HalideTraceViz --timestep 1000 --size 1920 1080 \
--strides 1 0 0 1 --gray --max 1024 \
--move 10 348 --func input \
--label input input 10 \
--move 305 360 --func denoised \
--label denoised denoised 10 \
--strides 1 0 0 1 0 220 \
--move 580 120 --func deinterleaved \
--label deinterleaved "gr" 10 \
--down 220 --label deinterleaved "r" 10 \
--down 220 --label deinterleaved "b" 10 \
--down 220 --label deinterleaved "gb" 10 \
--strides 1 0 0 1 \
--move 720 120 --func r_gr --label r_gr "r@gr" 10 \
--right 140 --func g_gr --label g_gr "g@gr" 10 \
--right 140 --func b_gr --label b_gr "b@gr" 10 \
--move 720 340 --func r_r --label r_r "r@r" 10 \
--right 140 --func g_r --label g_r "g@r" 10 \
--right 140 --func b_r --label b_r "b@r" 10 \
--move 720 560 --func r_b --label r_b "r@b" 10 \
--right 140 --func g_b --label g_b "g@b" 10 \
--right 140 --func b_b --label b_b "b@b" 10 \
--move 720 870 --func r_gb --label r_gb "r@gb" 10 \
--right 140 --func g_gb --label g_gb "g@gb" 10 \
--right 140 --func b_gb --label b_gb "b@gb" 10 \
--strides 1 0 0 1 0 0 --rgb 2 \
--move 1140 360 --func output --label output "demosaiced" 10 \
--move 1400 360 --func corrected --label corrected "color-corrected" 10 \
--max 256 --move 1660 360 --func curved --label curved "gamma-corrected" 10 |\
--zoom 4 --func sharpen_strength_x32 \
--rlabel curve "tone curve LUT" 0 0 10 \
|\
avconv -f rawvideo -pix_fmt bgr32 -s 1920x1080 -i /dev/stdin -c:v h264 $1/camera_pipe.mp4
#mplayer -demuxer rawvideo -rawvideo w=1920:h=1080:format=rgba:fps=30 -idle -fixed-vo -
17 changes: 10 additions & 7 deletions apps/hexagon_benchmarks/adb_run_on_device.sh
Expand Up @@ -20,17 +20,20 @@ APP_TARGET=arm-64-android
make bin/${APP_TARGET}/process

# Make a folder on device for the app and our dependencies.
adb shell mkdir -p ${DEVICE_PATH}
if [ $? == 0 ]
then
adb shell mkdir -p ${DEVICE_PATH}

# Push the Hexagon runtime to $DEVICE_PATH.
adb push ${HEXAGON_RUNTIME_PATH}/bin/${APP_TARGET}/libhalide_hexagon_host.so ${DEVICE_PATH}
adb push ${HEXAGON_RUNTIME_PATH}/bin/v60/signed_by_debug/libhalide_hexagon_remote_skel.so ${DEVICE_PATH}
adb push ${HEXAGON_RUNTIME_PATH}/bin/${APP_TARGET}/libhalide_hexagon_host.so ${DEVICE_PATH}
adb push ${HEXAGON_RUNTIME_PATH}/bin/v60/signed_by_debug/libhalide_hexagon_remote_skel.so ${DEVICE_PATH}

# If there's a testsig installed in the usual location, copy it to
# $DEVICE_PATH so it is visible to our modified $ASDP_LIBRARY_PATH.
adb shell cp /system/lib/rfsa/adsp/testsig* ${DEVICE_PATH} > /dev/null || true
adb shell cp /system/lib/rfsa/adsp/testsig* ${DEVICE_PATH} > /dev/null || true

# Push and run the app!
adb push ${BIN}/${APP_TARGET}/process ${DEVICE_PATH}
adb shell chmod +x ${DEVICE_PATH}/process
adb shell ${DEVICE_ENV} ${DEVICE_PATH}/process
adb push ${BIN}/${APP_TARGET}/process ${DEVICE_PATH}
adb shell chmod +x ${DEVICE_PATH}/process
adb shell ${DEVICE_ENV} ${DEVICE_PATH}/process
fi

0 comments on commit c2950c4

Please sign in to comment.