當前位置: 首頁>>代碼示例>>Python>>正文


Python pyopencl.CommandQueue方法代碼示例

本文整理匯總了Python中pyopencl.CommandQueue方法的典型用法代碼示例。如果您正苦於以下問題:Python pyopencl.CommandQueue方法的具體用法?Python pyopencl.CommandQueue怎麽用?Python pyopencl.CommandQueue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pyopencl的用法示例。


在下文中一共展示了pyopencl.CommandQueue方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _get_device

# 需要導入模塊: import pyopencl [as 別名]
# 或者: from pyopencl import CommandQueue [as 別名]
def _get_device(self, gpuid):
        """Return GPU devices, context, and queue."""
        all_platforms = cl.get_platforms()
        platform = next((p for p in all_platforms if
                         p.get_devices(device_type=cl.device_type.GPU) != []),
                        None)
        if platform is None:
            raise RuntimeError('No OpenCL GPU device found.')
        my_gpu_devices = platform.get_devices(device_type=cl.device_type.GPU)
        context = cl.Context(devices=my_gpu_devices)
        if gpuid > len(my_gpu_devices)-1:
            raise RuntimeError(
                'No device with gpuid {0} (available device IDs: {1}).'.format(
                    gpuid, np.arange(len(my_gpu_devices))))
        queue = cl.CommandQueue(context, my_gpu_devices[gpuid])
        if self.settings['debug']:
            print("Selected Device: ", my_gpu_devices[gpuid].name)
        return my_gpu_devices, context, queue 
開發者ID:pwollstadt,項目名稱:IDTxl,代碼行數:20,代碼來源:estimators_opencl.py

示例2: main

# 需要導入模塊: import pyopencl [as 別名]
# 或者: from pyopencl import CommandQueue [as 別名]
def main():
    fn = "matmul.floopy"
    with open(fn, "r") as inf:
        source = inf.read()

    dgemm, = lp.parse_transformed_fortran(source, filename=fn)

    ctx = cl.create_some_context()
    queue = cl.CommandQueue(ctx)

    n = 2048
    a = cl.array.empty(queue, (n, n), dtype=np.float64, order="F")
    b = cl.array.empty(queue, (n, n), dtype=np.float64, order="F")
    c = cl.array.zeros(queue, (n, n), dtype=np.float64, order="F")
    cl.clrandom.fill_rand(a)
    cl.clrandom.fill_rand(b)

    dgemm = lp.set_options(dgemm, write_code=True)

    dgemm(queue, a=a, b=b, alpha=1, c=c)

    c_ref = (a.get() @ b.get())
    assert la.norm(c_ref - c.get())/la.norm(c_ref) < 1e-10 
開發者ID:inducer,項目名稱:loopy,代碼行數:25,代碼來源:matmul-driver.py

示例3: test_globals_decl_once_with_multi_subprogram

# 需要導入模塊: import pyopencl [as 別名]
# 或者: from pyopencl import CommandQueue [as 別名]
def test_globals_decl_once_with_multi_subprogram(ctx_factory):
    ctx = ctx_factory()
    queue = cl.CommandQueue(ctx)
    np.random.seed(17)
    a = np.random.randn(16)
    cnst = np.random.randn(16)
    knl = lp.make_kernel(
            "{[i, ii]: 0<=i, ii<n}",
            """
            out[i] = a[i]+cnst[i]{id=first}
            out[ii] = 2*out[ii]+cnst[ii]{id=second}
            """,
            [lp.TemporaryVariable(
                'cnst', initializer=cnst,
                scope=lp.AddressSpace.GLOBAL,
                read_only=True), '...'])
    knl = lp.fix_parameters(knl, n=16)
    knl = lp.add_barrier(knl, "id:first", "id:second")

    knl = lp.split_iname(knl, "i", 2, outer_tag="g.0", inner_tag="l.0")
    knl = lp.split_iname(knl, "ii", 2, outer_tag="g.0", inner_tag="l.0")
    evt, (out,) = knl(queue, a=a)
    assert np.linalg.norm(out-((2*(a+cnst)+cnst))) <= 1e-15 
開發者ID:inducer,項目名稱:loopy,代碼行數:25,代碼來源:test_loopy.py

示例4: test_save_of_private_scalar

# 需要導入模塊: import pyopencl [as 別名]
# 或者: from pyopencl import CommandQueue [as 別名]
def test_save_of_private_scalar(ctx_factory, hw_loop, debug=False):
    ctx = ctx_factory()
    queue = cl.CommandQueue(ctx)

    knl = lp.make_kernel(
        "{ [i]: 0<=i<8 }",
        """
        for i
            <>t = i
            ... gbarrier
            out[i] = t
        end
        """, seq_dependencies=True)

    if hw_loop:
        knl = lp.tag_inames(knl, dict(i="g.0"))

    save_and_reload_temporaries_test(queue, knl, np.arange(8), debug) 
開發者ID:inducer,項目名稱:loopy,代碼行數:20,代碼來源:test_loopy.py

示例5: test_save_of_private_array

# 需要導入模塊: import pyopencl [as 別名]
# 或者: from pyopencl import CommandQueue [as 別名]
def test_save_of_private_array(ctx_factory, debug=False):
    ctx = ctx_factory()
    queue = cl.CommandQueue(ctx)

    knl = lp.make_kernel(
        "{ [i]: 0<=i<8 }",
        """
        for i
            <>t[i] = i
            ... gbarrier
            out[i] = t[i]
        end
        """, seq_dependencies=True)

    knl = lp.set_temporary_scope(knl, "t", "private")
    save_and_reload_temporaries_test(queue, knl, np.arange(8), debug) 
開發者ID:inducer,項目名稱:loopy,代碼行數:18,代碼來源:test_loopy.py

示例6: test_save_of_private_array_in_hw_loop

# 需要導入模塊: import pyopencl [as 別名]
# 或者: from pyopencl import CommandQueue [as 別名]
def test_save_of_private_array_in_hw_loop(ctx_factory, debug=False):
    ctx = ctx_factory()
    queue = cl.CommandQueue(ctx)

    knl = lp.make_kernel(
        "{ [i,j,k]: 0<=i,j,k<8 }",
        """
        for i
            for j
               <>t[j] = j
            end
            ... gbarrier
            for k
                out[i,k] = t[k]
            end
        end
        """, seq_dependencies=True)

    knl = lp.tag_inames(knl, dict(i="g.0"))
    knl = lp.set_temporary_scope(knl, "t", "private")

    save_and_reload_temporaries_test(
        queue, knl, np.vstack((8 * (np.arange(8),))), debug) 
開發者ID:inducer,項目名稱:loopy,代碼行數:25,代碼來源:test_loopy.py

示例7: test_save_of_private_multidim_array

# 需要導入模塊: import pyopencl [as 別名]
# 或者: from pyopencl import CommandQueue [as 別名]
def test_save_of_private_multidim_array(ctx_factory, debug=False):
    ctx = ctx_factory()
    queue = cl.CommandQueue(ctx)

    knl = lp.make_kernel(
        "{ [i,j,k,l,m]: 0<=i,j,k,l,m<8 }",
        """
        for i
            for j, k
               <>t[j,k] = k
            end
            ... gbarrier
            for l, m
                out[i,l,m] = t[l,m]
            end
        end
        """, seq_dependencies=True)

    knl = lp.set_temporary_scope(knl, "t", "private")

    result = np.array([np.vstack((8 * (np.arange(8),))) for i in range(8)])
    save_and_reload_temporaries_test(queue, knl, result, debug) 
開發者ID:inducer,項目名稱:loopy,代碼行數:24,代碼來源:test_loopy.py

示例8: test_save_of_local_array

# 需要導入模塊: import pyopencl [as 別名]
# 或者: from pyopencl import CommandQueue [as 別名]
def test_save_of_local_array(ctx_factory, debug=False):
    ctx = ctx_factory()
    queue = cl.CommandQueue(ctx)

    knl = lp.make_kernel(
        "{ [i,j]: 0<=i,j<8 }",
        """
        for i, j
            <>t[2*j] = j
            t[2*j+1] = j
            ... gbarrier
            out[i] = t[2*i]
        end
        """, seq_dependencies=True)

    knl = lp.set_temporary_scope(knl, "t", "local")
    knl = lp.tag_inames(knl, dict(i="g.0", j="l.0"))

    save_and_reload_temporaries_test(queue, knl, np.arange(8), debug) 
開發者ID:inducer,項目名稱:loopy,代碼行數:21,代碼來源:test_loopy.py

示例9: test_save_of_local_array_with_explicit_local_barrier

# 需要導入模塊: import pyopencl [as 別名]
# 或者: from pyopencl import CommandQueue [as 別名]
def test_save_of_local_array_with_explicit_local_barrier(ctx_factory, debug=False):
    ctx = ctx_factory()
    queue = cl.CommandQueue(ctx)

    knl = lp.make_kernel(
        "{ [i,j]: 0<=i,j<8 }",
        """
        for i, j
            <>t[2*j] = j
            ... lbarrier
            t[2*j+1] = t[2*j]
            ... gbarrier
            out[i] = t[2*i]
        end
        """, seq_dependencies=True)

    knl = lp.set_temporary_scope(knl, "t", "local")
    knl = lp.tag_inames(knl, dict(i="g.0", j="l.0"))

    save_and_reload_temporaries_test(queue, knl, np.arange(8), debug) 
開發者ID:inducer,項目名稱:loopy,代碼行數:22,代碼來源:test_loopy.py

示例10: test_save_local_multidim_array

# 需要導入模塊: import pyopencl [as 別名]
# 或者: from pyopencl import CommandQueue [as 別名]
def test_save_local_multidim_array(ctx_factory, debug=False):
    ctx = ctx_factory()
    queue = cl.CommandQueue(ctx)

    knl = lp.make_kernel(
            "{ [i,j,k]: 0<=i<2 and 0<=k<3 and 0<=j<2}",
            """
            for i, j, k
                ... gbarrier
                <> t_local[k,j] = 1
                ... gbarrier
                out[k,i*2+j] = t_local[k,j]
            end
            """, seq_dependencies=True)

    knl = lp.set_temporary_scope(knl, "t_local", "local")
    knl = lp.tag_inames(knl, dict(j="l.0", i="g.0"))

    save_and_reload_temporaries_test(queue, knl, 1, debug) 
開發者ID:inducer,項目名稱:loopy,代碼行數:21,代碼來源:test_loopy.py

示例11: test_save_with_base_storage

# 需要導入模塊: import pyopencl [as 別名]
# 或者: from pyopencl import CommandQueue [as 別名]
def test_save_with_base_storage(ctx_factory, debug=False):
    ctx = ctx_factory()
    queue = cl.CommandQueue(ctx)

    knl = lp.make_kernel(
            "{[i]: 0 <= i < 10}",
            """
            <>a[i] = 0
            <>b[i] = i
            ... gbarrier
            out[i] = a[i]
            """,
            "...",
            seq_dependencies=True)

    knl = lp.tag_inames(knl, dict(i="l.0"))
    knl = lp.set_temporary_scope(knl, "a", "local")
    knl = lp.set_temporary_scope(knl, "b", "local")

    knl = lp.alias_temporaries(knl, ["a", "b"],
            synchronize_for_exclusive_use=False)

    save_and_reload_temporaries_test(queue, knl, np.arange(10), debug) 
開發者ID:inducer,項目名稱:loopy,代碼行數:25,代碼來源:test_loopy.py

示例12: test_assign_to_linear_subscript

# 需要導入模塊: import pyopencl [as 別名]
# 或者: from pyopencl import CommandQueue [as 別名]
def test_assign_to_linear_subscript(ctx_factory):
    ctx = ctx_factory()
    queue = cl.CommandQueue(ctx)

    knl1 = lp.make_kernel(
            "{ [i]: 0<=i<n}",
            "a[i,i] = 1")
    knl2 = lp.make_kernel(
            "{ [i]: 0<=i<n}",
            "a[[i*n + i]] = 1",
            [lp.GlobalArg("a", shape="n,n"), "..."])

    a1 = cl.array.zeros(queue, (10, 10), np.float32)
    knl1(queue, a=a1)
    a2 = cl.array.zeros(queue, (10, 10), np.float32)
    knl2(queue, a=a2)

    assert np.array_equal(a1.get(),  a2.get()) 
開發者ID:inducer,項目名稱:loopy,代碼行數:20,代碼來源:test_loopy.py

示例13: test_call_with_no_returned_value

# 需要導入模塊: import pyopencl [as 別名]
# 或者: from pyopencl import CommandQueue [as 別名]
def test_call_with_no_returned_value(ctx_factory):
    import pymbolic.primitives as p

    ctx = ctx_factory()
    queue = cl.CommandQueue(ctx)

    knl = lp.make_kernel(
        "{:}",
        [lp.CallInstruction((), p.Call(p.Variable("f"), ()))]
        )

    from library_for_test import no_ret_f_mangler, no_ret_f_preamble_gen
    knl = lp.register_function_manglers(knl, [no_ret_f_mangler])
    knl = lp.register_preamble_generators(knl, [no_ret_f_preamble_gen])

    evt, _ = knl(queue)

# }}}


# {{{ call with no return values and options 
開發者ID:inducer,項目名稱:loopy,代碼行數:23,代碼來源:test_loopy.py

示例14: test_temp_initializer

# 需要導入模塊: import pyopencl [as 別名]
# 或者: from pyopencl import CommandQueue [as 別名]
def test_temp_initializer(ctx_factory, src_order, tmp_order):
    a = np.random.randn(3, 3).copy(order=src_order)

    ctx = ctx_factory()
    queue = cl.CommandQueue(ctx)

    knl = lp.make_kernel(
            "{[i,j]: 0<=i,j<n}",
            "out[i,j] = tmp[i,j]",
            [
                lp.TemporaryVariable("tmp",
                    initializer=a,
                    shape=lp.auto,
                    address_space=lp.AddressSpace.PRIVATE,
                    read_only=True,
                    order=tmp_order),
                "..."
                ])

    knl = lp.set_options(knl, write_cl=True)
    knl = lp.fix_parameters(knl, n=a.shape[0])

    evt, (a2,) = knl(queue, out_host=True)

    assert np.array_equal(a, a2) 
開發者ID:inducer,項目名稱:loopy,代碼行數:27,代碼來源:test_loopy.py

示例15: test_inames_conditional_generation

# 需要導入模塊: import pyopencl [as 別名]
# 或者: from pyopencl import CommandQueue [as 別名]
def test_inames_conditional_generation(ctx_factory):
    ctx = ctx_factory()
    knl = lp.make_kernel(
            "{[i,j,k]: 0 < k < i and 0 < j < 10 and 0 < i < 10}",
            """
            for k
                ... gbarrier
                <>tmp1 = 0
            end
            for j
                ... gbarrier
                <>tmp2 = i
            end
            """,
            "...",
            seq_dependencies=True)

    knl = lp.tag_inames(knl, dict(i="g.0"))

    with cl.CommandQueue(ctx) as queue:
        knl(queue) 
開發者ID:inducer,項目名稱:loopy,代碼行數:23,代碼來源:test_loopy.py


注:本文中的pyopencl.CommandQueue方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。