本文介绍了如何使用IDE(Netbeans,Eclipse)中的optirun(Bumblebee)来使用图形驱动程序运行构建?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人知道如何使eclipse或netbeans通过在IDE中调用optirun(bumblebee)来在optimus笔记本电脑中使用图形卡,以便可以使用IDE中的运行按钮在程序内的图形卡中运行程序IDE。



以最简单的形式,我只是希望IDE做相当于 optirun ./javaproject

解决方案

我在Eclipse中这样做的方式是首先启动Java调试器jdwp 并收听一个端口。然后使用 optirun java ... 启动JVM,并使用jdwp连接到此端口。通过在调试配置设置(运行 - >调试配置)中创建启动组,可以在Eclipse中同时启动这两个任务。详细地:


  1. 使用Standard(Socket Listen)创建远程Java应用程序调试配置连接类型和某些任意端口,例如56789.这将端口56789上的Java调试器 jdwp 连接到在该端口接受调试连接的虚拟机。

  2. 现在我们需要启动一个具有 optirun的JVM 。这可以通过外部工具配置(运行 - >外部工具 - >外部工具配置)完成。在外部工具配置窗口的左侧创建一个新的程序配置。您可以通过填写必填字段直接启动 optirun java<附加参数> 。但是,我决定使用一个可以被不同项目重用的shell脚本(从下面可以看出,缺少一个部分,使其完全可重用,我很高兴有更多经验丰富的Eclipse用户的帮助) 。因此,位置字段指向此shell脚本。脚本本身接受三个参数:项目的 classpath ,Java可执行文件的名称和端口号。这些参数可以传递到标签的参数字段中的脚本,例如




    • $ {project_classpath:$ {selected_resource_name}}

    • ExecName

    • 56789



    shell脚本看起来像这样,假设optirun在你的PATH中:

     #! / bin / sh 
    CLASS_PATH = $ {1}
    JAVA_EXECUTABLE = $ {2}
    PORT = $ {3}
    #TODO:修复这个java库路径:将其传递为一个争论也是。有没有存储这个的Eclipse变量?
    JAVA_LIBRARY_PATH = / usr / local / share / OpenCV / java
    #----------------------------- -------------------------------------------------
    optirun $ {JAVA_BIN} -agentlib:jdwp = transport = dt_socket,suspend = y,address = localhost:$ {PORT} -Djava.library.path = $ {JAVA_LIBRARY_PATH} -Dfile.encoding = UTF-8 -classpath $ {CLASS_PATH} $ {JAVA_EXECUTABLE}
    #------------------------------------- -----------------------------------------


  3. 最后,这两个部分汇集在启动组中的调试配置窗口(运行 - >调试配置)。创建一个新的启动组,并通过点击启动选项卡中的添加并选择相应的配置,添加以前生成的两个调试配置。
    请注意,由于步骤2中的类路径变量(即 $ {project_classpath:$ {selected_resource_name}} ),需要在 Package Explorer ,然后点击运行调试配置按钮(确保选择了启动组)。

该解决方案对我来说非常适用:我可以调试Eclipse内的Java代码,调用本地代码涉及CUDA优化,而大黄蜂只需在必要时激活独立显卡。


Does anyone know how to make eclipse or netbeans use the graphics card in optimus laptops by invoking optirun (bumblebee) inside the IDE so that one can just use the run button in the IDE to run the program in a graphics card within the IDE.

In simplest form I just want the IDE to do the equivalent of optirun ./javaproject

解决方案

The way I did this in Eclipse was to first start the Java debugger jdwp and listen to a port. Then start the JVM with optirun java ... and use jdwp to connect to this port. Both tasks can be started at the same time in Eclipse by creating a Launch Group in the debug configuration settings (Run -> Debug Configurations). In detail:

  1. Create a Remote Java Application debug configuration with "Standard (Socket Listen)" Connection Type and some arbitrary port, e.g. 56789. This attaches the Java debugger jdwp on port 56789 to a virtual machine which accepts debug connections at this port.
  2. Now we need to start a JVM with optirun. This can be done with a External Tool Configuration (Run -> External Tools -> External Tool Configurations). Create a new Program configuration in the left side of the External Tools Configurations window. You could directly start optirun java <additional arguments> by filling in the required fields. However, I have decided to use a shell script which is reusable by different projects (As can be seen below, there is one part missing to make it entirely reusable. I'm glad for any help from more experienced Eclipse users...). Hence, the Location field points to this shell script. The script itself accepts three arguments: the classpath for the project, the name of the Java executable, and the port number. These arguments can be passed to the script in the Arguments field of the Main tab, e.g.

    • ${project_classpath:${selected_resource_name}}
    • ExecName
    • 56789

    The shell script looks like this, assuming optirun is in your PATH:

    #!/bin/sh
    CLASS_PATH=${1}
    JAVA_EXECUTABLE=${2}
    PORT=${3}
    # TODO: fix this java library path: pass it as an argument as well. Is there an Eclipse variable which stores this?
    JAVA_LIBRARY_PATH=/usr/local/share/OpenCV/java
    #------------------------------------------------------------------------------
    optirun ${JAVA_BIN} -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:${PORT} -Djava.library.path=${JAVA_LIBRARY_PATH} -Dfile.encoding=UTF-8 -classpath ${CLASS_PATH} ${JAVA_EXECUTABLE}
    #------------------------------------------------------------------------------
    

  3. Finally, the two pieces are brought together in a Launch Group in the Debug Configurations window (Run -> Debug Configurations). Create a new Launch Group and add the two previously generated Debug configurations by clicking on Add in the Launches tab and by selecting the appropriate configurations.Note that due to the classpath variable in step 2 (i.e. ${project_classpath:${selected_resource_name}}), the appropriate package needs to be selected in the Package Explorer before clicking on the run debug configuration button (make sure that the Launch Group is selected).

This solution works perfectly for me: I can debug Java code inside Eclipse which calls native code involving CUDA optimizations and Bumblebee only activates the discrete graphics card when necessary.

这篇关于如何使用IDE(Netbeans,Eclipse)中的optirun(Bumblebee)来使用图形驱动程序运行构建?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 23:58