Esempio n. 1
0
    def compile_link_program(self,
                             header_infos,
                             source_infos,
                             build_options=[],
                             compile_options=[],
                             link_options=[],
                             info_is_filename=True):
        # > import
        from _program import Program
        import clip.cl
        import os

        # > set environment variable to suppress caching
        os.environ['PYOPENCL_NO_CACHE'] = 'TRUE'

        # > create header programs
        from pyopencl._cffi import ffi
        headers = []
        for info in header_infos:
            if info_is_filename:
                routine = open(info[0]).read()
            else:
                routine = info[0]
            # >> create header program
            pgm = Program(self, routine)
            # >> get cstring
            head_name = ffi.new("char[]", info[1])
            # >> wrap header
            headers += ((head_name, pgm._prg), )

        # > create source programs and compile
        sources = []
        for info in source_infos:
            if info_is_filename:
                routine = open(info).read()
            else:
                routine = info
            # >> create program
            pgm = Program(self, routine)
            # >> try to compile
            pgm.compile(compile_options, headers=headers)
            # >> add program to sources
            sources += (pgm._prg, )
        # > try to link
        import pyopencl

        # self.program = pyopencl.link_program(self, sources, link_options)

        options_bytes = ''
        self.program = pyopencl.Program(
            pyopencl._Program.link(self, sources, options_bytes, None))

        clip.cl.program = self.program
        self.program.__class__ = Program
        return self.program
Esempio n. 2
0
    def compile_link_program(self, header_infos, source_infos,
                             build_options=[],
                             compile_options=[], link_options=[],
                             info_is_filename=True):
        # > import
        from _program import Program
        import clip.cl
        import os

        # > set environment variable to suppress caching
        os.environ['PYOPENCL_NO_CACHE'] = 'TRUE'

        # > create header programs
        from pyopencl._cffi import ffi
        headers = []
        for info in header_infos:
            if info_is_filename:
                routine = open(info[0]).read()
            else:
                routine = info[0]
            # >> create header program
            pgm = Program(self, routine)
            # >> get cstring
            head_name = ffi.new("char[]", info[1])
            # >> wrap header
            headers += ((head_name, pgm._prg),)

        # > create source programs and compile
        sources = []
        for info in source_infos:
            if info_is_filename:
                routine = open(info).read()
            else:
                routine = info
            # >> create program
            pgm = Program(self, routine)
            # >> try to compile
            pgm.compile(compile_options, headers=headers)
            # >> add program to sources
            sources += (pgm._prg,)
        # > try to link
        import pyopencl

        # self.program = pyopencl.link_program(self, sources, link_options)

        options_bytes = ''
        self.program = pyopencl.Program(
            pyopencl._Program.link(self, sources, options_bytes, None))

        clip.cl.program = self.program
        self.program.__class__ = Program
        return self.program