#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() {
std::vector<Argument> args(2);
args[0] = input;
args[1] = offset;
brighter(x, y) = input(x, y) + offset;
target.
os = Target::Android;
target.
arch = Target::ARM;
std::vector<Target::Feature> arm_features;
brighter.
compile_to_file(
"lesson_11_arm_32_android", args,
"brighter", target);
target.
os = Target::Windows;
target.
arch = Target::X86;
std::vector<Target::Feature> x86_features;
x86_features.push_back(Target::AVX);
x86_features.push_back(Target::SSE41);
brighter.
compile_to_file(
"lesson_11_x86_64_windows", args,
"brighter", target);
target.
arch = Target::ARM;
std::vector<Target::Feature> armv7s_features;
armv7s_features.push_back(Target::ARMv7s);
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;
}
void compile_to_file(const std::string &filename_prefix, const std::vector< Argument > &args, const std::string &fn_name="", const Target &target=get_target_from_environment())
Compile to object file and header pair, with the given arguments.
Func & parallel(const VarOrRVar &var)
Mark a dimension to be traversed in parallel.
Func & vectorize(const VarOrRVar &var)
Mark a dimension to be computed all-at-once as a single vector.
An Image parameter to a halide pipeline.
A scalar parameter to a halide pipeline.
A Halide variable, to be used when defining functions.
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
unsigned __INT8_TYPE__ uint8_t
unsigned __INT32_TYPE__ uint32_t
A struct representing a target machine and os to generate code for.
void set_features(const std::vector< Feature > &features_to_set, bool value=true)
enum Halide::Target::Arch arch
int bits
The bit-width of the target machine.
enum Halide::Target::OS os