-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
502 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
add_subdirectory(Layers) | ||
add_subdirectory(Models) | ||
add_subdirectory(Ops) | ||
|
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,45 @@ | ||
#------------------------------------------------------------------------------- | ||
# Generate Non-Schedule Version Conv Layer Static Library | ||
#------------------------------------------------------------------------------- | ||
|
||
add_executable(conv_layer_generator conv_layer_generator.cpp) | ||
target_link_libraries(conv_layer_generator | ||
PRIVATE | ||
Halide::Generator) | ||
add_halide_library(conv_layer_nonschedule FROM conv_layer_generator) | ||
|
||
#------------------------------------------------------------------------------- | ||
# Generate Auto-Schedule Version Conv Layer Static Library | ||
#------------------------------------------------------------------------------- | ||
|
||
add_executable(conv_layer_autoschedule_generator conv_layer_generator-autoschedule.cpp) | ||
target_link_libraries(conv_layer_autoschedule_generator | ||
PRIVATE | ||
Halide::Generator) | ||
add_halide_library(conv_layer_autoschedule FROM conv_layer_autoschedule_generator | ||
AUTOSCHEDULER Halide::Mullapudi2016) | ||
|
||
#------------------------------------------------------------------------------- | ||
# Generate Manually-Schedule Version Conv Layer Static Library | ||
#------------------------------------------------------------------------------- | ||
|
||
add_executable(conv_layer_manually_generator conv_layer_generator-manually.cpp) | ||
target_link_libraries(conv_layer_manually_generator | ||
PRIVATE | ||
Halide::Generator) | ||
add_halide_library(conv_layer_manuallyschedule FROM conv_layer_manually_generator) | ||
|
||
#------------------------------------------------------------------------------- | ||
# Halide ConvLayer Benchmark Target | ||
#------------------------------------------------------------------------------- | ||
|
||
add_executable(halide-convlayer-benchmark | ||
Main.cpp | ||
HalideConvLayerBenchmark.cpp) | ||
|
||
target_link_libraries(halide-convlayer-benchmark | ||
GoogleBenchmark | ||
Halide::ImageIO | ||
conv_layer_nonschedule | ||
conv_layer_manuallyschedule | ||
conv_layer_autoschedule) |
87 changes: 87 additions & 0 deletions
87
benchmarks/DeepLearning/Layers/HalideConvLayerBenchmark.cpp
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 @@ | ||
#include <chrono> | ||
#include <cstdio> | ||
|
||
#include "conv_layer_nonschedule.h" | ||
#include "conv_layer_manuallyschedule.h" | ||
#include "conv_layer_autoschedule.h" | ||
#include <benchmark/benchmark.h> | ||
#include "HalideBuffer.h" | ||
|
||
using namespace Halide::Runtime; | ||
|
||
const int N = 5, CI = 128, CO = 128, W = 100, H = 80; | ||
|
||
Buffer<float, 4> input(CI, W + 2, H + 2, N), input1(CI, W + 2, H + 2, N), input2(CI, W + 2, H + 2, N); | ||
Buffer<float, 4> filter(CO, 3, 3, CI), filter1(CO, 3, 3, CI), filter2(CO, 3, 3, CI); | ||
Buffer<float, 1> bias(CO), bias1(CO), bias2(CO); | ||
Buffer<float, 4> output(CO, W, H, N), output1(CO, W, H, N), output2(CO, W, H, N); | ||
|
||
void initializeHalideConvLayerBenchmark(char **argv) { | ||
for (int c = 0; c < input.dim(3).extent(); c++) { | ||
for (int z = 0; z < input.channels(); z++) { | ||
for (int y = 0; y < input.height(); y++) { | ||
for (int x = 0; x < input.width(); x++) { | ||
input(x, y, z, c) = rand(); | ||
input1(x, y, z, c) = input(x, y, z, c); | ||
input2(x, y, z, c) = input(x, y, z, c); | ||
} | ||
} | ||
} | ||
} | ||
|
||
for (int c = 0; c < filter.dim(3).extent(); c++) { | ||
for (int z = 0; z < filter.channels(); z++) { | ||
for (int y = 0; y < filter.height(); y++) { | ||
for (int x = 0; x < filter.width(); x++) { | ||
filter(x, y, z, c) = rand(); | ||
filter1(x, y, z, c) = filter(x, y, z, c); | ||
filter2(x, y, z, c) = filter(x, y, z, c); | ||
} | ||
} | ||
} | ||
} | ||
|
||
for (int x = 0; x < bias.width(); x++) { | ||
bias(x) = rand(); | ||
bias1(x) = bias(x); | ||
bias2(x) = bias(x); | ||
} | ||
|
||
#ifdef _WIN32 | ||
_putenv_s("HL_CUDA_JIT_MAX_REGISTERS", "256"); | ||
#else | ||
setenv("HL_CUDA_JIT_MAX_REGISTERS", "256", 1); | ||
#endif | ||
} | ||
|
||
static void Halide_ConvLayer_NonSchedule(benchmark::State &state) { | ||
for (auto _ : state) { | ||
for (int i = 0; i < state.range(0); ++i) { | ||
conv_layer_nonschedule(input, filter, bias, output); | ||
} | ||
} | ||
} | ||
|
||
static void Halide_ConvLayer_MaunallySchedule(benchmark::State &state) { | ||
for (auto _ : state) { | ||
for (int i = 0; i < state.range(0); ++i) { | ||
conv_layer_manuallyschedule(input1, filter1, bias1, output1); | ||
} | ||
} | ||
} | ||
|
||
static void Halide_ConvLayer_AutoSchedule(benchmark::State &state) { | ||
for (auto _ : state) { | ||
for (int i = 0; i < state.range(0); ++i) { | ||
conv_layer_autoschedule(input2, filter2, bias2, output2); | ||
} | ||
} | ||
} | ||
|
||
// Register benchmarking function. | ||
void registerBenchmarkHalideConvLayer() { | ||
BENCHMARK(Halide_ConvLayer_NonSchedule)->Arg(1)->Unit(benchmark::kMillisecond); | ||
BENCHMARK(Halide_ConvLayer_MaunallySchedule)->Arg(1)->Unit(benchmark::kMillisecond); | ||
BENCHMARK(Halide_ConvLayer_AutoSchedule)->Arg(1)->Unit(benchmark::kMillisecond); | ||
} | ||
|
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,46 @@ | ||
//===- Main.cpp -----------------------------------------------------------===// | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This is the main file of the Halide Conv Layer benchmark. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include <benchmark/benchmark.h> | ||
#include <stdexcept> | ||
|
||
void initializeHalideConvLayerBenchmark(char **); | ||
|
||
void registerBenchmarkHalideConvLayer(); | ||
|
||
// Run benchmarks. | ||
int main(int argc, char **argv) { | ||
if (argc != 1) { | ||
throw std::invalid_argument( | ||
"No arguments needed.\n"); | ||
} | ||
|
||
initializeHalideConvLayerBenchmark(argv); | ||
|
||
// Register Benchmark Function. | ||
registerBenchmarkHalideConvLayer(); | ||
|
||
::benchmark::Initialize(&argc, argv); | ||
::benchmark::RunSpecifiedBenchmarks(); | ||
|
||
// Generate result. | ||
|
||
return 0; | ||
} |
71 changes: 71 additions & 0 deletions
71
benchmarks/DeepLearning/Layers/conv_layer_generator-autoschedule.cpp
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,71 @@ | ||
#include "Halide.h" | ||
|
||
namespace { | ||
|
||
using namespace Halide; | ||
|
||
class ConvolutionLayer : public Halide::Generator<ConvolutionLayer> { | ||
public: | ||
Input<Buffer<float, 4>> input{"input"}; | ||
Input<Buffer<float, 4>> filter{"filter"}; | ||
Input<Buffer<float, 1>> bias{"bias"}; | ||
Output<Buffer<float, 4>> relu{"relu"}; | ||
|
||
void generate() { | ||
const int N = 5, CI = 128, CO = 128, W = 100, H = 80; | ||
|
||
/* THE ALGORITHM */ | ||
|
||
Var x("x"), y("y"), c("c"), n("n"); | ||
|
||
Func conv("conv"); | ||
RDom r(0, CI, 0, 3, 0, 3); | ||
|
||
conv(c, x, y, n) = bias(c); | ||
conv(c, x, y, n) += filter(c, r.y, r.z, r.x) * input(r.x, x + r.y, y + r.z, n); | ||
|
||
relu(c, x, y, n) = max(0, conv(c, x, y, n)); | ||
|
||
/* THE SCHEDULE */ | ||
|
||
relu.dim(0).set_bounds(0, CO).set_stride(1); | ||
relu.dim(1).set_bounds(0, W).set_stride(CO); | ||
relu.dim(2).set_bounds(0, H).set_stride(CO * W); | ||
relu.dim(3).set_bounds(0, N).set_stride(CO * H * W); | ||
|
||
input.dim(0).set_bounds(0, CI).set_stride(1); | ||
input.dim(1).set_bounds(0, W + 2).set_stride(CI); | ||
input.dim(2).set_bounds(0, H + 2).set_stride(CI * (W + 2)); | ||
input.dim(3).set_bounds(0, N).set_stride(CI * (W + 2) * (H + 2)); | ||
|
||
filter.dim(0).set_bounds(0, CO).set_stride(1); | ||
filter.dim(1).set_bounds(0, 3).set_stride(CO); | ||
filter.dim(2).set_bounds(0, 3).set_stride(CO * 3); | ||
filter.dim(3).set_bounds(0, CI).set_stride(CO * 3 * 3); | ||
|
||
bias.dim(0).set_bounds(0, CO).set_stride(1); | ||
|
||
if (using_autoscheduler()) { | ||
input.dim(0).set_estimate(0, CI); | ||
input.dim(1).set_estimate(0, W + 2); | ||
input.dim(2).set_estimate(0, H + 2); | ||
input.dim(3).set_estimate(0, N); | ||
|
||
filter.dim(0).set_estimate(0, CO); | ||
filter.dim(1).set_estimate(0, 3); | ||
filter.dim(2).set_estimate(0, 3); | ||
filter.dim(3).set_estimate(0, CI); | ||
|
||
bias.dim(0).set_estimate(0, CO); | ||
|
||
relu.dim(0).set_estimate(0, W); | ||
relu.dim(1).set_estimate(0, H); | ||
relu.dim(2).set_estimate(0, CO); | ||
relu.dim(3).set_estimate(0, N); | ||
} | ||
} | ||
}; | ||
|
||
} // namespace | ||
|
||
HALIDE_REGISTER_GENERATOR(ConvolutionLayer, conv_layer_autoschedule) |
Oops, something went wrong.