Beispiel #1
0
def test01(shape):
    data_a = (np.random.randn(*shape)*100).astype(np.float16)
    data_b = (np.random.randn(*shape)*100).astype(np.float16)

    cuda_array_a = nc.array(data_a)
    cuda_array_b = nc.array(data_b)
    x = lambda : data_a+data_b
    y = lambda : cuda_array_a+cuda_array_b

    t1 = timeit.timeit(stmt=x, number=100)
    t2 = timeit.timeit(stmt=y, number=100)

    print("numpy time is:{}s".format(t1))
    print("numcuda time is:{}s".format(t2))
    print("numcuda is {0:.4f}x faster than numpy".format(t1/t2))
Beispiel #2
0
def test_div(shape, dtype):
    if dtype in (np.float16, np.float32, np.float64):
        data_a = np.random.randn(*shape) * 100
        data_a = data_a.astype(dtype)
        data_b = np.random.randn(*shape) * 100
        data_b = data_b.astype(dtype)
    else:
        data_a = np.random.randint(200, size=shape)
        data_b = np.random.randint(200, size=shape)
    cuda_array_a = nc.array(data_a)
    cuda_array_b = nc.array(data_b)

    data_c = data_a / data_b
    cuda_array_c = cuda_array_a / cuda_array_b
    res_data_c = cuda_array_c.asnumpy()

    #assert two array are equal
    np.testing.assert_equal(data_c, res_data_c)
Beispiel #3
0
def test_array(shape, dtype):
    if dtype in (np.float16, np.float32, np.float64):
        data_array = np.random.randn(*shape) * 100
        data_array = data_array.astype(dtype)
    else:
        data_array = np.random.randint(200, size=shape)

    test_data = nc.array(data_array)
    res_data = test_data.asnumpy()

    #assert two array are equal
    np.testing.assert_equal(data_array, res_data)