Ejemplo n.º 1
0
        def test_IdpyKernelCU(self):
            cu = CUDA()
            cu.SetDevice()
            tenet = cu.GetTenet()

            grid, block = ((self.n + self.block_size - 1) // self.block_size,
                           1, 1), (self.block_size, 1, 1)

            myTypes = CustomTypes({'SpinType': 'unsigned int'})
            np_c = NpTypes()
            SumOne = self.K_SumOne(custom_types=myTypes.Push(),
                                   constants={'DATA_N': self.n})
            SumOne_Idea = SumOne(tenet=tenet, grid=grid, block=block)

            A = IdpyMemory.Const(self.n,
                                 dtype=np_c.C[myTypes['SpinType']],
                                 const=0,
                                 tenet=tenet)
            print()
            print("A: ", A.D2H(), A.dtype)
            print("SumOne_Idea.Deploy([A])")
            SumOne_Idea.Deploy([A])
            print("A: ", A.D2H(), A.dtype)

            check_array = np.zeros(self.n, dtype=np_c.C[myTypes['SpinType']])
            check_array.fill(1)

            checks = [AllTrue(A.D2H() == check_array)]

            tenet.End()
            self.assertTrue(AllTrue(checks))
Ejemplo n.º 2
0
        def test_IdpyKernelLoopConstCL(self):
            ocl = OpenCL()
            ocl.SetDevice()
            tenet = ocl.GetTenet()

            grid, block = ((self.n + self.block_size - 1) // self.block_size,
                           1, 1), (self.block_size, 1, 1)

            myTypes = CustomTypes({'SpinType': 'unsigned int'})
            np_c = NpTypes()
            SumConst = self.K_SumConst(custom_types=myTypes.Push(),
                                       constants={'DATA_N': self.n})

            A = IdpyMemory.Const(self.n,
                                 dtype=np_c.C[myTypes['SpinType']],
                                 const=0,
                                 tenet=tenet)

            # https://stackoverflow.com/questions/5710690/pycuda-passing-variable-by-value-to-kernel
            mem_dict = {'A': A, 'const': np.int32(self.in_const)}
            SumOne_Loop = IdpyLoop([mem_dict], [[(SumConst(
                tenet=tenet, grid=grid, block=block), ['A', 'const'])]])

            print()
            print("A: ", A.D2H(), A.dtype)
            print("SumOne_Loop.Run(range(1))")
            SumOne_Loop.Run(range(1))
            print("A: ", A.D2H(), A.dtype)
            print("SumOne_Loop.Run(range(8))")
            SumOne_Loop.Run(range(8))
            print("A: ", A.D2H(), A.dtype)

            check_array = np.zeros(self.n, dtype=np_c.C[myTypes['SpinType']])
            check_array.fill(self.in_const * 9)

            checks = []
            checks += [AllTrue(A.D2H() == check_array)]

            tenet.End()
            self.assertTrue(AllTrue(checks))
Ejemplo n.º 3
0
        def test_IdpyKernelLoopCU(self):
            cu = CUDA()
            cu.SetDevice()
            tenet = cu.GetTenet()

            grid, block = ((self.n + self.block_size - 1) // self.block_size,
                           1, 1), (self.block_size, 1, 1)

            myTypes = CustomTypes({'SpinType': 'unsigned int'})
            np_c = NpTypes()
            SumOne = self.K_SumOne(custom_types=myTypes.Push(),
                                   constants={'DATA_N': self.n})

            A = IdpyMemory.Const(self.n,
                                 dtype=np_c.C[myTypes['SpinType']],
                                 const=0,
                                 tenet=tenet)
            mem_dict = {'A': A}
            SumOne_Loop = IdpyLoop(
                [mem_dict],
                [[(SumOne(tenet=tenet, grid=grid, block=block), ['A'])]])

            print()
            print("A: ", A.D2H(), A.dtype)
            print("SumOne_Loop.Run(range(1))")
            SumOne_Loop.Run(range(1))
            print("A: ", A.D2H(), A.dtype)
            print("SumOne_Loop.Run(range(8))")
            SumOne_Loop.Run(range(8))
            print("A: ", A.D2H(), A.dtype)

            check_array = np.zeros(self.n, dtype=np_c.C[myTypes['SpinType']])
            check_array.fill(9)

            checks = []
            checks += [AllTrue(A.D2H() == check_array)]

            tenet.End()
            self.assertTrue(AllTrue(checks))
Ejemplo n.º 4
0
def CheckOCLFP(tenet, custom_types):
    if idpy_langs_sys[OCL_T] and isinstance(tenet, idpy_tenet_types[OCL_T]):
        if tenet.device.get_info(cl.device_info.DOUBLE_FP_CONFIG) == 0:
            print("\nThe device", tenet.device.get_info(cl.device_info.NAME),
                  "does not support 64 bits floating-point variables")
            print("Changing all custom types from 64-bits to 32-bits")
            _swap_dict = {}
            for key, value in custom_types.Push().items():
                if value == 'double':
                    value = 'float'

                _swap_dict[key] = value

            return CustomTypes(_swap_dict)
        else:
            return custom_types
    else:
        return custom_types
Ejemplo n.º 5
0
        def test_IdpyKernelFuncLoopMultStreamCL(self):
            ocl = OpenCL()
            ocl.SetDevice()
            tenet = ocl.GetTenet()

            grid, block = ((self.n + self.block_size - 1) // self.block_size,
                           1, 1), (self.block_size, 1, 1)

            myTypes = CustomTypes({'SpinType': 'unsigned int'})
            np_c = NpTypes()
            SumTwoArrConst = self.K_SumTwoArrays(custom_types=myTypes.Push(),
                                                 constants={'DATA_N': self.n},
                                                 f_classes=[
                                                     self.F_SumTwoArraysPtr,
                                                     self.F_SumTwoArraysRet,
                                                     self.F_SumTwoArraysVal
                                                 ])

            SumConst = self.K_SumConst(custom_types=myTypes.Push(),
                                       constants={'DATA_N': self.n})

            A = IdpyMemory.Const(self.n,
                                 dtype=np_c.C[myTypes['SpinType']],
                                 const=0,
                                 tenet=tenet)

            B = IdpyMemory.Const(self.n,
                                 dtype=np_c.C[myTypes['SpinType']],
                                 const=1,
                                 tenet=tenet)

            C = IdpyMemory.Const(self.n,
                                 dtype=np_c.C[myTypes['SpinType']],
                                 const=2,
                                 tenet=tenet)

            D = IdpyMemory.Const(self.n,
                                 dtype=np_c.C[myTypes['SpinType']],
                                 const=3,
                                 tenet=tenet)

            print()
            print("A: ", A.D2H(), A.dtype)
            print("B: ", B.D2H(), B.dtype)
            print("C: ", C.D2H(), C.dtype)
            print("D: ", D.D2H(), D.dtype)
            '''
            Checking result
            '''
            a, b, c, cc = A.D2H()[0], B.D2H()[0], C.D2H()[0], self.in_const
            d = D.D2H()[0]

            for i in range(2):
                '''first stream'''
                c += cc
                c += a + b
                c += a + b
                c += a + b + cc
                a, c = c, a
                '''second stream'''
                d += cc

            # https://stackoverflow.com/questions/5710690/pycuda-passing-variable-by-value-to-kernel
            ##
            mem_dict_0 = {
                'A': A,
                'B': B,
                'C': C,
                'const': np_c.C[myTypes['SpinType']](self.in_const)
            }
            mem_dict_1 = {
                'D': D,
                'const': np_c.C[myTypes['SpinType']](self.in_const)
            }
            SumTwoArrConst_Loop = IdpyLoop(
                [mem_dict_0, mem_dict_1],
                [[(SumTwoArrConst(tenet=tenet, grid=grid,
                                  block=block), ['A', 'B', 'C', 'const']),
                  (self.M_SwapArrays(tenet), ['A', 'C'])],
                 [
                     (SumConst(tenet=tenet, grid=grid,
                               block=block), ['D', 'const']),
                 ]])

            print()
            print("SumTwoArrConst_Loop.Run(range(2))")
            SumTwoArrConst_Loop.Run(range(2))

            print("A: ", A.D2H(), A.dtype, a)
            print("B: ", B.D2H(), B.dtype, b)
            print("C: ", C.D2H(), C.dtype, c)
            print("D: ", D.D2H(), D.dtype, d)

            checks = []
            check_array = np.full(self.n, a, dtype=np_c.C[myTypes['SpinType']])
            checks += [AllTrue(A.D2H() == check_array)]
            check_array = np.full(self.n, b, dtype=np_c.C[myTypes['SpinType']])
            checks += [AllTrue(B.D2H() == check_array)]
            check_array = np.full(self.n, c, dtype=np_c.C[myTypes['SpinType']])
            checks += [AllTrue(C.D2H() == check_array)]
            check_array = np.full(self.n, d, dtype=np_c.C[myTypes['SpinType']])
            checks += [AllTrue(D.D2H() == check_array)]

            tenet.End()
            self.assertTrue(AllTrue(checks))
Ejemplo n.º 6
0
 def test_CustomTypes_ToList(self):
     myTypes = CustomTypes(self.types_dict)
     test_list = [key for key in self.types_dict]
     self.assertTrue(myTypes.ToList() == test_list)
Ejemplo n.º 7
0
 def test_CustomTypes_Push(self):
     myTypes = CustomTypes(self.types_dict)
     self.assertTrue(myTypes.Push() == self.types_dict)