本文整理汇总了C++中Func类的典型用法代码示例。如果您正苦于以下问题:C++ Func类的具体用法?C++ Func怎么用?C++ Func使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Func类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char **argv) {
// The camera pipe is specialized on the 2592x1968 images that
// come in, so we'll just use an image instead of a uniform image.
ImageParam input(UInt(16), 2);
ImageParam matrix_3200(Float(32), 2, "m3200"), matrix_7000(Float(32), 2, "m7000");
Param<float> color_temp("color_temp"); //, 3200.0f);
Param<float> gamma("gamma"); //, 1.8f);
Param<float> contrast("contrast"); //, 10.0f);
// shift things inwards to give us enough padding on the
// boundaries so that we don't need to check bounds. We're going
// to make a 2560x1920 output image, just like the FCam pipe, so
// shift by 16, 12
Func shifted;
shifted(x, y) = input(x+16, y+12);
// Parameterized output type, because LLVM PTX (GPU) backend does not
// currently allow 8-bit computations
int bit_width = atoi(argv[1]);
Type result_type = UInt(bit_width);
// Pick a schedule
schedule = atoi(argv[2]);
// Build the pipeline
Func processed = process(shifted, result_type, matrix_3200, matrix_7000, color_temp, gamma, contrast);
// We can generate slightly better code if we know the output is a whole number of tiles.
Expr out_width = processed.output_buffer().width();
Expr out_height = processed.output_buffer().height();
processed
.bound(tx, 0, (out_width/32)*32)
.bound(ty, 0, (out_height/32)*32);
//string s = processed.serialize();
//printf("%s\n", s.c_str());
std::vector<Argument> args = {color_temp, gamma, contrast, input, matrix_3200, matrix_7000};
processed.compile_to_file("curved", args);
processed.compile_to_assembly("curved.s", args);
return 0;
}
示例2: main
int main(int argc, char **argv) {
Func f;
Var x, y;
f(x, y) = x + y;
f.parallel(x);
// Having more threads than tasks shouldn't hurt performance too much.
double correct_time = 0;
for (int t = 2; t <= 64; t *= 2) {
std::ostringstream ss;
ss << "HL_NUM_THREADS=" << t;
std::string str = ss.str();
char buf[32] = {0};
memcpy(buf, str.c_str(), str.size());
putenv(buf);
Halide::Internal::JITSharedRuntime::release_all();
f.compile_jit();
// Start the thread pool without giving any hints as to the
// number of tasks we'll be using.
f.realize(t, 1);
double min_time = 1e20;
for (int i = 0; i < 3; i++) {
double t1 = current_time();
f.realize(2, 1000000);
double t2 = current_time() - t1;
if (t2 < min_time) min_time = t2;
}
printf("%d: %f ms\n", t, min_time);
if (t == 2) {
correct_time = min_time;
} else if (min_time > correct_time * 5) {
printf("Unacceptable overhead when using %d threads for 2 tasks: %f ms vs %f ms\n",
t, min_time, correct_time);
return -1;
}
}
printf("Success!\n");
return 0;
}
示例3: main
int main(int argc, char **argv) {
Func f;
Var x;
f(x) = sin(x);
f.compute_root();
const int N = 9;
std::vector<Expr> exprs;
for (int i = 0; i < N; i++) {
exprs.push_back(f(i));
}
exprs = bitonic_sort(exprs);
std::cout << exprs.size() << "\n";
// Use update definitions to write them to another Func in sorted
// order for inspection. Note that doing this doesn't explicitly
// share work between each element - it'll generate the huge
// min/max expression to extract each sorted element. llvm should
// lift out common subexpressions though.
Func g;
g(x) = undef<float>();
for (int i = 0; i < N; i++) {
g(i) = exprs[i];
}
Buffer<float> result = g.realize(N);
for (int i = 0; i < N; i++) {
printf("%f ", result(i));
}
printf("\n");
for (int i = 0; i < N-1; i++) {
if (result(i) >= result(i+1)) {
printf("Results were not in order\n");
return -1;
}
}
return 0;
}
示例4: main
int main(int argc, char **argv) {
Var x, y;
const int size = 32;
Image<double> noise(size, size);
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
noise(j,i) = (double)rand() / RAND_MAX;
}
}
// Define a seam carving-esque energy
// The meaning of this depends on the interleaving of the x and y
// dimensions during the reduction update
Func clamped;
clamped(x, y) = noise(clamp(x, 0, size-1), clamp(y, 0, size-1));
Func energy;
RDom ry(1, noise.height()-1);
energy(x, y) = clamped(x, y);
Expr xm = clamp(x-1, 0, size-1);
Expr xp = clamp(x+1, 0, size-1);
energy(x, ry) = clamped(x, ry) + min(min(energy(xm, ry-1), energy(x, ry-1)), energy(xp, ry-1));
Image<double> im_energy = energy.realize(size,size);
Image<double> ref_energy(noise);
for (int y = 1; y < size; y++) {
for (int x = 0; x < size; x++) {
int xm = std::max(x-1, 0);
int xp = std::min(x+1, size-1);
double incr = std::min(ref_energy(xm, y-1), std::min(ref_energy(x, y-1), ref_energy(xp, y-1)));
ref_energy(x, y) += incr;
if (ref_energy(x,y) != im_energy(x,y)) {
printf("energy(%d,%d) was %f instead of %f\n", x, y, im_energy(x,y), ref_energy(x,y));
return -1;
}
}
}
printf("Success!\n");
return 0;
}
示例5: rdom_wrapper_test
int rdom_wrapper_test() {
Func source("source"), g("g"), result("result");
Var x("x"), y("y");
source(x, y) = x + y;
ImageParam img(Int(32), 2, "img");
Buffer<int> buf = source.realize(200, 200);
img.set(buf);
g(x, y) = 10;
g(x, y) += 2 * img(x, x);
g(x, y) += 3 * img(y, y);
// Make a global wrapper on 'g', so that we can schedule initialization
// and the update on the same compute level at the global wrapper
Func wrapper = g.in().compute_root();
g.compute_at(wrapper, x);
Func img_f = img;
img_f.compute_root();
// Check the call graphs.
// Expect 'wrapper' to call 'g', initialization of 'g' to call nothing
// and its update to call 'img_f' and 'g', 'img_f' to call 'img'
Module m = wrapper.compile_to_module({wrapper.infer_arguments()});
CheckCalls c;
m.functions().front().body.accept(&c);
CallGraphs expected = {
{g.name(), {img_f.name(), g.name()}},
{wrapper.name(), {g.name()}},
{img_f.name(), {img.name()}},
};
if (check_call_graphs(c.calls, expected) != 0) {
return -1;
}
Buffer<int> im = wrapper.realize(200, 200);
auto func = [](int x, int y) { return 4*x + 6* y + 10; };
if (check_image(im, func)) {
return -1;
}
return 0;
}
示例6: main
int main(int argc, char **argv) {
ImageParam input(UInt(8), 1);
input.dim(0).set_bounds(0, size);
{
Func f;
Var x;
f(x) = input(x);
// Output must have the same size as the input.
f.output_buffer().dim(0).set_bounds(input.dim(0).min(), input.dim(0).extent());
f.add_custom_lowering_pass(new Validator);
f.compile_jit();
Buffer<uint8_t> dummy(size);
dummy.fill(42);
input.set(dummy);
Buffer<uint8_t> out = f.realize(size);
if (!out.all_equal(42)) {
std::cerr << "wrong output" << std::endl;
exit(-1);
}
}
{
Func f;
Var x;
f(x) = undef(UInt(8));
RDom r(input);
f(r.x) = cast<uint8_t>(42);
f.add_custom_lowering_pass(new Validator);
f.compile_jit();
Buffer<uint8_t> dummy(size);
input.set(dummy);
Buffer<uint8_t> out = f.realize(size);
if (!out.all_equal(42)) {
std::cerr << "wrong output" << std::endl;
exit(-1);
}
}
std::cout << "Success!" << std::endl;
return 0;
}
示例7: ShiftBilinearDataTest
bool ShiftBilinearDataTest(bool create, int width, int height, View::Format format, const Func & f)
{
bool result = true;
Data data(f.description);
std::cout << (create ? "Create" : "Verify") << " test " << f.description << " [" << width << ", " << height << "]." << std::endl;
View s(width, height, format, NULL, TEST_ALIGN(width));
View b(width, height, format, NULL, TEST_ALIGN(width));
View d1(width, height, format, NULL, TEST_ALIGN(width));
View d2(width, height, format, NULL, TEST_ALIGN(width));
const double dx = -5.3, dy = 3.7;
const int crop = 3;
if(create)
{
FillRandom(s);
FillRandom(b);
TEST_SAVE(s);
TEST_SAVE(b);
f.Call(s, b, dx, dy, crop, crop, width - crop, height - crop, d1);
TEST_SAVE(d1);
}
else
{
TEST_LOAD(s);
TEST_LOAD(b);
TEST_LOAD(d1);
f.Call(s, b, dx, dy, crop, crop, width - crop, height - crop, d2);
TEST_SAVE(d2);
result = result && Compare(d1, d2, 0, true, 64);
}
return result;
}
示例8: main
int main(int argc, char **argv) {
Param<float> reservoirConcentration;
Param<float> stepTime;
Param<float> layerMixConst;
Param<float> layerTimeDivisor;
Func sumDx;
Func layerMixed;
Func initialDeveloperMirrored;
ImageParam devConc(type_of<float>(),2);
Func dDevelConc;
Func developerConcentration = lambda(x,y,devConc(x,y));
dDevelConc = calcLayerMix(developerConcentration, layerMixConst, stepTime,
layerTimeDivisor, reservoirConcentration);
std::vector<Argument> ddcArgs = dDevelConc.infer_arguments();
dDevelConc.compile_to_file("calcLayerMix",ddcArgs);
return 0;
}
示例9: blur
Func blur(Func input, Expr sigma, Expr width, Expr height) {
// Compute IIR coefficients using the method of Young and Van Vliet.
Func coeff;
Expr q = select(sigma < 2.5f,
3.97156f - 4.14554f*sqrt(1 - 0.26891f*sigma),
0.98711f*sigma - 0.96330f);
Expr denom = 1.57825f + 2.44413f*q + 1.4281f*q*q + 0.422205f*q*q*q;
coeff(x) = undef<float>();
coeff(1) = (2.44413f*q + 2.85619f*q*q + 1.26661f*q*q*q)/denom;
coeff(2) = -(1.4281f*q*q + 1.26661f*q*q*q)/denom;
coeff(3) = (0.422205f*q*q*q)/denom;
coeff(0) = 1 - (coeff(1) + coeff(2) + coeff(3));
coeff.compute_root();
Func blurY, blurX;
blurY = blur_then_transpose(input, coeff, height, sigma);
blurX = blur_then_transpose(blurY, coeff, width, sigma);
return blurX;
}
示例10: new
Func* Func::clone(Class* cls, const StringData* name) const {
auto numParams = this->numParams();
Func* f = new (allocFuncMem(
m_name,
numParams,
isClosureBody(),
cls || !preClass())) Func(*this);
f->initPrologues(numParams);
f->m_funcId = InvalidFuncId;
if (name) {
f->m_name = name;
}
if (cls != f->m_cls) {
f->m_cls = cls;
}
f->setFullName(numParams);
f->m_profCounter = 0;
return f;
}
示例11: footprintOfFuncInExpr
std::vector<int> Expr::footprint(const Func& f) const {
MLVal fp = footprintOfFuncInExpr(f.name(), contents->node);
assert(!listEmpty(fp));
std::vector<int> footprint;
for (; !listEmpty(fp); fp = listTail(fp)) {
footprint.push_back(int(listHead(fp)));
}
return footprint;
}
示例12: AnyToAnyAutoTest
bool AnyToAnyAutoTest(int width, int height, View::Format srcType, View::Format dstType, const Func & f1, const Func & f2)
{
bool result = true;
TEST_LOG_SS(Info, "Test " << f1.description << " & " << f2.description << " for size [" << width << "," << height << "].");
View src(width, height, srcType, NULL, TEST_ALIGN(width));
FillRandom(src);
View dst1(width, height, dstType, NULL, TEST_ALIGN(width));
View dst2(width, height, dstType, NULL, TEST_ALIGN(width));
TEST_EXECUTE_AT_LEAST_MIN_TIME(f1.Call(src, dst1));
TEST_EXECUTE_AT_LEAST_MIN_TIME(f2.Call(src, dst2));
result = result && Compare(dst1, dst2, 0, true, 64);
return result;
}
示例13: main
int main(int argc, char **argv) {
ImageParam input(Float(32), 2);
Var x, y, z;
RDom dom(0, input.width()*8);
Func f;
Expr hard_to_reason_about = cast<int>(hypot(input.width(), input.height()));
f(x, y, z) = 1;
f(x, y, dom / hard_to_reason_about) += 1;
f.compile_jit();
Image<float> im(32, 32);
input.set(im);
f.realize(100, 100, 16);
printf("Success!\n");
return 0;
}
示例14: ifft2_c2r
//Convolution
Func ifft2_c2r(Func input, int W, int H) {
Target target = get_target_from_environment();
Fft2dDesc fwd_desc;
Fft2dDesc inv_desc;
inv_desc.gain = 1.0f/(W*H);
//Make complex
ComplexFunc input_complex;
input_complex(x, y, c) = {input(x, y, c, 0), input(x, y, c, 1)};
// Compute the inverse DFT
Func res = fft2d_c2r(input_complex, W, H, target, inv_desc);
//Schedule
res.compute_root();
return res;
}
示例15: StretchGrayDataTest
bool StretchGrayDataTest(bool create, int width, int height, const Func & f, int stretch)
{
bool result = true;
Data data(f.description);
std::cout << (create ? "Create" : "Verify") << " test " << f.description << " [" << width << ", " << height << "]." << std::endl;
const int stretchedWidth = width*stretch;
const int stretchedHeight = height*stretch;
View s(width, height, View::Gray8, NULL, TEST_ALIGN(width));
View d1(stretchedWidth, stretchedHeight, View::Gray8, NULL, TEST_ALIGN(stretchedWidth));
View d2(stretchedWidth, stretchedHeight, View::Gray8, NULL, TEST_ALIGN(stretchedWidth));
if(create)
{
FillRandom(s);
TEST_SAVE(s);
f.Call(s, d1);
TEST_SAVE(d1);
}
else
{
TEST_LOAD(s);
TEST_LOAD(d1);
f.Call(s, d2);
TEST_SAVE(d2);
result = result && Compare(d1, d2, 0, true, 64);
}
return result;
}