kerncraft/kernel.py
def compile_kernel(self, openmp=False, assembly=False, verbose=False):
        """
        Compile source (from as_code(type_)) to assembly or object and return (fileptr, filename).

        Output can be used with Kernel.assemble()
        """
        compiler, compiler_args = self._machine.get_compiler()

        in_filename = self.get_kernel_code(openmp=openmp, as_filename=True)

        if assembly:
            compiler_args += ['-S']
            suffix = '.s'
        else:
            suffix = '.o'
        out_filename, already_exists = self._get_intermediate_file(
            os.path.splitext(os.path.basename(in_filename))[0]+suffix, binary=not assembly, fp=False)
        if already_exists:
            if verbose:
                print('Executing (compile_kernel): ', 'using cached', out_filename)
            return out_filename

        compiler_args += ['-std=c99']

        cmd = ([compiler] +
               [in_filename,
                '-c',
                '-I'+reduce_path(os.path.abspath(os.path.dirname(
                    os.path.realpath(__file__)))+'/headers/'),
                '-o', out_filename] +
               compiler_args)

        if verbose:
            print('Executing (compile_kernel): ', ' '.join(cmd))

        try:
            subprocess.check_output(cmd)

        except subprocess.CalledProcessError as e:
            print("Compilation failed:", e, file=sys.stderr)
            sys.exit(1)

        # FIXME TODO FIXME TODO FIXME TODO
        # Hacky workaround for icc issue (icc may issue vkmovb instructions with AVX512, which are
        # invalid and should be kmovb):
        if compiler == 'icc' and assembly:
            with open(out_filename, 'r+') as f:
                assembly = f.read()
                f.seek(0)
                f.write(assembly.replace('vkmovb', 'kmovb'))
                f.truncate()
        # FIXME TODO FIXME TODO FIXME TODO

        # Let's return the out_file name
        return out_filename
def compile_kernel(self, openmp=False, assembly=False, verbose=False):
        """
        Compile source (from as_code(type_)) to assembly or object and return (fileptr, filename).

        Output can be used with Kernel.assemble()
        """
        compiler, compiler_args = self._machine.get_compiler()

        in_filename = self.get_kernel_code(openmp=openmp, as_filename=True)

        if assembly:
            compiler_args += ['-S']
            suffix = '.s'
        else:
            suffix = '.o'
        out_filename, already_exists = self._get_intermediate_file(
            os.path.splitext(os.path.basename(in_filename))[0]+suffix, binary=not assembly, fp=False)
        if already_exists:
            if verbose:
                print('Executing (compile_kernel): ', 'using cached', out_filename)
            return out_filename

        compiler_args += ['-std=c99']

        cmd = ([compiler] +
               [in_filename,
                '-c',
                '-I'+reduce_path(os.path.abspath(os.path.dirname(
                    os.path.realpath(__file__)))+'/headers/'),
                '-o', out_filename] +
               compiler_args)

        if verbose:
            print('Executing (compile_kernel): ', ' '.join(cmd))

        try:
            subprocess.check_output(cmd)

        except subprocess.CalledProcessError as e:
            print("Compilation failed:", e, file=sys.stderr)
            sys.exit(1)

        # FIXME TODO FIXME TODO FIXME TODO
        # Hacky workaround for icc issue (icc may issue vkmovb instructions with AVX512, which are
        # invalid and should be kmovb):
        if compiler == 'icc' and assembly:
            with open(out_filename, 'r+') as f:
                assembly = f.read()
                f.seek(0)
                f.write(assembly.replace('vkmovb', 'kmovb'))
                f.truncate()
        # FIXME TODO FIXME TODO FIXME TODO

        # Let's return the out_file name
        return out_filename
def compile_kernel ( self , openmp = False , assembly = False , verbose = False ) : compiler , compiler_args = self . _machine . get_compiler ( ) in_filename = self . get_kernel_code ( openmp = openmp , as_filename = True ) if assembly : compiler_args += [ '-S' ] suffix = '.s' else : suffix = '.o' out_filename , already_exists = self . _get_intermediate_file ( os . path . splitext ( os . path . basename ( in_filename ) ) [ 0 ] + suffix , binary = not assembly , fp = False ) if already_exists : if verbose : print ( 'Executing (compile_kernel): ' , 'using cached' , out_filename ) return out_filename compiler_args += [ '-std=c99' ] cmd = ( [ compiler ] + [ in_filename , '-c' , '-I' + reduce_path ( os . path . abspath ( os . path . dirname ( os . path . realpath ( __file__ ) ) ) + '/headers/' ) , '-o' , out_filename ] + compiler_args ) if verbose : print ( 'Executing (compile_kernel): ' , ' ' . join ( cmd ) ) try : subprocess . check_output ( cmd ) except subprocess . CalledProcessError as e : print ( "Compilation failed:" , e , file = sys . stderr ) sys . exit ( 1 ) # FIXME TODO FIXME TODO FIXME TODO # Hacky workaround for icc issue (icc may issue vkmovb instructions with AVX512, which are # invalid and should be kmovb): if compiler == 'icc' and assembly : with open ( out_filename , 'r+' ) as f : assembly = f . read ( ) f . seek ( 0 ) f . write ( assembly . replace ( 'vkmovb' , 'kmovb' ) ) f . truncate ( ) # FIXME TODO FIXME TODO FIXME TODO # Let's return the out_file name return out_filename
Compile source (from as_code(type_)) to assembly or object and return (fileptr, filename).

        Output can be used with Kernel.assemble()
Compile source ( from as_code ( type_ )) to assembly or object and return ( fileptr filename ) .