def test_gpu(): from neon.backends.nervanagpu import NervanaGPU ng = NervanaGPU() # test_nms((ng, nc), (0.1, 5)) import datetime time_old = datetime.datetime.now() score = 4 box_count = 5 thre = 0.1 for i in range(10000): dets = np.asarray( [[1, 2, 3, 4, 0.6], [1, 3, 3, 4, 0.7], [1, 1, 4, 4, 0.9], [2, 1, 4, 4, 0.85], [1, 1, 3, 4, 0.85]], dtype=np.float32) # print(dets) dets[:, score] = np.sort(np.random.random((box_count,)))[::-1] dets_ng = ng.array(dets) scores = dets_ng[:, 4].get() order = scores.argsort()[::-1] sorted_dets_dev = dets_ng[order, :] keep_ng = ng.nms(sorted_dets_dev, thre) # print("gpu nms", keep_ng) print('requests gpu', (datetime.datetime.now() - time_old).microseconds)
def test_slicing(fargs_tests): dims, dtype = fargs_tests gpu = NervanaGPU(default_dtype=dtype) cpu = NervanaCPU(default_dtype=dtype) array_np = np.random.uniform(-1, 1, dims).astype(dtype) array_ng = gpu.array(array_np, dtype=dtype) array_nc = cpu.array(array_np, dtype=dtype) assert_tensors_allclose(array_ng[0], array_nc[0], rtol=0, atol=1e-3) assert_tensors_allclose(array_ng[-1], array_nc[-1], rtol=0, atol=1e-3) assert_tensors_allclose(array_ng[0, :], array_nc[0, :], rtol=0, atol=1e-3) assert_tensors_allclose(array_ng[0:], array_nc[0:], rtol=0, atol=1e-3) assert_tensors_allclose(array_ng[:-1], array_nc[:-1], rtol=0, atol=1e-3) assert_tensors_allclose(array_ng[:, 0], array_nc[:, 0], rtol=0, atol=1e-3) assert_tensors_allclose(array_ng[:, 0:1], array_nc[:, 0:1], rtol=0, atol=1e-3) assert_tensors_allclose(array_ng[-1, 0:], array_nc[-1:, 0:], rtol=0, atol=1e-3) array_ng[0] = 0 array_nc[0] = 0 assert_tensors_allclose(array_ng, array_nc, rtol=0, atol=1e-3) del(gpu)