def test_from_sequence(self): seq = [list(range(i * 4, i * 4 + 4)) for i in range(5)] reference = torch.arange(0, 20).resize_(5, 4) for t in types: cuda_type = get_gpu_type(t) self.assertEqual(cuda_type(seq), reference)
def test_is_tensor(self): for t in types: tensor = get_gpu_type(t)() self.assertTrue(torch.is_tensor(tensor)) self.assertTrue(torch.is_tensor(torch.cuda.HalfTensor()))
after1 = torch.cuda.FloatTensor(100, device=1).normal_() self.assertEqual(before0, after0, 0) self.assertEqual(before1, after1, 0) def test_nvtx(self): # Just making sure we can see the symbols torch.cuda.nvtx.range_push("foo") torch.cuda.nvtx.mark("bar") torch.cuda.nvtx.range_pop() if HAS_CUDA: for decl in tests: for t in types: tensor = t() gpu_tensor = get_gpu_type(t)() if len(decl) == 3: name, constr, arg_constr = decl desc = '' elif len(decl) == 4: name, constr, arg_constr, desc = decl elif len(decl) == 5: name, constr, arg_constr, desc, type_subset = decl if t not in type_subset: continue precision = custom_precision.get(name, TestCuda.precision) for inplace in (True, False): if inplace: name_inner = name + '_' else: