Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/halide/Halide
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavb-ca committed Nov 14, 2019
2 parents 2a39fd0 + 08bd367 commit b46414c
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 44 deletions.
7 changes: 5 additions & 2 deletions Makefile
Expand Up @@ -62,11 +62,14 @@ LLVM_BINDIR = $(shell $(LLVM_CONFIG) --bindir | sed -e 's/\\/\//g' -e 's/\([a-zA
LLVM_LIBDIR = $(shell $(LLVM_CONFIG) --libdir | sed -e 's/\\/\//g' -e 's/\([a-zA-Z]\):/\/\1/g')
# Apparently there is no llvm_config flag to get canonical paths to tools,
# so we'll just construct one relative to --src-root and hope that is stable everywhere.
LLVM_LLD_INCLUDE_DIR = $(shell $(LLVM_CONFIG) --src-root | sed -e 's/\\/\//g' -e 's/\([a-zA-Z]\):/\/\1/g')/tools/lld/include
# TODO(srj): remove this after all buildbots are switched to GitHub.
LLVM_SVN_LLD_INCLUDE_DIR = $(shell $(LLVM_CONFIG) --src-root | sed -e 's/\\/\//g' -e 's/\([a-zA-Z]\):/\/\1/g')/tools/lld/include
# The paths are slightly different for SVN vs GIT installs
LLVM_GIT_LLD_INCLUDE_DIR = $(shell $(LLVM_CONFIG) --src-root | sed -e 's/\\/\//g' -e 's/\([a-zA-Z]\):/\/\1/g')/../lld/include
LLVM_SYSTEM_LIBS=$(shell ${LLVM_CONFIG} --system-libs --link-static | sed -e 's/[\/&]/\\&/g')
LLVM_AS = $(LLVM_BINDIR)/llvm-as
LLVM_NM = $(LLVM_BINDIR)/llvm-nm
LLVM_CXX_FLAGS = -std=c++11 $(filter-out -O% -g -fomit-frame-pointer -pedantic -W% -W, $(shell $(LLVM_CONFIG) --cxxflags | sed -e 's/\\/\//g' -e 's/\([a-zA-Z]\):/\/\1/g;s/-D/ -D/g;s/-O/ -O/g')) -I$(LLVM_LLD_INCLUDE_DIR)
LLVM_CXX_FLAGS = -std=c++11 $(filter-out -O% -g -fomit-frame-pointer -pedantic -W% -W, $(shell $(LLVM_CONFIG) --cxxflags | sed -e 's/\\/\//g' -e 's/\([a-zA-Z]\):/\/\1/g;s/-D/ -D/g;s/-O/ -O/g')) -I$(LLVM_SVN_LLD_INCLUDE_DIR) -I$(LLVM_GIT_LLD_INCLUDE_DIR)
OPTIMIZE ?= -O3
OPTIMIZE_FOR_BUILD_TIME ?= -O0

Expand Down
43 changes: 17 additions & 26 deletions README.md
Expand Up @@ -50,23 +50,27 @@ must be somewhere in the path. If your OS does not have packages for llvm-8.0
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.
If you want to build it yourself, first check it out from GitHub:

% svn co https://llvm.org/svn/llvm-project/llvm/branches/release_90 llvm9.0
% svn co https://llvm.org/svn/llvm-project/cfe/branches/release_90 llvm9.0/tools/clang
% git clone https://github.com/llvm/llvm-project.git
% git checkout release/9.x # to build LLVM 9.x

(If you want to build LLVM 9.x, use `git checkout release/9.x`; for LLVM 8.0, use `release 8.x`; for current trunk, use `git checkout master`)

Then build it like so:

% cd llvm9.0
% cd llvm-project
% 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 ..
% make -j8
% cmake -DLLVM_ENABLE_PROJECTS="clang;lld" -DLLVM_ENABLE_RTTI=ON -DLLVM_ENABLE_TERMINFO=OFF -DLLVM_TARGETS_TO_BUILD="X86;ARM;NVPTX;AArch64;Mips;PowerPC" -DLLVM_ENABLE_ASSERTIONS=ON -DCMAKE_BUILD_TYPE=Release -DLLVM_BUILD_32_BITS=OFF ../llvm
% make -j

then to point Halide to it:

export LLVM_CONFIG=<path to llvm>/build/bin/llvm-config

(Note that you *must* add `clang` to `LLVM_ENABLE_PROJECTS`; adding `lld` to `LLVM_ENABLE_PROJECTS` is only required when using WebAssembly, but we recommend enabling it in all cases, to simplify builds.)

#### Building Halide with make

With `LLVM_CONFIG` set (or `llvm-config` in your path), you should be
Expand Down Expand Up @@ -94,7 +98,7 @@ If you wish to use cmake to build Halide, the build procedure is:
% mkdir cmake_build
% cd cmake_build
% cmake -DLLVM_DIR=/path-to-llvm-build/lib/cmake/llvm -DCMAKE_BUILD_TYPE=Release /path/to/halide
% make -j8
% make -j

`LLVM_DIR` should be the folder in the LLVM installation or build tree that contains `LLVMConfig.cmake`.

Expand All @@ -108,11 +112,11 @@ path. The instructions below assume Halide is checked out under

% mkdir C:\Code\llvm-build
% cd C:\Code\llvm-build
% cmake -DCMAKE_INSTALL_PREFIX=../llvm-install -DLLVM_ENABLE_TERMINFO=OFF -DLLVM_TARGETS_TO_BUILD=X86;ARM;NVPTX;AArch64;Mips;Hexagon -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_BUILD_32_BITS=OFF -DCMAKE_BUILD_TYPE=Release ../llvm -G "Visual Studio 14 Win64"
% cmake -DCMAKE_INSTALL_PREFIX=../llvm-install -DLLVM_ENABLE_TERMINFO=OFF -DLLVM_TARGETS_TO_BUILD=X86;ARM;NVPTX;AArch64;Mips;Hexagon -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_BUILD_32_BITS=OFF -DCMAKE_BUILD_TYPE=Release ../llvm/llvm -G "Visual Studio 14 Win64"

For a 32-bit build use:

% cmake -DCMAKE_INSTALL_PREFIX=../llvm-install -DLLVM_ENABLE_TERMINFO=OFF -DLLVM_TARGETS_TO_BUILD=X86;ARM;NVPTX;AArch64;Mips;Hexagon -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_BUILD_32_BITS=ON -DCMAKE_BUILD_TYPE=Release ../llvm -G "Visual Studio 14"
% cmake -DCMAKE_INSTALL_PREFIX=../llvm-install -DLLVM_ENABLE_TERMINFO=OFF -DLLVM_TARGETS_TO_BUILD=X86;ARM;NVPTX;AArch64;Mips;Hexagon -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_BUILD_32_BITS=ON -DCMAKE_BUILD_TYPE=Release ../llvm/llvm -G "Visual Studio 14"

Then build it like so:

Expand Down Expand Up @@ -331,26 +335,13 @@ 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 v5.0 or later from llvm.org
1. Obtain and build trunk LLVM and Clang. (Earlier versions of LLVM may work but are not actively tested and thus not recommended.)
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 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 5.0.

cd <path to llvm>
svn co http://llvm.org/svn/llvm-project/llvm/trunk .
svn co http://llvm.org/svn/llvm-project/cfe/trunk ./tools/clang
# Or:
# git clone http://llvm.org/git/llvm.git .
# git clone http://llvm.org/git/clang.git llvm/tools
mkdir build
cd build
cmake -DLLVM_ENABLE_TERMINFO=OFF -DLLVM_TARGETS_TO_BUILD="X86;ARM;NVPTX;AArch64;Mips;PowerPC;Hexagon" -DLLVM_ENABLE_ASSERTIONS=ON -DCMAKE_BUILD_TYPE=Release ..
make -j8
export LLVM_CONFIG=<path to llvm>/build/bin/llvm-config
#### 1. Obtain and build trunk LLVM and Clang

(Instructions given previous, just be sure to check out the `master` branch.)

#### 2. Download and install the Hexagon SDK and version 8.0 Hexagon Tools
Go to https://developer.qualcomm.com/software/hexagon-dsp-sdk/tools
Expand Down
8 changes: 6 additions & 2 deletions apps/onnx/onnx_converter.cc
Expand Up @@ -2818,8 +2818,12 @@ Node convert_random_node(
low = attr.f();
} else if (attr.name() == "seed") {
use_seed = true;
float fseed = attr.f();
seed = reinterpret_cast<int &>(fseed);
union {
float f;
int32_t i;
} u;
u.f = attr.f();
seed = u.i;
} else if (attr.name() == "mean") {
mean = attr.f();
} else if (attr.name() == "scale") {
Expand Down
4 changes: 4 additions & 0 deletions src/CodeGen_PTX_Dev.cpp
Expand Up @@ -461,7 +461,11 @@ vector<char> CodeGen_PTX_Dev::compile_to_src() {

// Ask the target to add backend passes as necessary.
bool fail = target_machine->addPassesToEmitFile(module_pass_manager, ostream, nullptr,
#if LLVM_VERSION >= 100
::llvm::CGFT_AssemblyFile,
#else
TargetMachine::CGFT_AssemblyFile,
#endif
true);
if (fail) {
internal_error << "Failed to set up passes to emit PTX source\n";
Expand Down
4 changes: 4 additions & 0 deletions src/LLVM_Headers.h
Expand Up @@ -38,6 +38,9 @@
#include <llvm/IR/Verifier.h>
#include <llvm/Linker/Linker.h>
#include <llvm/Passes/PassBuilder.h>
#if LLVM_VERSION >= 100
#include <llvm/Support/CodeGen.h>
#endif
#include <llvm/Support/DataExtractor.h>
#include <llvm/Support/DynamicLibrary.h>
#include <llvm/Support/FileSystem.h>
Expand All @@ -46,6 +49,7 @@
#include <llvm/Support/TargetSelect.h>
#include <llvm/Support/raw_os_ostream.h>
#include <llvm/Support/raw_ostream.h>
#include <llvm/Target/TargetMachine.h>
#include <llvm/Transforms/IPO.h>
#include <llvm/Transforms/IPO/Inliner.h>
#include <llvm/Transforms/IPO/PassManagerBuilder.h>
Expand Down
16 changes: 15 additions & 1 deletion src/LLVM_Output.cpp
Expand Up @@ -325,7 +325,13 @@ std::unique_ptr<llvm::Module> clone_module(const llvm::Module &module_in) {

} // namespace

void emit_file(const llvm::Module &module_in, Internal::LLVMOStream &out, llvm::TargetMachine::CodeGenFileType file_type) {
void emit_file(const llvm::Module &module_in, Internal::LLVMOStream &out,
#if LLVM_VERSION >= 100
llvm::CodeGenFileType file_type
#else
llvm::TargetMachine::CodeGenFileType file_type
#endif
) {
Internal::debug(1) << "emit_file.Compiling to native code...\n";
Internal::debug(2) << "Target triple: " << module_in.getTargetTriple() << "\n";

Expand Down Expand Up @@ -376,11 +382,19 @@ std::unique_ptr<llvm::Module> compile_module_to_llvm_module(const Module &module
}

void compile_llvm_module_to_object(llvm::Module &module, Internal::LLVMOStream &out) {
#if LLVM_VERSION >= 100
emit_file(module, out, llvm::CGFT_ObjectFile);
#else
emit_file(module, out, llvm::TargetMachine::CGFT_ObjectFile);
#endif
}

void compile_llvm_module_to_assembly(llvm::Module &module, Internal::LLVMOStream &out) {
#if LLVM_VERSION >= 100
emit_file(module, out, llvm::CGFT_AssemblyFile);
#else
emit_file(module, out, llvm::TargetMachine::CGFT_AssemblyFile);
#endif
}

void compile_llvm_module_to_llvm_bitcode(llvm::Module &module, Internal::LLVMOStream &out) {
Expand Down
32 changes: 24 additions & 8 deletions src/runtime/HalideBuffer.h
Expand Up @@ -532,33 +532,49 @@ class Buffer {
return buf.type;
}

/** A pointer to the element with the lowest address. If all
* strides are positive, equal to the host pointer. */
T *begin() const {
private:
/** Offset to the element with the lowest address. If all
* strides are positive, equal to zero. Offset is in elements, not bytes. */
ptrdiff_t begin_offset() const {
ptrdiff_t index = 0;
for (int i = 0; i < dimensions(); i++) {
if (dim(i).stride() < 0) {
index += dim(i).stride() * (dim(i).extent() - 1);
}
}
return (T *)(buf.host + index * type().bytes());
return index;
}

/** A pointer to one beyond the element with the highest address. */
T *end() const {
/** An offset to one beyond the element with the highest address.
* Offset is in elements, not bytes. */
ptrdiff_t end_offset() const {
ptrdiff_t index = 0;
for (int i = 0; i < dimensions(); i++) {
if (dim(i).stride() > 0) {
index += dim(i).stride() * (dim(i).extent() - 1);
}
}
index += 1;
return (T *)(buf.host + index * type().bytes());
return index;
}

public:
/** A pointer to the element with the lowest address. If all
* strides are positive, equal to the host pointer. */
T *begin() const {
assert(buf.host != nullptr); // Cannot call begin() on an unallocated Buffer.
return (T *)(buf.host + begin_offset() * type().bytes());
}

/** A pointer to one beyond the element with the highest address. */
T *end() const {
assert(buf.host != nullptr); // Cannot call end() on an unallocated Buffer.
return (T *)(buf.host + end_offset() * type().bytes());
}

/** The total number of bytes spanned by the data in memory. */
size_t size_in_bytes() const {
return (size_t)((const uint8_t *)end() - (const uint8_t *)begin());
return (size_t)(end_offset() - begin_offset()) * type().bytes();
}

/** Reset the Buffer to be equivalent to a default-constructed Buffer
Expand Down
2 changes: 0 additions & 2 deletions test/correctness/simd_op_check.cpp
@@ -1,8 +1,6 @@
#include "Halide.h"
#include "simd_op_check.h"

#include <fstream>
#include <future>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
Expand Down
1 change: 0 additions & 1 deletion test/correctness/simd_op_check.h
Expand Up @@ -261,7 +261,6 @@ class SimdOpCheckTest {
virtual void setup_images() {
for (auto p : image_params) {
p.reset();
p.set_host_alignment(128);
}
}
virtual bool test_all() {
Expand Down
4 changes: 3 additions & 1 deletion test/correctness/simd_op_check_hvx.cpp
Expand Up @@ -24,7 +24,9 @@ class SimdOpCheckHVX : public SimdOpCheckTest {
void setup_images() override {
for (auto p : image_params) {
p.reset();
p.set_host_alignment(128);
// HVX needs 128 byte alignment
constexpr int kHostAlignmentBytes = 128;
p.set_host_alignment(kHostAlignmentBytes);
Expr min = p.dim(0).min();
p.dim(0).set_min((min/128) * 128);
}
Expand Down
2 changes: 1 addition & 1 deletion tutorial/lesson_05_scheduling_1.cpp
Expand Up @@ -14,7 +14,7 @@

// If you have the entire Halide source tree, you can also build it by
// running:
// make tutorial_lesson_05_schedule_1
// make tutorial_lesson_05_scheduling_1
// in a shell with the current directory at the top of the halide
// source tree.

Expand Down

0 comments on commit b46414c

Please sign in to comment.