本文整理汇总了C++中Param::set方法的典型用法代码示例。如果您正苦于以下问题:C++ Param::set方法的具体用法?C++ Param::set怎么用?C++ Param::set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Param
的用法示例。
在下文中一共展示了Param::set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char **argv) {
Var x("x");
Func f("f");
Param<float> u;
f(x) = u;
Target target = get_target_from_environment();
if (target.features & Target::CUDA) {
f.cuda_tile(x, 256);
}
u.set(17.0f);
Image<float> out_17 = f.realize(1024);
u.set(123.0f);
Image<float> out_123 = f.realize(1024);
for (int i = 0; i < 1024; i++) {
if (out_17(i) != 17.0f || out_123(i) != 123.0f) {
printf("Failed!\n");
for (int i = 0; i < 1024; i++) {
printf("%f %f\n", out_17(i), out_123(i));
}
return -1;
}
}
printf("Success!\n");
return 0;
}
示例2: main
int main(int argc, char **argv) {
Var x("x");
Func f("f");
Param<float> u;
f(x) = u;
std::string target = get_target();
if (target == "ptx" || target == "ptx-debug") {
f.cuda_tile(x, 256);
}
u.set(17.0f);
Image<float> out_17 = f.realize(1024);
u.set(123.0f);
Image<float> out_123 = f.realize(1024);
for (int i = 0; i < 1024; i++) {
if (out_17(i) != 17.0f || out_123(i) != 123.0f) {
printf("Failed!\n");
for (int i = 0; i < 1024; i++) {
printf("%f %f\n", out_17(i), out_123(i));
}
return -1;
}
}
printf("Success!\n");
return 0;
}
示例3: simple_rfactor_with_specialize_test
int simple_rfactor_with_specialize_test(bool compile_module) {
Func f("f"), g("g");
Var x("x"), y("y");
f(x, y) = x + y;
f.compute_root();
g(x, y) = 40;
RDom r(10, 20, 30, 40);
g(r.x, r.y) = min(f(r.x, r.y) + 2, g(r.x, r.y));
Param<int> p;
Var u("u");
Func intm = g.update(0).specialize(p >= 10).rfactor(r.y, u);
intm.compute_root();
intm.vectorize(u, 8);
intm.update(0).vectorize(r.x, 2);
if (compile_module) {
p.set(20);
// Check the call graphs.
Module m = g.compile_to_module({g.infer_arguments()});
CheckCalls checker;
m.functions().front().body.accept(&checker);
CallGraphs expected = {
{g.name(), {}},
{g.update(0).name(), {f.name(), intm.name(), g.name()}},
{intm.name(), {}},
{intm.update(0).name(), {f.name(), intm.name()}},
{f.name(), {}},
};
if (check_call_graphs(checker.calls, expected) != 0) {
return -1;
}
} else {
{
p.set(0);
Image<int> im = g.realize(80, 80);
auto func = [](int x, int y, int z) {
return (10 <= x && x <= 29) && (30 <= y && y <= 69) ? std::min(x + y + 2, 40) : 40;
};
if (check_image(im, func)) {
return -1;
}
}
{
p.set(20);
Image<int> im = g.realize(80, 80);
auto func = [](int x, int y, int z) {
return (10 <= x && x <= 29) && (30 <= y && y <= 69) ? std::min(x + y + 2, 40) : 40;
};
if (check_image(im, func)) {
return -1;
}
}
}
return 0;
}
示例4: tuple_memoize_test
int tuple_memoize_test(bool toggle_val, int index) {
buffer_index = index;
Param<bool> toggle;
Func f1("f1_" + std::to_string(index)), f2("f2_" + std::to_string(index));
Var x;
f1(x) = Tuple(2*x, 2*x);
f2(x) = Tuple(select(toggle, f1(x)[0], 1),
select(toggle, f1(x)[1], 1));
f1.compute_root().memoize();
f2.set_custom_trace(&single_toggle_trace);
f1.trace_stores();
f2.compile_jit();
set_toggle1 = toggle_val;
toggle.set(set_toggle1);
Realization out = f2.realize(128);
Image<int> out0 = out[0];
Image<int> out1 = out[1];
if (check_correctness_single(out0, set_toggle1) != 0) {
return -1;
}
if (check_correctness_single(out1, set_toggle1) != 0) {
return -1;
}
return 0;
}
示例5: main
int main(int argc, char **argv) {
ImageParam im1(UInt(8), 1);
Buffer<uint8_t> im2(10), im3(20);
Param<int> j;
assert(im1.dimensions() == 1);
assert(im2.dimensions() == 1);
assert(im3.dimensions() == 1);
Func f;
Var x;
f(x) = x + im1.width();
RDom r(0, clamp(im2(j), 0, 99));
f(r) = 37;
im2(3) = 10;
j.set(3);
im1.set(im3);
Buffer<int> result = f.realize(100);
for (int i = 0; i < 100; i++) {
int correct = i < im2(3) ? 37 : (i+20);
if (result(i) != correct) {
printf("result(%d) = %d instead of %d\n", i, result(i), correct);
return -1;
}
}
printf("Success!\n");
return 0;
}
示例6: non_trivial_allocate_predicate_test
int non_trivial_allocate_predicate_test(bool toggle_val, int index) {
buffer_index = index;
Param<bool> toggle;
Func f1("f1_" + std::to_string(index)), f2("f2_" + std::to_string(index));
Func f3("f3_" + std::to_string(index));
Var x;
// Generate allocate f1[...] if toggle
f1(x) = 2*x;
f2(x) = select(toggle, f1(x), 1);
f3(x) = select(toggle, f2(x), 1);
f1.compute_root().memoize();
f2.compute_root().memoize();
f3.set_custom_trace(&double_toggle_trace);
f1.trace_stores();
f2.trace_stores();
f3.compile_jit();
set_toggle1 = toggle_val;
set_toggle2 = toggle_val;
toggle.set(set_toggle1);
Image<int> out = f3.realize(10);
if (check_correctness_single(out, set_toggle1) != 0) {
return -1;
}
return 0;
}
示例7: single_memoize_test
int single_memoize_test(bool toggle_val, int index) {
buffer_index = index;
Param<bool> toggle;
Func f1("f1_" + std::to_string(index)), f2("f2_" + std::to_string(index));
Var x;
f1(x) = 2*x;
f2(x) = select(toggle, f1(x), 1);
f1.compute_root().memoize();
f2.set_custom_trace(&single_toggle_trace);
f1.trace_stores();
f2.compile_jit();
set_toggle1 = toggle_val;
toggle.set(set_toggle1);
Image<int> out = f2.realize(10);
if (check_correctness_single(out, set_toggle1) != 0) {
return -1;
}
return 0;
}
示例8: check
void check(MemoryType t1, MemoryType t2, MemoryType t3) {
Var x;
// By default, small constant-sized allocations, or
// allocations that can be bounded with a small constant size,
// go on the stack. Other allocations go on the heap.
Func f1, f2, f3;
f1(x) = x;
f1.compute_root().store_in(t1);
f2(x) = x;
f2.compute_root().store_in(t2);
f3(x) = x;
f3.compute_root().store_in(t3);
Func f;
Param<bool> p;
f(x) = (f1(0) + f1(1)) + f2(select(p, 0, 2)) + f2(0) + f3(x % 1000);
p.set(true);
int expected_mallocs = ((t1 == MemoryType::Heap ? 1 : 0) +
(t2 == MemoryType::Heap ? 1 : 0) +
(t3 == MemoryType::Heap ? 1 : 0));
mallocs = 0;
f.set_custom_allocator(my_malloc, my_free);
f.realize(1024);
if (mallocs != expected_mallocs) {
std::cerr << "Wrong number of mallocs for " << t1 << ", " << t2 << ", " << t3 << "\n"
<< "Expected " << expected_mallocs << " got " << mallocs << "\n";
exit(-1);
}
}
示例9: main
int main(int argc, char **argv) {
Var x, y, z;
Func f;
Param<int> k;
k.set(3);
f(x, y, z) = x*y+z*k+1;
f.parallel(x);
f.parallel(y);
f.parallel(z);
Image<int> im = f.realize(64, 64, 64);
for (int x = 0; x < 64; x++) {
for (int y = 0; y < 64; y++) {
for (int z = 0; z < 64; z++) {
if (im(x, y, z) != x*y+z*3+1) {
printf("im(%d, %d, %d) = %d\n", x, y, z, im(x, y, z));
return -1;
}
}
}
}
printf("Success!\n");
return 0;
}
示例10: main
int main(int argc, char **argv) {
// Define a pipeline that dumps some squares to a file using an
// external consumer stage.
Func source;
Var x;
source(x) = x*x;
Param<int> min, extent;
Param<const char *> filename;
Func sink;
std::vector<ExternFuncArgument> args;
args.push_back(source);
args.push_back(filename);
args.push_back(min);
args.push_back(extent);
sink.define_extern("dump_to_file", args, Int(32), 0);
source.compute_root();
sink.compile_jit();
// Dump the first 10 squares to a file
filename.set("halide_test_extern_consumer.txt");
min.set(0);
extent.set(10);
sink.realize();
if (!check_result())
return -1;
// Test ImageParam ExternFuncArgument via passed in image.
Image<int32_t> buf = source.realize(10);
ImageParam passed_in(Int(32), 1);
passed_in.set(buf);
Func sink2;
std::vector<ExternFuncArgument> args2;
args2.push_back(passed_in);
args2.push_back(filename);
args2.push_back(min);
args2.push_back(extent);
sink2.define_extern("dump_to_file", args2, Int(32), 0);
sink2.realize();
if (!check_result())
return -1;
printf("Success!\n");
return 0;
}
示例11: CoordXform
CoordXform() : m0("m0"), m1("m1"), m2("m2"), m3("m3"), m4("m4"), m5("m5") {
m0.set(m[0]);
m1.set(m[1]);
m2.set(m[2]);
m3.set(m[3]);
m4.set(m[4]);
m5.set(m[5]);
}
示例12: main
int main(int argc, char **argv) {
Param<float> val;
Func f, g;
Var x, y;
f(x, y) = val + cast<uint8_t>(x);
g(x, y) = f(x, y) + f(x - 1, y) + f(x + 1, y);
g.split(y, y, _, 16);
f.store_root();
f.compute_at(g, y).memoize();
val.set(23.0f);
Image<uint8_t> out = g.realize(128, 128);
for (int32_t i = 0; i < 128; i++) {
for (int32_t j = 0; j < 128; j++) {
assert(out(i, j) == (uint8_t)(3 * 23 + i + (i - 1) + (i + 1)));
}
}
}
示例13: main
int main(int argc, char **argv) {
Var x, y, z;
Func f, g;
Param<int> k;
k.set(3);
f(x, y, z) = x*y+z*k+1;
g(x, y, z) = f(x, y, z) + 2;
f.parallel(x);
f.parallel(y);
g.parallel(z);
f.compute_at(g, z);
auto target = get_jit_target_from_environment();
if (target.features_any_of({Target::HVX_64, Target::HVX_128})) {
g.hexagon().vectorize(x, 32);
f.vectorize(x, 32);
}
Buffer<int> im = g.realize(64, 64, 64);
for (int x = 0; x < 64; x++) {
for (int y = 0; y < 64; y++) {
for (int z = 0; z < 64; z++) {
if (im(x, y, z) != x*y+z*3+3) {
printf("im(%d, %d, %d) = %d\n", x, y, z, im(x, y, z));
return -1;
}
}
}
}
printf("Success!\n");
return 0;
}
示例14: main
int main(int argc, char **argv) {
Var x;
Func f;
Param<int> k;
k.set(3);
f(x) = x*k;
f.parallel(x);
Buffer<int> im = f.realize(16);
for (int i = 0; i < 16; i++) {
if (im(i) != i*3) {
printf("im(%d) = %d\n", i, im(i));
return -1;
}
}
printf("Success!\n");
return 0;
}
示例15: run
static int run(int argc, char **argv) {
static const MeCab::Option long_options[] = {
{ "dicdir", 'd', ".", "DIR", "set DIR as dicdir(default \".\" )" },
{ "outdir", 'o', ".", "DIR", "set DIR as output dir" },
{ "model", 'm', 0, "FILE", "use FILE as model file" },
{ "version", 'v', 0, 0, "show the version and exit" },
{ "training-algorithm", 'a', "crf", "(crf|hmm)",
"set training algorithm" },
{ "default-emission-cost", 'E', "4000", "INT",
"set default emission cost for HMM" },
{ "default-transition-cost", 'T', "4000", "INT",
"set default transition cost for HMM" },
{ "help", 'h', 0, 0, "show this help and exit." },
{ 0, 0, 0, 0 }
};
Param param;
if (!param.open(argc, argv, long_options)) {
std::cout << param.what() << "\n\n" << COPYRIGHT
<< "\ntry '--help' for more information." << std::endl;
return -1;
}
if (!param.help_version()) return 0;
ContextID cid;
DecoderFeatureIndex fi;
DictionaryRewriter rewrite;
const std::string dicdir = param.get<std::string>("dicdir");
const std::string outdir = param.get<std::string>("outdir");
const std::string model = param.get<std::string>("model");
#define DCONF(file) create_filename(dicdir, std::string(file)).c_str()
#define OCONF(file) create_filename(outdir, std::string(file)).c_str()
CHECK_DIE(param.load(DCONF(DICRC)))
<< "no such file or directory: " << DCONF(DICRC);
std::string charset;
{
Dictionary dic;
CHECK_DIE(dic.open(DCONF(SYS_DIC_FILE), "r"));
charset = dic.charset();
CHECK_DIE(!charset.empty());
}
int default_emission_cost = 0;
int default_transition_cost = 0;
std::string type = param.get<std::string>("training-algorithm");
toLower(&type);
if (type == "hmm") {
default_emission_cost =
param.get<int>("default-emission-cost");
default_transition_cost =
param.get<int>("default-transition-cost");
CHECK_DIE(default_transition_cost > 0)
<< "default transition cost must be > 0";
CHECK_DIE(default_emission_cost > 0)
<< "default transition cost must be > 0";
param.set("identity-template", 1);
}
CharProperty property;
CHECK_DIE(property.open(param));
property.set_charset(charset.c_str());
const std::string bos = param.get<std::string>("bos-feature");
const int factor = param.get<int>("cost-factor");
std::vector<std::string> dic;
enum_csv_dictionaries(dicdir.c_str(), &dic);
{
CHECK_DIE(dicdir != outdir) <<
"output directory = dictionary directory! "
"Please specify different directory.";
CHECK_DIE(!outdir.empty()) << "output directory is empty";
CHECK_DIE(!model.empty()) << "model file is empty";
CHECK_DIE(fi.open(param)) << fi.what();
CHECK_DIE(factor > 0) << "cost factor needs to be positive value";
CHECK_DIE(!bos.empty()) << "bos-feature is empty";
CHECK_DIE(dic.size()) << "no dictionary is found in " << dicdir;
CHECK_DIE(rewrite.open(DCONF(REWRITE_FILE)));
}
gencid_bos(bos, &rewrite, &cid);
gencid(DCONF(UNK_DEF_FILE), &rewrite, &cid);
for (std::vector<std::string>::const_iterator it = dic.begin();
it != dic.end();
++it) {
gencid(it->c_str(), &rewrite, &cid);
}
std::cout << "emitting "
<< OCONF(LEFT_ID_FILE) << "/ "
//.........这里部分代码省略.........