def build_extension(self, ext_file, source_files, debug=False): cc_cmdline = ( self._cmdline(source_files, False) + ["-o", ext_file] ) length = len(source_files[0])-len('module.cpp') cache_dir = source_files[0][:length] print "cache_dir", cache_dir f = open(cache_dir+'makefile', 'w') f.write('all:\n') f.write('\t'+" ".join(cc_cmdline)) f.close() #f.write('CC='+cc_cmdline[0]) cmdline = ['make', '-f', cache_dir+'makefile'] from pytools.prefork import call #if debug: #print " ".join(cc_cmdline) result = call(cmdline) if result != 0: import sys print >> sys.stderr, "FAILED compiler invocation:", \ " ".join(cc_cmdline) raise CompileError, "module compilation failed"
def _invoke_postaction(self, **kwargs): comm, rank, root = get_comm_rank_root() # If we have a post-action and are the root rank then fire it if rank == root and self.postact: # If a post-action is currently running then wait for it if self.postactaid is not None: prefork.wait(self.postactaid) # Prepare the command line cmdline = shlex.split(self.postact.format(**kwargs)) # Invoke if self.postactmode == 'blocking': prefork.call(cmdline) else: self.postactaid = prefork.call_async(cmdline)
def _invoke_postaction(self, **kwargs): comm, rank, root = get_comm_rank_root() # If we have a post-action and are the root rank then fire it if rank == root and self.postact: # If a post-action is currently running then wait for it if self.postactaid is not None: prefork.wait(self.postactaid) # Prepare the command line cmdline = shlex.split(self.postact.format(**kwargs)) # Invoke if self.postactmode == "blocking": prefork.call(cmdline) else: self.postactaid = prefork.call_async(cmdline)
def compile_plain(source, options, keep, nvcc, cache_dir): from os.path import join if cache_dir: checksum = _new_md5() checksum.update(source) for option in options: checksum.update(option) checksum.update(get_nvcc_version(nvcc)) from pycuda.characterize import platform_bits checksum.update(str(platform_bits())) cache_file = checksum.hexdigest() cache_path = join(cache_dir, cache_file + ".cubin") try: return open(cache_path, "rb").read() except: pass from tempfile import mkdtemp file_dir = mkdtemp() file_root = "kernel" cu_file_name = file_root + ".cu" cu_file_path = join(file_dir, cu_file_name) outf = open(cu_file_path, "w") outf.write(str(source)) outf.close() if keep: options = options[:] options.append("--keep") print "*** compiler output in %s" % file_dir cmdline = [nvcc, "--cubin"] + options + [cu_file_name] try: from pytools.prefork import call_capture_output except ImportError: from pytools.prefork import call try: result = call(cmdline, cwd=file_dir) except OSError, e: raise OSError("%s was not found (is it on the PATH?) [%s]" % (nvcc, str(e))) stdout = None stderr = None
def link_extension(self, ext_file, object_files, debug=False): cc_cmdline = (self._cmdline(object_files, False) + ["-o", ext_file]) from pytools.prefork import call if debug: print(" ".join(cc_cmdline)) result = call(cc_cmdline) if result != 0: import sys print("FAILED compiler invocation:" + " ".join(cc_cmdline), file=sys.stderr) raise CompileError("module compilation failed")
def build_extension(self, ext_file, source_files, debug=False): cc_cmdline = (self._cmdline(source_files, False) + ["-o", ext_file]) from pytools.prefork import call if debug: print " ".join(cc_cmdline) result = call(cc_cmdline) if result != 0: import sys print >> sys.stderr, "FAILED compiler invocation:", \ " ".join(cc_cmdline) raise CompileError, "module compilation failed"
def link_extension(self, ext_file, object_files, debug=False): cc_cmdline = ( self._cmdline(object_files, False) + ["-o", ext_file] ) from pytools.prefork import call if debug: print " ".join(cc_cmdline) result = call(cc_cmdline) if result != 0: import sys print >> sys.stderr, "FAILED compiler invocation:", \ " ".join(cc_cmdline) raise CompileError, "module compilation failed"
def build_object(self, ext_file, source_files, debug=False): cc_cmdline = ( self._cmdline(source_files, True) + ["-o", ext_file] ) from pytools.prefork import call #if debug: #print " ".join(cc_cmdline) result = call(cc_cmdline) if result != 0: import sys print >> sys.stderr, "FAILED compiler invocation:", \ " ".join(cc_cmdline) raise CompileError, "module compilation failed"
def build_object(self, ext_file, source_files, debug=False): cc_cmdline = ( self._cmdline(source_files, True) + ["-o", ext_file] ) from pytools.prefork import call if debug: print(" ".join(cc_cmdline)) result = call(cc_cmdline) if result != 0: import sys print("FAILED compiler invocation: {}".format(" ".join(cc_cmdline)), file=sys.stderr) raise CompileError("module compilation failed")
def _invoke_postaction(self, intg, **kwargs): comm, rank, root = get_comm_rank_root() # If we have a post-action and are the root rank then fire it if rank == root and self.postact: # If a post-action is currently running then wait for it if self.postactaid is not None: prefork.wait(self.postactaid) # Prepare the command line cmdline = shlex.split(self.postact.format(**kwargs)) # Invoke if self.postactmode == 'blocking': # Store returning code of the post-action # If it is different from zero # request intg to abort the computation intg.abort |= bool(prefork.call(cmdline)) else: self.postactaid = prefork.call_async(cmdline)