本文整理汇总了C++中af::deviceGC方法的典型用法代码示例。如果您正苦于以下问题:C++ af::deviceGC方法的具体用法?C++ af::deviceGC怎么用?C++ af::deviceGC使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类af
的用法示例。
在下文中一共展示了af::deviceGC方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TEST
TEST(Join, JoinLargeDim) {
using af::constant;
using af::deviceGC;
using af::span;
// const int nx = 32;
const int nx = 1;
const int ny = 4 * 1024 * 1024;
const int nw = 4 * 1024 * 1024;
deviceGC();
{
array in = randu(nx, ny, u8);
array joined = join(0, in, in);
dim4 in_dims = in.dims();
dim4 joined_dims = joined.dims();
ASSERT_EQ(2 * in_dims[0], joined_dims[0]);
ASSERT_EQ(0.f, sum<float>((joined(0, span) - joined(1, span)).as(f32)));
array in2 = constant(1, (dim_t)nx, (dim_t)ny, (dim_t)2, (dim_t)nw, u8);
joined = join(3, in, in);
in_dims = in.dims();
joined_dims = joined.dims();
ASSERT_EQ(2 * in_dims[3], joined_dims[3]);
}
}
示例2: sparseArithTesterMul
void sparseArithTesterMul(const int m, const int n, int factor, const double eps)
{
deviceGC();
if (noDoubleTests<T>()) return;
#if 1
array A = cpu_randu<T>(dim4(m, n));
array B = cpu_randu<T>(dim4(m, n));
#else
array A = randu(m, n, (dtype)dtype_traits<T>::af_type);
array B = randu(m, n, (dtype)dtype_traits<T>::af_type);
#endif
A = makeSparse<T>(A, factor);
array RA = sparse(A, AF_STORAGE_CSR);
array OA = sparse(A, AF_STORAGE_COO);
// Forward
{
// Arith Op
array resR = arith_op<af_mul_t>()(RA, B);
array resO = arith_op<af_mul_t>()(OA, B);
// We will test this by converting the COO to CSR and CSR to COO and
// comparing them. In essense, we are comparing the resR and resO
// TODO: Make a better comparison using dense
// Check resR against conR
array conR = sparseConvertTo(resR, AF_STORAGE_CSR);
sparseCompare<T>(resR, conR, eps);
// Check resO against conO
array conO = sparseConvertTo(resR, AF_STORAGE_COO);
sparseCompare<T>(resO, conO, eps);
}
// Reverse
{
// Arith Op
array resR = arith_op<af_mul_t>()(B, RA);
array resO = arith_op<af_mul_t>()(B, OA);
// We will test this by converting the COO to CSR and CSR to COO and
// comparing them. In essense, we are comparing the resR and resO
// TODO: Make a better comparison using dense
// Check resR against conR
array conR = sparseConvertTo(resR, AF_STORAGE_CSR);
sparseCompare<T>(resR, conR, eps);
// Check resO against conO
array conO = sparseConvertTo(resR, AF_STORAGE_COO);
sparseCompare<T>(resO, conO, eps);
}
}
示例3: sparseArithTesterDiv
void sparseArithTesterDiv(const int m, const int n, int factor, const double eps)
{
deviceGC();
if (noDoubleTests<T>()) return;
#if 1
array A = cpu_randu<T>(dim4(m, n));
array B = cpu_randu<T>(dim4(m, n));
#else
array A = randu(m, n, (dtype)dtype_traits<T>::af_type);
array B = randu(m, n, (dtype)dtype_traits<T>::af_type);
#endif
A = makeSparse<T>(A, factor);
array RA = sparse(A, AF_STORAGE_CSR);
array OA = sparse(A, AF_STORAGE_COO);
// Arith Op
array resR = arith_op<af_div_t>()(RA, B);
array resO = arith_op<af_div_t>()(OA, B);
// Assert division by sparse is not allowed
af_array out_temp = 0;
ASSERT_EQ(AF_ERR_NOT_SUPPORTED, af_div(&out_temp, B.get(), RA.get(), false));
ASSERT_EQ(AF_ERR_NOT_SUPPORTED, af_div(&out_temp, B.get(), OA.get(), false));
if(out_temp != 0) af_release_array(out_temp);
// We will test this by converting the COO to CSR and CSR to COO and
// comparing them. In essense, we are comparing the resR and resO
// TODO: Make a better comparison using dense
// Check resR against conR
array conR = sparseConvertTo(resR, AF_STORAGE_CSR);
sparseCompare<T>(resR, conR, eps);
// Check resO against conO
array conO = sparseConvertTo(resR, AF_STORAGE_COO);
sparseCompare<T>(resO, conO, eps);
}
示例4: sparseArithTester
void sparseArithTester(const int m, const int n, int factor, const double eps)
{
deviceGC();
if (noDoubleTests<T>()) return;
#if 1
array A = cpu_randu<T>(dim4(m, n));
array B = cpu_randu<T>(dim4(m, n));
#else
array A = randu(m, n, (dtype)dtype_traits<T>::af_type);
array B = randu(m, n, (dtype)dtype_traits<T>::af_type);
#endif
A = makeSparse<T>(A, factor);
array RA = sparse(A, AF_STORAGE_CSR);
array OA = sparse(A, AF_STORAGE_COO);
// Arith Op
array resR = arith_op<op>()(RA, B);
array resO = arith_op<op>()(OA, B);
array resD = arith_op<op>()( A, B);
array revR = arith_op<op>()(B, RA);
array revO = arith_op<op>()(B, OA);
array revD = arith_op<op>()(B, A);
ASSERT_NEAR(0, sum<double>(abs(real(resR - resD))) / (m * n), eps);
ASSERT_NEAR(0, sum<double>(abs(imag(resR - resD))) / (m * n), eps);
ASSERT_NEAR(0, sum<double>(abs(real(resO - resD))) / (m * n), eps);
ASSERT_NEAR(0, sum<double>(abs(imag(resO - resD))) / (m * n), eps);
ASSERT_NEAR(0, sum<double>(abs(real(revR - revD))) / (m * n), eps);
ASSERT_NEAR(0, sum<double>(abs(imag(revR - revD))) / (m * n), eps);
ASSERT_NEAR(0, sum<double>(abs(real(revO - revD))) / (m * n), eps);
ASSERT_NEAR(0, sum<double>(abs(imag(revO - revD))) / (m * n), eps);
}