#include "Halide.h"
#include <cstdio>
#include <fstream>
#include <vector>
template<typename T, size_t N>
bool check_file_header(const std::string& filename, const T (&expected)[N]) {
std::ifstream file(filename, std::ios::binary);
if (!file) {
std::cout << "Could not open file: " << filename << "\n";
return false;
}
T header[N];
if (!file.read(reinterpret_cast<char*>(header), sizeof header)) {
std::cout << "Could not read header from file: " << filename << "\n";
return false;
}
for (size_t i = 0; i < N; i++) {
if (header[i] != expected[i]) {
std::cout << "File " << filename << " has bad data: "
<< static_cast<int>(header[i]) << " instead of "
<< static_cast<int>(expected[i]) << "\n";
return false;
}
}
return true;
}
int main() {
Func brighter;
Var x, y;
Param<uint8_t> offset;
ImageParam input(type_of<uint8_t>(), 2);
std::vector<Argument> args(2);
args[0] = input;
args[1] = offset;
brighter(x, y) = input(x, y) + offset;
brighter.vectorize(x, 16).parallel(y);
brighter.compile_to_file("lesson_11_host", args, "brighter");
Target target;
target.os = Target::Android;
target.arch = Target::ARM;
target.bits = 32;
std::vector<Target::Feature> arm_features;
target.set_features(arm_features);
brighter.compile_to_file("lesson_11_arm_32_android", args, "brighter", target);
target.os = Target::Windows;
target.arch = Target::X86;
target.bits = 64;
std::vector<Target::Feature> x86_features;
x86_features.push_back(Target::AVX);
x86_features.push_back(Target::SSE41);
target.set_features(x86_features);
brighter.compile_to_file("lesson_11_x86_64_windows", args, "brighter", target);
target.os = Target::IOS;
target.arch = Target::ARM;
target.bits = 32;
std::vector<Target::Feature> armv7s_features;
armv7s_features.push_back(Target::ARMv7s);
target.set_features(armv7s_features);
brighter.compile_to_file("lesson_11_arm_32_ios", args, "brighter", target);
uint8_t arm_32_android_magic[] = {0x7f,
'E',
'L',
'F',
1,
1,
1};
if (!check_file_header("lesson_11_arm_32_android.o", arm_32_android_magic)) {
return -1;
}
uint8_t win_64_magic[] = {0x64, 0x86};
if (!check_file_header("lesson_11_x86_64_windows.obj", win_64_magic)) {
return -1;
}
uint32_t arm_32_ios_magic[] = {0xfeedface,
12,
11,
1};
if (!check_file_header("lesson_11_arm_32_ios.o", arm_32_ios_magic)) {
return -1;
}
printf("Success!\n");
return 0;
}
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
unsigned __INT8_TYPE__ uint8_t
unsigned __INT32_TYPE__ uint32_t