Exemplo n.º 1
0
def sum(a, dtype=None, queue=None):
    """
    .. versionadded:: 2011.1
    """
    from pyopencl.reduction import get_sum_kernel
    krnl = get_sum_kernel(a.context, dtype, a.dtype)
    return krnl(a, queue=queue)
Exemplo n.º 2
0
def sum(a, dtype=None, queue=None):
    """
    .. versionadded:: 2011.1
    """
    from pyopencl.reduction import get_sum_kernel
    krnl = get_sum_kernel(a.context, dtype, a.dtype)
    return krnl(a, queue=queue)
    def init_OpenCL_decoding(self,msg_at_time_, context_=False):
        if not context_:
            self.context = cl.create_some_context()
        else:
            self.context = context_

        print(self.context.get_info(cl.context_info.DEVICES))
        path = os.path.split(os.path.abspath(__file__))

        kernelsource = open(os.path.join(path[0], "kernels_min_and_BP.cl")).read()
        tpl = Template(kernelsource)
        rendered_tp = tpl.render(cn_degree=self.d_c_max, vn_degree=self.d_v_max, msg_at_time=msg_at_time_)

        self.program = cl.Program(self.context, str(rendered_tp)).build()

        self.queue = cl.CommandQueue(self.context)

        self.inbox_memory_start_varnodes_buffer = cl_array.to_device(self.queue,
                                                                self.inbox_memory_start_varnodes.astype(np.int32))

        self.inbox_memory_start_checknodes_buffer = cl_array.to_device(self.queue,
                                                                  self.inbox_memory_start_checknodes.astype(np.int32))

        self.degree_varnode_nr_buffer = cl_array.to_device(self.queue, self.degree_varnode_nr.astype(np.int32))

        self.degree_checknode_nr_buffer = cl_array.to_device(self.queue, self.degree_checknode_nr.astype(np.int32))

        self.target_memorycells_varnodes_buffer = cl_array.to_device(self.queue,
                                                                self.target_memory_cells_varnodes.astype(np.int32))
        self.target_memorycells_checknodes_buffer = cl_array.to_device(self.queue,
                                                                  self.target_memory_cells_checknodes.astype(np.int32))


        self.checknode_inbox_buffer = cl_array.empty(self.queue, self.inbox_memory_checknodes.shape, dtype=np.float64)

        self.varnode_inbox_buffer = cl_array.empty(self.queue, self.inbox_memory_varnodes.shape, dtype=np.float64)

        self.syndrom_buffer = cl_array.empty(self.queue,
            (self.degree_checknode_nr.shape[0], self.inbox_memory_varnodes.shape[-1]), dtype=np.int32)

        self.krnl = get_sum_kernel(self.context, None,
                                   dtype_in=self.varnode_inbox_buffer.dtype)  # varnode_output_buffer.dtype )

        # define programs
        self.send_prog = self.program.send_channel_values_to_checknode_inbox

        self.varnode_update_prog = self.program.varnode_update

        self.checknode_update_prog = self.program.checknode_update

        self.calc_syndrom_prog = self.program.calc_syndrome

        self.varoutput_prog = self.program.calc_varnode_output
Exemplo n.º 4
0
 def sum(a, dtype=None, queue=None):
     from pyopencl.reduction import get_sum_kernel
     krnl = get_sum_kernel(dtype, a.dtype)
     return krnl(a, queue=queue)
Exemplo n.º 5
0
def sum(a, dtype=None, queue=None):
    from pyopencl.reduction import get_sum_kernel
    krnl = get_sum_kernel(a.context, dtype, a.dtype)
    return krnl(a, queue=queue)
    def init_OpenCL_decoding(self, msg_at_time_, context_=False):
        if not context_:
            self.context = cl.create_some_context()
        else:
            self.context = context_

        path = os.path.split(os.path.abspath(__file__))

        kernelsource = open(os.path.join(path[0],
                                         "kernels_template.cl")).read()
        tpl = Template(kernelsource)
        rendered_tp = tpl.render(cn_degree=self.degree_checknode_nr[0],
                                 vn_degree=self.degree_varnode_nr[0],
                                 msg_at_time=msg_at_time_)

        self.program = cl.Program(self.context, str(rendered_tp)).build()

        self.queue = cl.CommandQueue(self.context)
        mem_pool = cl.tools.MemoryPool(
            cl.tools.ImmediateAllocator(self.queue, cl.mem_flags.READ_ONLY))
        mem_pool2 = cl.tools.MemoryPool(cl.tools.ImmediateAllocator(
            self.queue))

        #mem_pool = None
        self.inbox_memory_start_varnodes_buffer = cl_array.to_device(
            self.queue,
            self.inbox_memory_start_varnodes.astype(np.int32),
            allocator=mem_pool)

        self.inbox_memory_start_checknodes_buffer = cl_array.to_device(
            self.queue,
            self.inbox_memory_start_checknodes.astype(np.int32),
            allocator=mem_pool)

        self.degree_varnode_nr_buffer = cl_array.to_device(
            self.queue,
            self.degree_varnode_nr.astype(np.int32),
            allocator=mem_pool)

        self.degree_checknode_nr_buffer = cl_array.to_device(
            self.queue,
            self.degree_checknode_nr.astype(np.int32),
            allocator=mem_pool)

        self.target_memorycells_varnodes_buffer = cl_array.to_device(
            self.queue,
            self.target_memory_cells_varnodes.astype(np.int32),
            allocator=mem_pool)
        self.target_memorycells_checknodes_buffer = cl_array.to_device(
            self.queue,
            self.target_memory_cells_checknodes.astype(np.int32),
            allocator=mem_pool)

        self.Trellis_checknode_vector_a_buffer = cl_array.to_device(
            self.queue,
            self.Trellis_checknode_vector_a.astype(np.int32),
            allocator=mem_pool)

        self.Trellis_varnode_vector_a_buffer = cl_array.to_device(
            self.queue,
            self.Trellis_varnode_vector_a.astype(np.int32),
            allocator=mem_pool)

        self.checknode_inbox_buffer = cl_array.empty(
            self.queue,
            self.inbox_memory_checknodes.shape,
            dtype=np.int32,
            allocator=mem_pool2)

        self.varnode_inbox_buffer = cl_array.empty(
            self.queue,
            self.inbox_memory_varnodes.shape,
            dtype=np.int32,
            allocator=mem_pool2)

        self.syndrom_buffer = cl_array.empty(
            self.queue, (self.degree_checknode_nr.shape[0],
                         self.inbox_memory_varnodes.shape[-1]),
            dtype=np.int32,
            allocator=mem_pool2)

        self.krnl = get_sum_kernel(self.context,
                                   None,
                                   dtype_in=self.varnode_inbox_buffer.dtype
                                   )  # varnode_output_buffer.dtype )

        # define programs
        self.send_prog = self.program.send_channel_values_to_checknode_inbox

        self.first_iter_prog = self.program.checknode_update_iter0
        self.first_iter_prog.set_scalar_arg_dtypes(
            [None, None, None, None, None, np.int32, np.int32, None])

        self.varnode_update_prog = self.program.varnode_update
        self.varnode_update_prog.set_scalar_arg_dtypes([
            None, None, None, None, None, None, np.int32, np.int32, np.int32,
            None
        ])

        self.checknode_update_prog = self.program.checknode_update
        self.checknode_update_prog.set_scalar_arg_dtypes(
            [None, None, None, None, None, np.int32, np.int32, np.int32, None])

        self.calc_syndrom_prog = self.program.calc_syndrome
        self.calc_syndrom_prog.set_scalar_arg_dtypes(
            [None, None, None, np.int32, None])

        self.varoutput_prog = self.program.calc_varnode_output
        self.varoutput_prog.set_scalar_arg_dtypes(
            [None, None, None, None, np.int32, np.int32, np.int32, None, None])