diff --git a/CHANGELOG.md b/CHANGELOG.md index cb238c89f547f1f409b0c26c1726af21ec69fcb6..259816d44b91f36e8d12db7f82121a06613dfa87 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## 1.4.1 +* Fixed NullPointerException when using KernelManger from the KernelManagers class + ## 1.4.0 * Updated nexus stagin plugin: 1.6.7 -> 1.6.8 diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index cc5493943a1976c9df791d78a3d4b678dc36680d..3e28a455e3c771630795d1e259086746339f1bc8 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -17,6 +17,7 @@ * Lorenzo Gallucci * Fernando Marino` * AMD Corporation +* Nicholas Wright - https://github.com/seeker # Details diff --git a/src/main/java/com/aparapi/internal/kernel/KernelManagers.java b/src/main/java/com/aparapi/internal/kernel/KernelManagers.java index 6784f6d2122c1db5a930a8cba987abbbf92f7128..92042204724068e17acba36869161ebb048f5cc5 100644 --- a/src/main/java/com/aparapi/internal/kernel/KernelManagers.java +++ b/src/main/java/com/aparapi/internal/kernel/KernelManagers.java @@ -26,21 +26,17 @@ public class KernelManagers { public static final KernelManager JTP_ONLY = new KernelManager() { - private List<Device.TYPE> types = Collections.singletonList(Device.TYPE.JTP); - @Override protected List<Device.TYPE> getPreferredDeviceTypes() { - return types; + return Collections.singletonList(Device.TYPE.JTP); } }; public static final KernelManager SEQUENTIAL_ONLY = new KernelManager() { - private final List<Device.TYPE> types = Collections.singletonList(Device.TYPE.SEQ); - @Override protected List<Device.TYPE> getPreferredDeviceTypes() { - return types; + return Collections.singletonList(Device.TYPE.SEQ); } }; } diff --git a/src/test/java/com/aparapi/runtime/Issue55Test.java b/src/test/java/com/aparapi/runtime/Issue55Test.java new file mode 100644 index 0000000000000000000000000000000000000000..c2e9a26854fb6af80c5cb3cbf763d2ef043a9eee --- /dev/null +++ b/src/test/java/com/aparapi/runtime/Issue55Test.java @@ -0,0 +1,76 @@ +/** + * Copyright (c) 2016 - 2017 Syncleus, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.aparapi.runtime; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.Test; + +import com.aparapi.Kernel; +import com.aparapi.device.Device; +import com.aparapi.internal.kernel.KernelManager; +import com.aparapi.internal.kernel.KernelManagers; + +public class Issue55Test { + private Kernel testKernel; + + @Before + public void setUp() { + testKernel = new Kernel() { + + /** + * This kernel does nothing. + */ + @Override + public void run() { + // this block was intentionally left empty, as the kernel should do nothing + } + }; + } + + @After + public void tearDown() { + testKernel.dispose(); + } + + @AfterClass + public static void tearDownClass() { + // reset the KernelManager after we are done, as some tests expect a openCL device + KernelManager.setKernelManager(new KernelManager() {}); + } + + @Test + public void testUseJtpOnly() { + KernelManager.setKernelManager(KernelManagers.JTP_ONLY); + + Device device = KernelManager.instance().getDefaultPreferences().getPreferredDevice(testKernel); + + assertThat(device.getType(), is(Device.TYPE.JTP)); + } + + @Test + public void testUseSequentialOnly() { + KernelManager.setKernelManager(KernelManagers.SEQUENTIAL_ONLY); + + Device device = KernelManager.instance().getDefaultPreferences().getPreferredDevice(testKernel); + + assertThat(device.getType(), is(Device.TYPE.SEQ)); + } +}