summaryrefslogtreecommitdiffstats
path: root/test/com/jogamp/opencl/TestUtils.java
blob: e2ef16f3ea08dcb5a1c47e9a6ea8eee82e248980 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.jogamp.opencl;

import java.nio.ByteBuffer;
import java.util.Random;

import static java.lang.System.*;
import static org.junit.Assert.*;

/**
 * @author Michael Bien
 */
public class TestUtils {

    //decrease this value on systems with few memory.
    final static int ONE_MB = 1048576;

    final static int NUM_ELEMENTS = 10000000;

    public static final void fillBuffer(ByteBuffer buffer, int seed) {

        Random rnd = new Random(seed);

        while(buffer.remaining() != 0)
            buffer.putInt(rnd.nextInt());

        buffer.rewind();
    }

    public static final int roundUp(int groupSize, int globalSize) {
        int r = globalSize % groupSize;
        if (r == 0) {
            return globalSize;
        } else {
            return globalSize + groupSize - r;
        }
    }

    public static final void checkIfEqual(ByteBuffer a, ByteBuffer b, int elements) {
        for(int i = 0; i < elements; i++) {
            int aVal = a.getInt();
            int bVal = b.getInt();
            if(aVal != bVal) {
                out.println("a: "+aVal);
                out.println("b: "+bVal);
                out.println("position: "+a.position());
                fail("a!=b");
            }
        }
        a.rewind();
        b.rewind();
    }
}