forked from halide/Halide
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request halide#2118 from halide/bazel-lite
Add Bazel build rules to distrib packages
- Loading branch information
Showing
14 changed files
with
1,414 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
load("@halide//:halide.bzl", "halide_library") | ||
|
||
halide_library( | ||
name="bazeldemo", | ||
srcs=["bazeldemo_generator.cpp"] | ||
) | ||
|
||
cc_binary( | ||
name = "main", | ||
srcs = ["main.cpp"], | ||
deps = [ | ||
":bazeldemo", | ||
"@halide//:halide_buffer" | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Note that this requires you to have built the toplevel Halide 'distrib' folder via 'make distrib' | ||
local_repository( | ||
name = "halide", | ||
path = "../../distrib", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include "Halide.h" | ||
|
||
namespace { | ||
|
||
class BazelDemo : public Halide::Generator<BazelDemo> { | ||
public: | ||
GeneratorParam<bool> vectorize{"vectorize", true}; | ||
GeneratorParam<bool> parallelize{"parallelize", true}; | ||
|
||
Input<Buffer<float>> input{"input", 2}; | ||
Input<float> scale{"scale"}; | ||
|
||
Output<Buffer<float>> output{"output", 2}; | ||
|
||
void generate() { | ||
output(x, y) = input(x, y) * scale; | ||
} | ||
void schedule() { | ||
if (vectorize) { | ||
output.vectorize(x, natural_vector_size<float>()); | ||
} | ||
if (parallelize) { | ||
output.parallel(y); | ||
} | ||
} | ||
|
||
private: | ||
Var x, y; | ||
}; | ||
|
||
HALIDE_REGISTER_GENERATOR(BazelDemo, "bazeldemo") | ||
|
||
} // namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include <cmath> | ||
#include <cstdio> | ||
|
||
#include "HalideBuffer.h" | ||
#include "bazeldemo.h" // Generated by Bazel via halide_library() rule | ||
|
||
int main(int argc, char **argv) { | ||
constexpr int kEdge = 30; | ||
constexpr float kMax = kEdge * kEdge; | ||
|
||
Halide::Runtime::Buffer<float> input(kEdge, kEdge); | ||
for (int x = 0; x < kEdge; ++x) { | ||
for (int y = 0; y < kEdge; ++y) { | ||
input(x, y) = static_cast<float>(x + y) / kMax; | ||
} | ||
} | ||
|
||
const float kScale = 0.5f; | ||
Halide::Runtime::Buffer<float> output(kEdge, kEdge); | ||
int result = bazeldemo(input, kScale, output); | ||
if (result != 0) { | ||
fprintf(stderr, "Failure: %d\n", result); | ||
return -1; | ||
} | ||
|
||
for (int x = 0; x < kEdge; ++x) { | ||
for (int y = 0; y < kEdge; ++y) { | ||
const float expected = input(x, y) * kScale; | ||
constexpr float kEpsilon = 0.00001f; | ||
if (fabs(expected - output(x, y)) > kEpsilon) { | ||
fprintf(stderr, "Expected %f, Got %f\n", expected, output(x, y)); | ||
return -1; | ||
} | ||
} | ||
} | ||
|
||
printf("Success!\n"); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# Bazel build rules for clients using Halize distributions. | ||
# Note that these rules aren't meant to build Halide itself; | ||
# they assume that a Halide library has already been built, | ||
# and that a downstream client wants to use it. | ||
# | ||
# These rules have only been tested with Bazel 0.5+, and are unlikely | ||
# to work with earlier versions of Bazel. | ||
|
||
package( | ||
default_visibility = ["//visibility:public"], | ||
) | ||
|
||
load( | ||
"@halide//:halide.bzl", | ||
"halide_config_settings", | ||
"halide_language_copts", | ||
"halide_library_runtimes", | ||
) | ||
|
||
halide_config_settings() | ||
|
||
halide_library_runtimes() | ||
|
||
cc_library( | ||
name = "language", | ||
hdrs = ["include/Halide.h"], | ||
copts = halide_language_copts(), | ||
includes = ["include"], | ||
deps = [ | ||
":lib_halide_static", | ||
":runtime", | ||
], | ||
) | ||
|
||
# You should rarely need to add an explicit dep on this library | ||
# (the halide_library() rule will add it for you), but there are | ||
# unusual circumstances where it is necessary. | ||
cc_library( | ||
name = "runtime", | ||
hdrs = glob(["include/HalideRuntime*.h"]), | ||
includes = ["include"], | ||
) | ||
|
||
# Header-only library to let clients to use Halide::Buffer at runtime. | ||
# (Generators should never need to use this library.) | ||
cc_library( | ||
name = "halide_buffer", | ||
hdrs = glob(["include/HalideBuffer*.h"]), | ||
includes = ["include"], | ||
) | ||
|
||
# Config setting to catch the case where someone is trying to build | ||
# on Windows, but forgot to specify --host_cpu=x64_windows_msvc AND | ||
# --cpu=x64_windows_msvc. | ||
config_setting( | ||
name = "windows_not_using_msvc", | ||
values = {"cpu": "x64_windows"}, | ||
) | ||
|
||
cc_library( | ||
name = "lib_halide_static", | ||
srcs = select({ | ||
":windows_not_using_msvc": [ | ||
"please_set_host_cpu_and_cpu_to_x86_64_windows", | ||
], | ||
"@halide//:halide_config_x86_64_windows": [ | ||
"Release/Halide.lib", | ||
"Release/Halide.dll", | ||
], | ||
"//conditions:default": [ | ||
"lib/libHalide.a", | ||
], | ||
}), | ||
visibility = ["//visibility:private"], | ||
) | ||
|
||
# This library is visibility:public, because any package that uses the | ||
# halide_library() rule will implicitly need access to it; that said, it is | ||
# intended only for the private, internal use of the halide_library() rule. | ||
# Please don't depend on it directly; doing so will likely break your code at | ||
# some point in the future. | ||
cc_library( | ||
name = "internal_halide_generator_glue", | ||
srcs = ["tools/GenGen.cpp"], | ||
includes = ["include"], | ||
deps = [":language"], | ||
) |
Oops, something went wrong.