示例#1
0
 private static void extractAndLoadNativeLibs() throws IOException {
   Path target = Paths.get(ioTmpDir, "/tklib");
   if (!target.toFile().exists()) {
     Files.createDirectories(target);
   }
   final boolean windows = System.getProperty("os.name").equalsIgnoreCase("windows");
   String fileExtension = windows ? "dll" : "so";
   String prefix = windows ? "" : "lib";
   String libPattern = fileExtension.equals("dll") ? "-windows" : "-linux" + "-x86";
   if (System.getProperty("sun.arch.data.model").equals("64")) {
     libPattern += "_64";
   }
   libPattern += "." + fileExtension;
   //		System.err.println(libPattern);
   System.setProperty("java.library.path", target.toString());
   //		System.err.println(System.getProperty("java.library.path"));
   extractAndLoadNativeLib(prefix + "JCudaDriver" + libPattern, target);
   extractAndLoadNativeLib(prefix + "JCudaRuntime" + libPattern, target);
   extractAndLoadNativeLib(prefix + "JCurand" + libPattern, target);
 }
示例#2
0
 // void compileKernelsPtx()
 static void compileKernelsPtx() throws IOException {
   if (!new File(ioTmpDir, PHEROMONES_CU + ".ptx").exists()) { // TODO externalize
     try (InputStream is =
         CudaEngine.class.getResourceAsStream(
             "/turtlekit/cuda/kernels/" + PHEROMONES_CU + ".cu")) {
       final Path path = Paths.get(ioTmpDir, PHEROMONES_CU + ".cu");
       try {
         Files.copy(is, path);
       } catch (FileAlreadyExistsException e) {
       }
       System.err.println("--------------- Compiling ptx ----------------------");
       KernelLauncher.create(
           path.toString(),
           Kernel.DIFFUSION_TO_TMP.name(),
           false,
           "--use_fast_math",
           "--prec-div=false"); // ,"--gpu-architecture=sm_20");
     } catch (IOException e) {
       throw e;
     }
   }
 }
示例#3
0
 private static void extractAndLoadNativeLib(String nativeLibName, Path target) {
   //		System.err.println("loading "+nativeLibName);
   final Path path = Paths.get(target.toString(), nativeLibName);
   if (!path.toFile().exists()) {
     try (InputStream is =
         CudaEngine.class
             .getClassLoader()
             .getResourceAsStream("/lib/" + nativeLibName)) { // TODO TK property for lib dir
       Files.copy(is, path);
     } catch (IOException e) {
       e.printStackTrace();
     } catch (NullPointerException e) { // TODO find a way to do it instead of eclipse
       final Path eclipsePath = FileSystems.getDefault().getPath("lib", nativeLibName);
       try {
         Files.copy(eclipsePath, path);
       } catch (IOException e1) {
         // TODO Auto-generated catch block
         e1.printStackTrace();
       }
     }
   }
   System.load(path.toString());
   //		System.load(nativeLibName);
 }