Esempio n. 1
0
    def __init__(self,
                 specializer="default_specializer",
                 cache_dir=None,
                 use_cuda=False,
                 use_cilk=False,
                 use_tbb=False,
                 use_pthreads=False,
                 use_scala=False):

        self.specialized_functions = {}
        self.helper_method_names = []

        self.db = ASPDB(specializer)

        if cache_dir:
            self.cache_dir = cache_dir
        else:
            # create a per-user cache directory
            import tempfile, os
            if os.name == 'nt':
                username = os.environ['USERNAME']
            else:
                username = os.environ['LOGNAME']

            self.cache_dir = tempfile.gettempdir() + "/asp_cache_" + username
            if not os.access(self.cache_dir, os.F_OK):
                os.mkdir(self.cache_dir)

        self.backends = {}
        self.backends["c++"] = ASPBackend(codepy.bpl.BoostPythonModule(),
                                          codepy.toolchain.guess_toolchain(),
                                          self.cache_dir)
        if use_cuda:
            self.backends["cuda"] = ASPBackend(
                codepy.cuda.CudaModule(self.backends["c++"].module),
                codepy.toolchain.guess_nvcc_toolchain(), self.cache_dir,
                self.backends["c++"].toolchain)
            self.backends['cuda'].module.add_to_preamble(
                [cpp_ast.Include('cuda.h', True)]
            )  # codepy.CudaModule doesn't do this automatically for some reason
            self.backends['cuda'].module.add_to_preamble(
                [cpp_ast.Include('cuda_runtime.h', True)]
            )  # codepy.CudaModule doesn't do this automatically for some reason
            self.backends['c++'].module.add_to_preamble(
                [cpp_ast.Include('cuda_runtime.h', True)]
            )  # codepy.CudaModule doesn't do this automatically for some reason
            self.backends["cuda"].toolchain.cflags += ["-shared"]
        if use_cilk:
            self.backends["cilk"] = self.backends["c++"]
            self.backends["cilk"].toolchain.cc = "icc"
        if use_tbb:
            self.backends["tbb"] = self.backends["c++"]
            self.backends["tbb"].toolchain.cflags += ["-ltbb"]
        if use_pthreads:
            self.backends["pthreads"] = self.backends["c++"]
            self.backends["pthreads"].toolchain.cflags += ["-pthread"]
        if use_scala:
            self.backends["scala"] = ASPBackend(scala_module.ScalaModule(),
                                                scala_module.ScalaToolchain(),
                                                self.cache_dir)
Esempio n. 2
0
 def add_header(self, include_file, brackets=False, backend="c++"):
     """
     Add a header (e.g. #include "foo.h") to the module source file.
     With brackets=True, it will be C++-style #include <foo> instead.
     """
     self.backends[backend].module.add_to_preamble(
         [cpp_ast.Include(include_file, brackets)])
 def add_libraries(self, mod):
     # these are necessary includes, includedirs, and init statements to use the numpy library
     mod.add_library("numpy", [numpy.get_include() + "/numpy"])
     mod.add_header("arrayobject.h")
     mod.add_to_init([cpp_ast.Statement("import_array();")])
     if self.with_cilk:
         mod.module.add_to_preamble([cpp_ast.Include("cilk/cilk.h", True)])
Esempio n. 4
0
    def __init__(self,
                 specializer="default_specializer",
                 cache_dir=None,
                 use_cuda=False,
                 use_cilk=False):

        self.specialized_functions = {}
        self.helper_method_names = []

        self.db = ASPDB(specializer)

        if cache_dir:
            self.cache_dir = cache_dir
        else:
            # create a per-user cache directory
            import tempfile, os
            if os.name == 'nt':
                username = os.environ['USERNAME']
            else:
                username = os.environ['LOGNAME']

            self.cache_dir = tempfile.gettempdir() + "/asp_cache_" + username
            if not os.access(self.cache_dir, os.F_OK):
                os.mkdir(self.cache_dir)

        self.dirty = False
        self.timing_enabled = True
        self.use_cuda = use_cuda

        self.backends = {}
        self.backends["c++"] = ASPBackend(codepy.bpl.BoostPythonModule(),
                                          codepy.toolchain.guess_toolchain(),
                                          self.cache_dir)
        if use_cuda:
            self.backends["cuda"] = ASPBackend(
                codepy.cuda.CudaModule(self.backends["c++"].module),
                codepy.toolchain.guess_nvcc_toolchain(), self.cache_dir)
            self.backends["cuda"].module.add_to_preamble(
                [cpp_ast.Include('cuda.h', False)])

        if use_cilk:
            self.backends["cilk"] = self.backends["c++"]
            self.backends["cilk"].toolchain.cc = "icc"