我一直在尝试使用这个 GPU 库Rootbeer
我已经运行了演示,并且它们运行良好,然后我尝试运行我的代码,并且在这个片段的倒数第二行 ( Rootbeer rootbeer = new Rootbeer();
),我收到一个错误(请参阅最后一节)。
// This sesction is within a JSlider change event.
int val = sldBrightness.getValue();
List<Kernel> jobs = new ArrayList<Kernel>();
jobs.add(new Brightness(val));
Rootbeer rootbeer = new Rootbeer();
rootbeer.runAll(jobs);
这是我正在运行的课程:
package pocketshop.graphics.adjustments;
import edu.syr.pcpratts.rootbeer.runtime.Kernel;
import java.awt.image.BufferedImage;
import pocketshop.Canvas;
import pocketshop.graphics.Colors;
import pocketshop.graphics.Preview;
/**
*
* @author Ryan
*/
public class Brightness implements Kernel {
protected int amount = 0;
protected int width, height;
int[] pixels; // = new int[width * height];
public void amount(int amount) {
this.amount = amount;
}
public Brightness(int amount) {
this.amount = amount;
width = Canvas.image.getWidth();
height = Canvas.image.getHeight();
pixels = new int[width * height];
Canvas.image.getRGB(0, 0, width, height, pixels, 0, width);
}
public void setImage() {
BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
img.setRGB(0, 0, width, height, pixels, 0, width);
Preview.setImage(img);
}
@Override
public void gpuMethod() {
int[] pixels = this.pixels;
for (int i = 0; i < pixels.length; i++) {
int pixel = pixels[i];
int red = Colors.red(pixel);
int green = Colors.green(pixel);
int blue = Colors.blue(pixel);
red += amount;
if (red > 255) {
red = 255;
} else if (red < 0) {
red = 0;
}
green += amount;
if (green > 255) {
green = 255;
} else if (green < 0) {
green = 0;
}
blue += amount;
if (blue > 255) {
blue = 255;
} else if (blue < 0) {
blue = 0;
}
pixels[i] = Colors.rgba(red, green, blue);
}
}
}
这是输出错误。我真的很困惑为什么会这样Caused by: edu.syr.pcpratts.rootbeer.runtime2.cuda.CudaErrorException: CUDA_ERROR_OUT_OF_MEMORY: gpuHandlesMemory memory allocation failed
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at edu.syr.pcpratts.rootbeer.runtime.RootbeerFactory.create(RootbeerFactory.java:19)
at edu.syr.pcpratts.rootbeer.runtime.Rootbeer.<init>(Rootbeer.java:19)
at pocketshop.dialogs.BrightnessContrastDialog.sldBrightnessStateChanged(BrightnessContrastDialog.java:191)
at pocketshop.dialogs.BrightnessContrastDialog.access$100(BrightnessContrastDialog.java:21)
at pocketshop.dialogs.BrightnessContrastDialog$2.stateChanged(BrightnessContrastDialog.java:65)
at javax.swing.JSlider.fireStateChanged(JSlider.java:432)
at javax.swing.JSlider$ModelListener.stateChanged(JSlider.java:350)
at javax.swing.DefaultBoundedRangeModel.fireStateChanged(DefaultBoundedRangeModel.java:364)
at javax.swing.DefaultBoundedRangeModel.setRangeProperties(DefaultBoundedRangeModel.java:302)
at javax.swing.DefaultBoundedRangeModel.setValue(DefaultBoundedRangeModel.java:168)
at javax.swing.JSlider.setValue(JSlider.java:531)
at pocketshop.dialogs.BrightnessContrastDialog.txtBrightnessActionPerformed(BrightnessContrastDialog.java:180)
at pocketshop.dialogs.BrightnessContrastDialog.access$300(BrightnessContrastDialog.java:21)
at pocketshop.dialogs.BrightnessContrastDialog$4.actionPerformed(BrightnessContrastDialog.java:88)
at javax.swing.JTextField.fireActionPerformed(JTextField.java:508)
at javax.swing.JTextField.postActionEvent(JTextField.java:721)
at javax.swing.JTextField$NotifyAction.actionPerformed(JTextField.java:836)
at javax.swing.SwingUtilities.notifyAction(SwingUtilities.java:1664)
at javax.swing.JComponent.processKeyBinding(JComponent.java:2879)
at javax.swing.JComponent.processKeyBindings(JComponent.java:2926)
at javax.swing.JComponent.processKeyEvent(JComponent.java:2842)
at java.awt.Component.processEvent(Component.java:6282)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1895)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:762)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:1027)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:899)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:727)
at java.awt.Component.dispatchEventImpl(Component.java:4731)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:723)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:682)
at java.awt.EventQueue$3.run(EventQueue.java:680)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:696)
at java.awt.EventQueue$4.run(EventQueue.java:694)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:693)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:155)
at java.awt.WaitDispatchSupport$2.run(WaitDispatchSupport.java:182)
at java.awt.WaitDispatchSupport$4.run(WaitDispatchSupport.java:221)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.WaitDispatchSupport.enter(WaitDispatchSupport.java:219)
at java.awt.Dialog.show(Dialog.java:1077)
at java.awt.Component.show(Component.java:1651)
at java.awt.Component.setVisible(Component.java:1603)
at java.awt.Window.setVisible(Window.java:1014)
at java.awt.Dialog.setVisible(Dialog.java:1003)
at pocketshop.Main.jMenuItem4ActionPerformed(Main.java:233)
at pocketshop.Main.access$200(Main.java:15)
at pocketshop.Main$3.actionPerformed(Main.java:180)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.AbstractButton.doClick(AbstractButton.java:376)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:833)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:877)
at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:289)
at java.awt.Component.processMouseEvent(Component.java:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:723)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:682)
at java.awt.EventQueue$3.run(EventQueue.java:680)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:696)
at java.awt.EventQueue$4.run(EventQueue.java:694)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:693)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)
Caused by: edu.syr.pcpratts.rootbeer.runtime2.cuda.CudaErrorException: CUDA_ERROR_OUT_OF_MEMORY: gpuHandlesMemory memory allocation failed
at edu.syr.pcpratts.rootbeer.runtime2.cuda.CudaRuntime2.setup(Native Method)
at edu.syr.pcpratts.rootbeer.runtime2.cuda.CudaRuntime2.<init>(CudaRuntime2.java:92)
at edu.syr.pcpratts.rootbeer.runtime2.cuda.CudaRuntime2.v(CudaRuntime2.java:38)
at edu.syr.pcpratts.rootbeer.runtime.ConcreteRootbeer.<init>(ConcreteRootbeer.java:27)
... 105 more