当前位置: 首页>>代码示例>>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;未经允许,请勿转载。