예제 #1
0
TEST(JIT, CPP_Multi_pre_eval)
{
    const int num = 1 << 16;
    array a = randu(num, s32);
    array b = randu(num, s32);
    array x = a + b;
    array y = a - b;

    eval(x);

    // Should evaluate only y
    eval(x, y);

    // Should not evaluate anything
    // Should not error out
    eval(x, y);

    vector<int> ha(num);
    vector<int> hb(num);
    vector<int> hx(num);
    vector<int> hy(num);

    a.host(&ha[0]);
    b.host(&hb[0]);
    x.host(&hx[0]);
    y.host(&hy[0]);

    for (int i = 0; i < num; i++) {
        ASSERT_EQ((ha[i] + hb[i]), hx[i]);
        ASSERT_EQ((ha[i] - hb[i]), hy[i]);
    }
}
예제 #2
0
TEST(JIT, CPP_strided)
{
    const int num = 1024;
    gforSet(true);
    array a = randu(num, 1, s32);
    array b = randu(1, num, s32);
    array x = a + b;
    array y = a - b;
    eval(x);
    eval(y);
    gforSet(false);

    vector<int> ha(num);
    vector<int> hb(num);
    vector<int> hx(num * num);
    vector<int> hy(num * num);

    a.host(&ha[0]);
    b.host(&hb[0]);
    x.host(&hx[0]);
    y.host(&hy[0]);

    for (int j = 0; j < num; j++) {
        for (int i = 0; i < num; i++) {
            ASSERT_EQ((ha[i] + hb[j]), hx[j*num + i]);
            ASSERT_EQ((ha[i] - hb[j]), hy[j*num + i]);
        }
    }
}
예제 #3
0
TEST(JIT, ISSUE_1646)
{
    array test1 = randn(10, 10);
    array test2 = randn(10);
    array test3 = randn(10);

    for (int i = 0; i < 1000; i++) {
        test3 += sum(test1, 1);
        test2 += test3;
    }
    eval(test2);
    eval(test3);
}
예제 #4
0
TEST(JIT, NonLinearLargeY)
{
    const int d0 = 2;
    // This needs to be > 2 * (1 << 20) to properly check this.
    const int d1 = 3 * (1 << 20);
    array a = randn(d0);
    array b = randn(1, d1);

    // tile is jit-ted for both the operations
    array c = tile(a, 1, d1) + tile(b, d0, 1);
    eval(c);

    vector<float> ha(d0);
    vector<float> hb(d1);
    vector<float> hc(d0 * d1);

    a.host(ha.data());
    b.host(hb.data());
    c.host(hc.data());

    for (int j = 0; j < d1; j++) {
        for (int i = 0; i < d0; i++) {
            ASSERT_EQ(hc[i + j * d0], ha[i] + hb[j]) << " at " << i << " , " << j;
        }
    }
}
예제 #5
0
TEST(JIT, CPP_JIT_HASH)
{
    const int num = 20;
    const float valA = 3;
    const float valB = 5;
    const float valC = 2;
    const float valD = valA + valB;
    const float valE = valA + valC;
    const float valF1 = valD * valE - valE;
    const float valF2 = valD * valE - valD;

    array a = constant(valA, num);
    array b = constant(valB, num);
    array c = constant(valC, num);
    eval(a);
    eval(b);
    eval(c);


    // Creating a kernel
    {
        array d = a + b;
        array e = a + c;
        array f1 = d * e - e;
        float *hF1 = f1.host<float>();

        for (int i = 0; i < num; i++) {
            ASSERT_EQ(hF1[i], valF1);
        }

        freeHost(hF1);
    }

    // Making sure a different kernel is generated
    {
        array d = a + b;
        array e = a + c;
        array f2 = d * e - d;
        float *hF2 = f2.host<float>();

        for (int i = 0; i < num; i++) {
            ASSERT_EQ(hF2[i], valF2);
        }

        freeHost(hF2);
    }
}
예제 #6
0
TEST(JIT, ISSUE_1894)
{
    array a = randu(1);
    array b = tile(a, 2 * (1 << 20));
    eval(b);
    float ha = -100;
    vector<float> hb(b.elements(), -200);

    a.host(&ha);
    b.host(hb.data());

    for (size_t i = 0; i < hb.size(); i++) {
        ASSERT_EQ(ha, hb[i]);
    }
}
예제 #7
0
TEST(JIT, LinearLarge)
{
    // Needs to be larger than 65535 * 256 (or 1 << 24)
    float v1 = std::rand() % 100;
    float v2 = std::rand() % 100;

    array a = constant(v1, 1 << 25);
    array b = constant(v2, 1 << 25);
    array c = (a + b) * (a - b);
    eval(c);

    float v3 = (v1 + v2) * (v1 - v2);

    vector<float> hc(c.elements());
    c.host(hc.data());

    for (size_t i = 0; i < hc.size(); i++) {
        ASSERT_EQ(hc[i], v3);
    }
}
예제 #8
0
TEST(JIT, CPP_Multi_linear)
{
    const int num = 1 << 16;
    array a = randu(num, s32);
    array b = randu(num, s32);
    array x = a + b;
    array y = a - b;
    eval(x, y);

    vector<int> ha(num);
    vector<int> hb(num);
    vector<int> hx(num);
    vector<int> hy(num);

    a.host(&ha[0]);
    b.host(&hb[0]);
    x.host(&hx[0]);
    y.host(&hy[0]);

    for (int i = 0; i < num; i++) {
        ASSERT_EQ((ha[i] + hb[i]), hx[i]);
        ASSERT_EQ((ha[i] - hb[i]), hy[i]);
    }
}