当前位置: 首页>>代码示例>>Python>>正文


Python cuda.to_device方法代码示例

本文整理汇总了Python中numba.cuda.to_device方法的典型用法代码示例。如果您正苦于以下问题:Python cuda.to_device方法的具体用法?Python cuda.to_device怎么用?Python cuda.to_device使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在numba.cuda的用法示例。


在下文中一共展示了cuda.to_device方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: uniform

# 需要导入模块: from numba import cuda [as 别名]
# 或者: from numba.cuda import to_device [as 别名]
def uniform(size, dtype=np.float, device=False):
    '''Generate floating point random number sampled
    from a uniform distribution

    :param size: Number of samples.
    :param dtype: np.float32 or np.float64.
    :param device: Set to True to return a device array instead or numpy array.

    :returns: A numpy array or a device array.

    >>> from pyculib import rand
    >>> rand.uniform(size=10)
    array([...])

    .. seealso:: :py:meth:`pyculib.rand.PRNG.uniform`
    '''
    ary = np.empty(size, dtype=dtype)
    devary = cuda.to_device(ary, copy=False)
    prng = _get_prng()
    prng.uniform(devary, size)
    if device:
        return devary
    else:
        devary.copy_to_host(ary)
        return ary 
开发者ID:numba,项目名称:pyculib,代码行数:27,代码来源:api.py

示例2: poisson

# 需要导入模块: from numba import cuda [as 别名]
# 或者: from numba.cuda import to_device [as 别名]
def poisson(lmbd, size, device=False):
    '''Generate int32 random number sampled
    from a poisson distribution.

    :param lmbda: Lambda of the distribution.
    :param size:  Number of samples
    :param device: Set to True to return a device array instead or ndarray.
    :returns: A numpy array or a device array.

    >>> from pyculib import rand
    >>> rand.poisson(lmbd=1, size=10)
    array([...], dtype=uint32)

    .. seealso:: :py:meth:`pyculib.rand.PRNG.poisson`
    '''
    ary = np.empty(size, dtype=np.uint32)
    devary = cuda.to_device(ary, copy=False)
    prng = _get_prng()
    prng.poisson(devary, lmbd, size)
    if device:
        return devary
    else:
        devary.copy_to_host(ary)
        return ary 
开发者ID:numba,项目名称:pyculib,代码行数:26,代码来源:api.py

示例3: Taxpy

# 需要导入模块: from numba import cuda [as 别名]
# 或者: from numba.cuda import to_device [as 别名]
def Taxpy(self, fn, dtype):
        from pyculib.blas.binding import cuBlas

        alpha = 1.234
        x = np.random.random(10).astype(dtype)
        y = np.random.random(10).astype(dtype)
        y0 = y.copy()

        d_x = cuda.to_device(x)
        d_y = cuda.to_device(y)

        blas = cuBlas()
        getattr(blas, fn)(x.size, alpha, d_x, 1, d_y, 1)

        d_y.copy_to_host(y)

        self.assertTrue(np.allclose(alpha * x + y0, y)) 
开发者ID:numba,项目名称:pyculib,代码行数:19,代码来源:test_blas_low_level.py

示例4: Trot

# 需要导入模块: from numba import cuda [as 别名]
# 或者: from numba.cuda import to_device [as 别名]
def Trot(self, fn, dtype):
        from pyculib.blas.binding import cuBlas

        x = np.random.random(10).astype(dtype)
        y = np.random.random(10).astype(dtype)
        angle = 1.342
        c = np.cos(angle)
        s = np.sin(angle)

        x0, y0 = c * x + s * y, -s * x + c * y

        d_x = cuda.to_device(x)
        d_y = cuda.to_device(y)

        blas = cuBlas()
        getattr(blas, fn)(x.size, d_x, 1, d_y, 1, c, s)

        d_x.copy_to_host(x)
        d_y.copy_to_host(y)

        self.assertTrue(np.allclose(x, x0))
        self.assertTrue(np.allclose(y, y0)) 
开发者ID:numba,项目名称:pyculib,代码行数:24,代码来源:test_blas_low_level.py

示例5: Trotm

# 需要导入模块: from numba import cuda [as 别名]
# 或者: from numba.cuda import to_device [as 别名]
def Trotm(self, fn, dtype):
        from pyculib.blas.binding import cuBlas

        x = np.random.random(10).astype(dtype)
        y = np.random.random(10).astype(dtype)

        param = np.random.random(5).astype(dtype)
        param[0] = -1.0
        h11, h21, h12, h22 = param[1:].tolist()

        x0, y0 = h11 * x + h12 * y, h21 * x + h22 * y

        d_x = cuda.to_device(x)
        d_y = cuda.to_device(y)

        blas = cuBlas()
        getattr(blas, fn)(x.size, d_x, 1, d_y, 1, param)

        d_x.copy_to_host(x)
        d_y.copy_to_host(y)

        self.assertTrue(np.allclose(x, x0))
        self.assertTrue(np.allclose(y, y0)) 
开发者ID:numba,项目名称:pyculib,代码行数:25,代码来源:test_blas_low_level.py

示例6: Tgbmv

# 需要导入模块: from numba import cuda [as 别名]
# 或者: from numba.cuda import to_device [as 别名]
def Tgbmv(self, fn, dtype):
        from pyculib.blas.binding import cuBlas

        blas = cuBlas()
        kl = 0
        ku = 0
        alpha = 1.
        beta = 0.
        A = np.array([[1, 0, 0],
                      [0, 2, 0],
                      [0, 0, 3]], order='F', dtype=dtype)
        x = np.array([1, 2, 3], dtype=dtype)
        y = np.array([1, 2, 3], dtype=dtype)
        lda, n = A.shape
        m = lda
        y0 = y.copy()
        dA = cuda.to_device(A)
        dx = cuda.to_device(x)
        dy = cuda.to_device(y)
        getattr(blas, fn)('N', m, n, kl, ku, alpha, dA, lda, dx, 1, beta, dy, 1)
        dy.copy_to_host(y)
        self.assertFalse(all(y0 == y)) 
开发者ID:numba,项目名称:pyculib,代码行数:24,代码来源:test_blas_low_level.py

示例7: Tgemv

# 需要导入模块: from numba import cuda [as 别名]
# 或者: from numba.cuda import to_device [as 别名]
def Tgemv(self, fn, dtype):
        from pyculib.blas.binding import cuBlas

        blas = cuBlas()
        alpha = 1.
        beta = 0.
        A = np.array([[1, 2, 0],
                      [0, 3, 0],
                      [1, 0, 1]], order='F', dtype=dtype)
        x = np.array([1, 2, 3], dtype=dtype)
        y = np.array([1, 2, 3], dtype=dtype)
        m, n = A.shape
        lda = m
        y0 = y.copy()
        dA = cuda.to_device(A)
        dx = cuda.to_device(x)
        dy = cuda.to_device(y)
        getattr(blas, fn)('N', m, n, alpha, dA, lda, dx, 1, beta, dy, 1)
        dy.copy_to_host(y)
        self.assertFalse(all(y0 == y)) 
开发者ID:numba,项目名称:pyculib,代码行数:22,代码来源:test_blas_low_level.py

示例8: Ttbmv

# 需要导入模块: from numba import cuda [as 别名]
# 或者: from numba.cuda import to_device [as 别名]
def Ttbmv(self, fn, dtype):
        from pyculib.blas.binding import cuBlas

        A = np.array([[1, 2, 0],
                      [0, 3, 0],
                      [1, 0, 1]], order='F', dtype=dtype)
        x = np.array([1, 2, 3], dtype=dtype)
        dA = cuda.to_device(A)
        dx = cuda.to_device(x)

        blas = cuBlas()
        uplo = 'U'
        trans = 'N'
        diag = False
        n = 3
        lda = n
        x0 = x.copy()
        inc = 1
        k = 0
        getattr(blas, fn)(uplo, trans, diag, n, k, dA, lda, dx, inc)
        dx.copy_to_host(x)

        self.assertFalse(all(x == x0)) 
开发者ID:numba,项目名称:pyculib,代码行数:25,代码来源:test_blas_low_level.py

示例9: Ttpmv

# 需要导入模块: from numba import cuda [as 别名]
# 或者: from numba.cuda import to_device [as 别名]
def Ttpmv(self, fn, dtype):
        from pyculib.blas.binding import cuBlas

        AP = np.array([[1, 2, 0],
                       [0, 3, 0],
                       [1, 0, 1]], order='F', dtype=dtype)
        x = np.array([1, 2, 3], dtype=dtype)
        dAP = cuda.to_device(AP)
        dx = cuda.to_device(x)

        blas = cuBlas()
        uplo = 'U'
        trans = 'N'
        diag = False
        n = 3
        x0 = x.copy()
        inc = 1
        getattr(blas, fn)(uplo, trans, diag, n, dAP, dx, inc)
        dx.copy_to_host(x)

        self.assertFalse(all(x == x0)) 
开发者ID:numba,项目名称:pyculib,代码行数:23,代码来源:test_blas_low_level.py

示例10: Ttrsv

# 需要导入模块: from numba import cuda [as 别名]
# 或者: from numba.cuda import to_device [as 别名]
def Ttrsv(self, fn, dtype):
        from pyculib.blas.binding import cuBlas

        A = np.array([[1, 2, 0],
                      [0, 3, 0],
                      [1, 0, 1]], order='F', dtype=dtype)
        x = np.array([1, 2, 3], dtype=dtype)
        dA = cuda.to_device(A)
        dx = cuda.to_device(x)

        blas = cuBlas()
        uplo = 'U'
        trans = 'N'
        diag = False
        lda = n = 3
        x0 = x.copy()
        inc = 1
        getattr(blas, fn)(uplo, trans, diag, n, dA, lda, dx, inc)
        dx.copy_to_host(x)

        self.assertFalse(all(x == x0)) 
开发者ID:numba,项目名称:pyculib,代码行数:23,代码来源:test_blas_low_level.py

示例11: _Ttpsv

# 需要导入模块: from numba import cuda [as 别名]
# 或者: from numba.cuda import to_device [as 别名]
def _Ttpsv(self, fn, dtype):
        from pyculib.blas.binding import cuBlas

        A = np.array([[1, 2, 0],
                      [0, 3, 0],
                      [1, 0, 1]], order='F', dtype=dtype)
        x = np.array([1, 2, 3], dtype=dtype)
        dA = cuda.to_device(A)
        dx = cuda.to_device(x)

        blas = cuBlas()
        uplo = 'U'
        trans = 'N'
        diag = False
        n = 3
        x0 = x.copy()
        inc = 1
        getattr(blas, fn)(uplo, trans, diag, n, dA, dx, inc)
        dx.copy_to_host(x)

        self.assertFalse(all(x == x0)) 
开发者ID:numba,项目名称:pyculib,代码行数:23,代码来源:test_blas_low_level.py

示例12: _Ttbsv

# 需要导入模块: from numba import cuda [as 别名]
# 或者: from numba.cuda import to_device [as 别名]
def _Ttbsv(self, fn, dtype):
        from pyculib.blas.binding import cuBlas

        A = np.array([[1, 2, 0],
                      [0, 3, 0],
                      [1, 0, 1]], order='F', dtype=dtype)
        x = np.array([1, 2, 3], dtype=dtype)
        dA = cuda.to_device(A)
        dx = cuda.to_device(x)

        blas = cuBlas()
        uplo = 'U'
        trans = 'N'
        diag = False
        lda = n = 3
        k = 0
        x0 = x.copy()
        inc = 1
        getattr(blas, fn)(uplo, trans, diag, n, k, dA, lda, dx, inc)
        dx.copy_to_host(x)

        self.assertFalse(all(x == x0)) 
开发者ID:numba,项目名称:pyculib,代码行数:24,代码来源:test_blas_low_level.py

示例13: _Tsbmv

# 需要导入模块: from numba import cuda [as 别名]
# 或者: from numba.cuda import to_device [as 别名]
def _Tsbmv(self, fn, dtype):
        from pyculib.blas.binding import cuBlas

        A = np.array([[1, 2, 0],
                      [0, 3, 0],
                      [1, 0, 1]], order='F', dtype=dtype)
        x = np.array([1, 2, 3], dtype=dtype)
        y = np.array([8, 2, 3], dtype=dtype)
        dA = cuda.to_device(A)
        dx = cuda.to_device(x)
        dy = cuda.to_device(y)

        alpha = 1.2
        beta = .34
        blas = cuBlas()
        uplo = 'U'
        lda = n = 3
        k = 0
        y0 = y.copy()
        incx = incy = 1
        getattr(blas, fn)(uplo, n, k, alpha, dA, lda, dx, incx, beta, dy, incy)
        dy.copy_to_host(y)

        self.assertFalse(all(y == y0)) 
开发者ID:numba,项目名称:pyculib,代码行数:26,代码来源:test_blas_low_level.py

示例14: _Tspmv

# 需要导入模块: from numba import cuda [as 别名]
# 或者: from numba.cuda import to_device [as 别名]
def _Tspmv(self, fn, dtype):
        from pyculib.blas.binding import cuBlas

        AP = np.array([[1, 2, 0],
                       [0, 3, 0],
                       [1, 0, 1]], order='F', dtype=dtype)
        x = np.array([1, 2, 3], dtype=dtype)
        y = np.array([8, 2, 3], dtype=dtype)
        dAP = cuda.to_device(AP)
        dx = cuda.to_device(x)
        dy = cuda.to_device(y)

        alpha = 1.2
        beta = .34
        blas = cuBlas()
        uplo = 'U'
        n = 3
        y0 = y.copy()
        incx = incy = 1
        getattr(blas, fn)(uplo, n, alpha, dAP, dx, incx, beta, dy, incy)
        dy.copy_to_host(y)

        self.assertFalse(all(y == y0)) 
开发者ID:numba,项目名称:pyculib,代码行数:25,代码来源:test_blas_low_level.py

示例15: _Tger

# 需要导入模块: from numba import cuda [as 别名]
# 或者: from numba.cuda import to_device [as 别名]
def _Tger(self, fn, dtype):
        from pyculib.blas.binding import cuBlas

        A = np.array([[1, 2, 0],
                      [0, 3, 0],
                      [1, 0, 1]], order='F', dtype=dtype)
        x = np.array([1, 2, 3], dtype=dtype)
        y = np.array([8, 2, 3], dtype=dtype)
        dA = cuda.to_device(A)
        dx = cuda.to_device(x)
        dy = cuda.to_device(y)

        alpha = 1.2

        blas = cuBlas()

        lda = m = n = 3
        A0 = A.copy()
        incx = incy = 1
        getattr(blas, fn)(m, n, alpha, dx, incx, dy, incy, dA, lda)
        dA.copy_to_host(A)

        self.assertFalse(np.all(A == A0)) 
开发者ID:numba,项目名称:pyculib,代码行数:25,代码来源:test_blas_low_level.py


注:本文中的numba.cuda.to_device方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。