本文整理汇总了C++中Func::args方法的典型用法代码示例。如果您正苦于以下问题:C++ Func::args方法的具体用法?C++ Func::args怎么用?C++ Func::args使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Func
的用法示例。
在下文中一共展示了Func::args方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: repeat_edge
Func repeat_edge(const Func &source,
const std::vector<std::pair<Expr, Expr>> &bounds) {
std::vector<Var> args(source.args());
user_assert(args.size() >= bounds.size()) <<
"repeat_edge called with more bounds (" << bounds.size() <<
") than dimensions (" << args.size() << ") Func " <<
source.name() << "has.\n";
std::vector<Expr> actuals;
for (size_t i = 0; i < bounds.size(); i++) {
Var arg_var = args[i];
Expr min = bounds[i].first;
Expr extent = bounds[i].second;
if (min.defined() && extent.defined()) {
actuals.push_back(clamp(likely(arg_var), min, min + extent - 1));
} else if (!min.defined() && !extent.defined()) {
actuals.push_back(arg_var);
} else {
user_error << "Partially undefined bounds for dimension " << arg_var
<< " of Func " << source.name() << "\n";
}
}
// If there were fewer bounds than dimensions, regard the ones at the end as unbounded.
actuals.insert(actuals.end(), args.begin() + actuals.size(), args.end());
Func bounded("repeat_edge");
bounded(args) = source(actuals);
return bounded;
}
示例2: constant_exterior
Func constant_exterior(const Func &source, Tuple value,
const std::vector<std::pair<Expr, Expr>> &bounds) {
std::vector<Var> args(source.args());
user_assert(args.size() >= bounds.size()) <<
"constant_exterior called with more bounds (" << bounds.size() <<
") than dimensions (" << source.args().size() << ") Func " <<
source.name() << "has.\n";
Expr out_of_bounds = cast<bool>(false);
for (size_t i = 0; i < bounds.size(); i++) {
Var arg_var = source.args()[i];
Expr min = bounds[i].first;
Expr extent = bounds[i].second;
if (min.defined() && extent.defined()) {
out_of_bounds = (out_of_bounds ||
arg_var < min ||
arg_var >= min + extent);
} else if (min.defined() || extent.defined()) {
user_error << "Partially undefined bounds for dimension " << arg_var
<< " of Func " << source.name() << "\n";
}
}
Func bounded("constant_exterior");
if (value.as_vector().size() > 1) {
std::vector<Expr> def;
for (size_t i = 0; i < value.as_vector().size(); i++) {
def.push_back(select(out_of_bounds, value[i], repeat_edge(source, bounds)(args)[i]));
}
bounded(args) = Tuple(def);
} else {
bounded(args) = select(out_of_bounds, value[0], repeat_edge(source, bounds)(args));
}
return bounded;
}
示例3: mirror_interior
Func mirror_interior(const Func &source,
const std::vector<std::pair<Expr, Expr>> &bounds) {
std::vector<Var> args(source.args());
user_assert(args.size() >= bounds.size()) <<
"mirror_interior called with more bounds (" << bounds.size() <<
") than dimensions (" << args.size() << ") Func " <<
source.name() << "has.\n";
std::vector<Expr> actuals;
for (size_t i = 0; i < bounds.size(); i++) {
Var arg_var = args[i];
Expr min = bounds[i].first;
Expr extent = bounds[i].second;
if (min.defined() && extent.defined()) {
Expr limit = extent - 1;
Expr coord = arg_var - min; // Enforce zero origin.
coord = coord % (2 * limit); // Range is 0 to 2w-1
coord = coord - limit; // Range is -w, w
coord = abs(coord); // Range is 0, w
coord = limit - coord; // Range is 0, w
coord = coord + min; // Restore correct min
// The boundary condition probably doesn't apply
coord = select(arg_var < min || arg_var >= min + extent, coord,
clamp(likely(arg_var), min, min + extent - 1));
actuals.push_back(coord);
} else if (!min.defined() && !extent.defined()) {
actuals.push_back(arg_var);
} else {
user_error << "Partially undefined bounds for dimension " << arg_var
<< " of Func " << source.name() << "\n";
}
}
// If there were fewer bounds than dimensions, regard the ones at the end as unbounded.
actuals.insert(actuals.end(), args.begin() + actuals.size(), args.end());
Func bounded("mirror_interior");
bounded(args) = source(actuals);
return bounded;
}
示例4: fft2d_r2c
ComplexFunc fft2d_r2c(Func r,
const vector<int> &R0,
const vector<int> &R1,
const Target& target,
const Fft2dDesc& desc) {
string prefix = desc.name.empty() ? "r2c_" : desc.name + "_";
vector<Var> args(r.args());
Var n0(args[0]), n1(args[1]);
args.erase(args.begin());
args.erase(args.begin());
// Get the innermost variable outside the FFT.
Var outer = Var::outermost();
if (!args.empty()) {
outer = args.front();
}
int N0 = product(R0);
int N1 = product(R1);
// Cache of twiddle factors for this FFT.
TwiddleFactorSet twiddle_cache;
// The gain requested of the FFT.
Expr gain = desc.gain;
// Combine pairs of real columns x, y into complex columns z = x + j y. This
// allows us to compute two real DFTs using one complex FFT. See the large
// comment above this function for more background.
//
// An implementation detail is that we zip the columns in groups from the
// input data to enable the loads to be dense vectors. x is taken from the
// even indexed groups columns, y is taken from the odd indexed groups of
// columns.
//
// Changing the group size can (insignificantly) numerically change the result
// due to regrouping floating point operations. To avoid this, if the FFT
// description specified a vector width, use it as the group size.
ComplexFunc zipped(prefix + "zipped");
int zip_width = desc.vector_width;
if (zip_width <= 0) {
zip_width = target.natural_vector_size(r.output_types()[0]);
}
// Ensure the zip width divides the zipped extent.
zip_width = gcd(zip_width, N0 / 2);
Expr zip_n0 = (n0 / zip_width) * zip_width * 2 + (n0 % zip_width);
zipped(A({n0, n1}, args)) =
ComplexExpr(r(A({zip_n0, n1}, args)),
r(A({zip_n0 + zip_width, n1}, args)));
// DFT down the columns first.
ComplexFunc dft1 = fft_dim1(zipped,
R1,
-1, // sign
std::min(zip_width, N0 / 2), // extent of dim 0
1.0f,
false, // We parallelize unzipped below instead.
prefix,
target,
&twiddle_cache);
// Unzip the two groups of real DFTs we zipped together above. For more
// information about the unzipping operation, see the large comment above this
// function.
ComplexFunc unzipped(prefix + "unzipped"); {
Expr unzip_n0 = (n0 / (zip_width * 2)) * zip_width + (n0 % zip_width);
ComplexExpr Z = dft1(A({unzip_n0, n1}, args));
ComplexExpr conjsymZ = conj(dft1(A({unzip_n0, (N1 - n1) % N1}, args)));
ComplexExpr X = Z + conjsymZ;
ComplexExpr Y = -j * (Z - conjsymZ);
// Rather than divide the above expressions by 2 here, adjust the gain
// instead.
gain /= 2;
unzipped(A({n0, n1}, args)) =
select(n0 % (zip_width * 2) < zip_width, X, Y);
}
// Zip the DC and Nyquist DFT bin rows, which should be real.
ComplexFunc zipped_0(prefix + "zipped_0");
zipped_0(A({n0, n1}, args)) =
select(n1 > 0, likely(unzipped(A({n0, n1}, args))),
ComplexExpr(re(unzipped(A({n0, 0}, args))),
re(unzipped(A({n0, N1 / 2}, args)))));
// The vectorization of the columns must not exceed this value.
int zipped_extent0 = std::min((N1 + 1) / 2, zip_width);
// transpose so we can FFT dimension 0 (by making it dimension 1).
ComplexFunc unzippedT, unzippedT_tiled;
std::tie(unzippedT, unzippedT_tiled) = tiled_transpose(zipped_0, zipped_extent0, target, prefix);
// DFT down the columns again (the rows of the original).
ComplexFunc dftT = fft_dim1(unzippedT,
R0,
-1, // sign
zipped_extent0,
gain,
//.........这里部分代码省略.........