diff --git a/src/main/java/com/aparapi/IProfileReportObserver.java b/src/main/java/com/aparapi/IProfileReportObserver.java index 43c17ba895151141dc7cf891527db2e645df4da2..c2f9b903ef5d62e26f4c3280da6f10840a4b1bc0 100644 --- a/src/main/java/com/aparapi/IProfileReportObserver.java +++ b/src/main/java/com/aparapi/IProfileReportObserver.java @@ -29,11 +29,13 @@ public interface IProfileReportObserver { /** * The listener method will be invoked each time a profile report becomes available for each Aparapi Kernel which has * a registered observer.<br/> - * <b>Note1: </b>A report will be generated by a thread executing a kernel, but if multiple threads execute the same kernel, - * on the same device, the report rate is limited to a single thread at a time per kernel per device.<br/> + * <b>Note1: </b>A report will be generated by a thread executing a kernel. If multiple threads execute the same kernel, + * concurrently, this method can be called concurrently too, thus classes implementing this interface need to provide + * a thread safe method. * <br/> - * <b>Note2: </b>When an observer is registered there is no need to acknowledge the reception of a profile report, a new - * one will be automatically generated when another thread runs the same kernel on the same device. + * <b>Note2: </b>If profiling information is to be stored has a {@link com.aparapi.ProfileReport}, it is necessary to clone + * the profileInfo object with {@link com.aparapi.ProfileReport#clone()}. A WeakReference is used to help differentiate such + * need, however it is guaranteed that profileInfo will not be null, during the method execution. * <br/> * @param kernelClass the class of the kernel to which the profile report pertains * @param device the device on which the kernel ran, producing the profile report diff --git a/src/main/java/com/aparapi/Kernel.java b/src/main/java/com/aparapi/Kernel.java index c901a2b01611f6a3f250d13133df47e01b66e3a4..a41e2eab5aa634cd5c381943f9895f63c83d55bf 100644 --- a/src/main/java/com/aparapi/Kernel.java +++ b/src/main/java/com/aparapi/Kernel.java @@ -2518,10 +2518,10 @@ public abstract class Kernel implements Cloneable { } /** - * Retrieves a profile report for the last thread that executed this kernel on the given device.<br/> + * Retrieves a profile report for the last thread that executed this kernel on the given device. * A report will only be available if at least one thread executed the kernel on the device. - * - * <b>Note1: <b>If the profile report is intended to be kept in memory, the object should be cloned with + * <br/> + * <b>Note1: </b>If the profile report is intended to be kept in memory, the object should be cloned with * {@link com.aparapi.ProfileReport#clone()}<br/> * * @param device the relevant device where the kernel executed @@ -2556,10 +2556,11 @@ public abstract class Kernel implements Cloneable { /** * Retrieves the most recent complete report available for the current thread calling this method for - * the current kernel instance and executed on the given device.<br/> - * <b>Note1: <b>If the profile report is intended to be kept in memory, the object should be cloned with + * the current kernel instance and executed on the given device. + * <br/> + * <b>Note1: </b>If the profile report is intended to be kept in memory, the object should be cloned with * {@link com.aparapi.ProfileReport#clone()}<br/> - * <b>Note2: <b/>If the thread didn't execute this kernel on the specified device, it + * <b>Note2: </b>If the thread didn't execute this kernel on the specified device, it * will return null. * * @param device the relevant device where the kernel executed diff --git a/src/main/java/com/aparapi/device/OpenCLDevice.java b/src/main/java/com/aparapi/device/OpenCLDevice.java index 56cd1760ce081b386999ab09d6747c22905638f2..c962ba8f7b3431a127e45c990bdc9e158647d2d1 100644 --- a/src/main/java/com/aparapi/device/OpenCLDevice.java +++ b/src/main/java/com/aparapi/device/OpenCLDevice.java @@ -28,7 +28,10 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.logging.Level; +import java.util.logging.Logger; +import com.aparapi.Config; import com.aparapi.Range; import com.aparapi.internal.opencl.OpenCLArgDescriptor; import com.aparapi.internal.opencl.OpenCLKernel; @@ -46,6 +49,7 @@ import com.aparapi.opencl.OpenCL.Resource; import com.aparapi.opencl.OpenCL.Source; public class OpenCLDevice extends Device implements Comparable<Device> { + private static Logger logger = Logger.getLogger(Config.getLoggerName()); private static IOpenCLDeviceConfigurator configurator = null; @@ -137,6 +141,15 @@ public class OpenCLDevice extends Device implements Comparable<Device> { this.name = name; } + private static void configuratorWrapper(final IOpenCLDeviceConfigurator configurator, final OpenCLDevice device) { + try { + configurator.configure(device); + } catch (Throwable ex) { + logger.log(Level.WARNING, "Failed to configure device - Id: " + device.deviceId + + ", Name: " + device.getName(), ex); + } + } + /** * Called by the underlying Aparapi OpenCL platform, upon device * detection. @@ -144,8 +157,11 @@ public class OpenCLDevice extends Device implements Comparable<Device> { public void configure() { if (configurator != null && !underConfiguration.get() && underConfiguration.compareAndSet(false, true)) { - configurator.configure(this); - underConfiguration.set(false); + try { + configuratorWrapper(configurator, this); + } finally { + underConfiguration.set(false); + } } } diff --git a/src/main/java/com/aparapi/internal/kernel/KernelDeviceProfile.java b/src/main/java/com/aparapi/internal/kernel/KernelDeviceProfile.java index a45cfd8361595245f654bedaf3b2e18785f01a75..d5ba22767b19b8717e84d88a19d7a5a49921bcc9 100644 --- a/src/main/java/com/aparapi/internal/kernel/KernelDeviceProfile.java +++ b/src/main/java/com/aparapi/internal/kernel/KernelDeviceProfile.java @@ -220,9 +220,9 @@ public class KernelDeviceProfile { /** * Retrieves the most recent complete report available for the current thread calling this method.<br/> - * <b>Note1: <b>If the profile report is intended to be kept in memory, the object should be cloned with + * <b>Note1: </b>If the profile report is intended to be kept in memory, the object should be cloned with * {@link com.aparapi.ProfileReport#clone()}<br/> - * <b>Note2: <b/>If the thread didn't execute this KernelDeviceProfile instance respective kernel and device, it + * <b>Note2: </b>If the thread didn't execute this KernelDeviceProfile instance respective kernel and device, it * will return null. * @return <ul><li>the profiling report for the current most recent execution</li> * <li>null, if no profiling report is available for such thread</li></ul> @@ -236,7 +236,7 @@ public class KernelDeviceProfile { /** * Retrieves the most recent complete report available for the last thread that executed this KernelDeviceProfile * instance respective kernel and device.<br/> - * <b>Note1: <b>If the profile report is intended to be kept in memory, the object should be cloned with + * <b>Note1: </b>If the profile report is intended to be kept in memory, the object should be cloned with * {@link com.aparapi.ProfileReport#clone()}<br/> * * @return <ul><li>the profiling report for the current most recent execution</li> diff --git a/src/test/java/com/aparapi/runtime/AtomicsSupportAdvTest.java b/src/test/java/com/aparapi/runtime/AtomicsSupportAdvTest.java index 9a15ae587b7513c330509ef117a591e649e220df..e9daf33a7546a3bf499890fee0b8366588a776ea 100644 --- a/src/test/java/com/aparapi/runtime/AtomicsSupportAdvTest.java +++ b/src/test/java/com/aparapi/runtime/AtomicsSupportAdvTest.java @@ -24,6 +24,7 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; +import org.junit.AfterClass; import org.junit.Before; import org.junit.Test; @@ -75,6 +76,11 @@ public class AtomicsSupportAdvTest { openCLDevice = (OpenCLDevice) device; } + @AfterClass + public static void classTeardown() { + Util.resetKernelManager(); + } + @Test public void testOpenCLExplicit() { final int in[] = new int[SIZE]; diff --git a/src/test/java/com/aparapi/runtime/AtomicsSupportTest.java b/src/test/java/com/aparapi/runtime/AtomicsSupportTest.java index d6e4b2a5183dde21b2719d8cbe7083b1920b5e6c..ef9bd22f0928547120453a37f3fec06a23e5f2e3 100644 --- a/src/test/java/com/aparapi/runtime/AtomicsSupportTest.java +++ b/src/test/java/com/aparapi/runtime/AtomicsSupportTest.java @@ -23,6 +23,7 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; +import org.junit.AfterClass; import org.junit.Before; import org.junit.Test; @@ -60,6 +61,11 @@ public class AtomicsSupportTest { } } + @AfterClass + public static void classTeardown() { + Util.resetKernelManager(); + } + @Before public void setUpBeforeClass() throws Exception { KernelManager.setKernelManager(new CLKernelManager()); diff --git a/src/test/java/com/aparapi/runtime/BarrierSupportTest.java b/src/test/java/com/aparapi/runtime/BarrierSupportTest.java index c0403aba017703f6cd805a6a58cfcf815a40e878..b6b65c672b75858baa807d5dd75156a4fdc60ec0 100644 --- a/src/test/java/com/aparapi/runtime/BarrierSupportTest.java +++ b/src/test/java/com/aparapi/runtime/BarrierSupportTest.java @@ -29,6 +29,7 @@ import java.util.Arrays; import java.util.LinkedHashSet; import java.util.List; +import org.junit.AfterClass; import org.junit.Before; import org.junit.Test; @@ -56,6 +57,11 @@ public class BarrierSupportTest { } } + @AfterClass + public static void classTeardown() { + Util.resetKernelManager(); + } + @Before public void setUpBefore() throws Exception { KernelManager.setKernelManager(new CLKernelManager()); diff --git a/src/test/java/com/aparapi/runtime/MultiDimensionalLocalArrayTest.java b/src/test/java/com/aparapi/runtime/MultiDimensionalLocalArrayTest.java index 8cc14518b82a5a9e7c8393711d7ed2baaceb40c0..7eb5461c9c47ebc7122ca10f90b085fed61468ad 100644 --- a/src/test/java/com/aparapi/runtime/MultiDimensionalLocalArrayTest.java +++ b/src/test/java/com/aparapi/runtime/MultiDimensionalLocalArrayTest.java @@ -22,6 +22,7 @@ import java.util.Arrays; import java.util.LinkedHashSet; import java.util.List; +import org.junit.AfterClass; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; @@ -59,6 +60,11 @@ public class MultiDimensionalLocalArrayTest return Arrays.asList(Device.TYPE.JTP); } } + + @AfterClass + public static void classTeardown() { + Util.resetKernelManager(); + } @Before public void setUpBeforeClass() throws Exception { diff --git a/src/test/java/com/aparapi/runtime/NegativeIntegerTest.java b/src/test/java/com/aparapi/runtime/NegativeIntegerTest.java index 1575cdf70a41984490a2dd212c386c4ee7885299..183bc772d2ab1c0f3f08d3281261f8aaca28727c 100644 --- a/src/test/java/com/aparapi/runtime/NegativeIntegerTest.java +++ b/src/test/java/com/aparapi/runtime/NegativeIntegerTest.java @@ -21,6 +21,7 @@ import static org.junit.Assume.assumeTrue; import java.util.Arrays; import java.util.List; +import org.junit.AfterClass; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; @@ -58,6 +59,11 @@ public class NegativeIntegerTest openCLDevice = (OpenCLDevice) device; } + @AfterClass + public static void classTeardown() { + Util.resetKernelManager(); + } + @Test public void negativeIntegerTestPass() { diff --git a/src/test/java/com/aparapi/runtime/OpenCLDeviceConfiguratorTest.java b/src/test/java/com/aparapi/runtime/OpenCLDeviceConfiguratorTest.java index 942dd2ef3dd37a1877adb47acec03bcd371a9757..78fd2c59bfd3926de1c914da4d8a0b648d8adea0 100644 --- a/src/test/java/com/aparapi/runtime/OpenCLDeviceConfiguratorTest.java +++ b/src/test/java/com/aparapi/runtime/OpenCLDeviceConfiguratorTest.java @@ -17,19 +17,27 @@ package com.aparapi.runtime; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeTrue; +import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; +import java.util.LinkedHashSet; import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; +import org.junit.After; import org.junit.Test; import com.aparapi.device.Device; import com.aparapi.device.IOpenCLDeviceConfigurator; +import com.aparapi.device.JavaDevice; import com.aparapi.device.OpenCLDevice; import com.aparapi.internal.kernel.KernelManager; +import com.aparapi.internal.kernel.KernelPreferences; import com.aparapi.internal.opencl.OpenCLPlatform; /** @@ -39,16 +47,100 @@ import com.aparapi.internal.opencl.OpenCLPlatform; */ public class OpenCLDeviceConfiguratorTest { private static OpenCLDevice openCLDevice = null; + private final AtomicInteger callCounter = new AtomicInteger(0); + + public static List<OpenCLDevice> listDevices(OpenCLDevice.TYPE type) { + final ArrayList<OpenCLDevice> results = new ArrayList<>(); - private class CLKernelManager extends KernelManager { - @Override - protected List<Device.TYPE> getPreferredDeviceTypes() { - return Arrays.asList(Device.TYPE.ACC, Device.TYPE.GPU, Device.TYPE.CPU); - } - } + for (final OpenCLPlatform p : OpenCLPlatform.getUncachedOpenCLPlatforms()) { + for (final OpenCLDevice device : p.getOpenCLDevices()) { + if (type == null || device.getType() == type) { + results.add(device); + } + } + } + + return results; + } + + private class UncachedCLKernelManager extends KernelManager { + private KernelPreferences defaultPreferences; + + @Override + protected void setup() { + callCounter.set(0); + defaultPreferences = createDefaultPreferences(); + } + + @Override + public KernelPreferences getDefaultPreferences() { + return defaultPreferences; + } + + private List<OpenCLDevice> filter(OpenCLDevice.TYPE type, List<OpenCLDevice> devices) { + final ArrayList<OpenCLDevice> results = new ArrayList<>(); + + for (final OpenCLDevice device : devices) { + if (type == null || device.getType() == type) { + results.add(device); + } + } + + return results; + } + + @Override + protected LinkedHashSet<Device> createDefaultPreferredDevices() { + LinkedHashSet<Device> devices = new LinkedHashSet<>(); + + List<OpenCLDevice> all = listDevices(null); + + List<OpenCLDevice> accelerators = filter(Device.TYPE.ACC, all); + List<OpenCLDevice> gpus = filter(Device.TYPE.GPU, all); + List<OpenCLDevice> cpus = filter(Device.TYPE.CPU, all); + + Collections.sort(accelerators, getDefaultAcceleratorComparator()); + Collections.sort(gpus, getDefaultGPUComparator()); + + List<Device.TYPE> preferredDeviceTypes = getPreferredDeviceTypes(); + + for (Device.TYPE type : preferredDeviceTypes) { + switch (type) { + case UNKNOWN: + throw new AssertionError("UNKNOWN device type not supported"); + case GPU: + devices.addAll(gpus); + break; + case CPU: + devices.addAll(cpus); + break; + case JTP: + devices.add(JavaDevice.THREAD_POOL); + break; + case SEQ: + devices.add(JavaDevice.SEQUENTIAL); + break; + case ACC: + devices.addAll(accelerators); + break; + case ALT: + devices.add(JavaDevice.ALTERNATIVE_ALGORITHM); + break; + default: + } + } + + return devices; + } + + @Override + protected List<Device.TYPE> getPreferredDeviceTypes() { + return Arrays.asList(Device.TYPE.ACC, Device.TYPE.GPU, Device.TYPE.CPU); + } + } public void setUp() throws Exception { - KernelManager.setKernelManager(new CLKernelManager()); + KernelManager.setKernelManager(new UncachedCLKernelManager()); Device device = KernelManager.instance().bestDevice(); if (device == null || !(device instanceof OpenCLDevice)) { System.out.println("!!!No OpenCLDevice available for running the integration test"); @@ -57,6 +149,12 @@ public class OpenCLDeviceConfiguratorTest { openCLDevice = (OpenCLDevice) device; } + @After + public void teardDown() { + Util.resetKernelManager(); + } + + public void setUpWithConfigurator(IOpenCLDeviceConfigurator configurator) throws Exception { OpenCLDevice.setConfigurator(configurator); setUp(); @@ -64,7 +162,6 @@ public class OpenCLDeviceConfiguratorTest { @Test public void configuratorCallbackTest() throws Exception { - final AtomicInteger callCounter = new AtomicInteger(0); IOpenCLDeviceConfigurator configurator = new IOpenCLDeviceConfigurator() { @Override public void configure(OpenCLDevice device) { @@ -93,4 +190,51 @@ public class OpenCLDeviceConfiguratorTest { assertEquals("Number of configured devices should match numnber of devices", numberOfDevices, numberOfConfiguredDevices); assertEquals("Number of calls doesn't match the expected", numberOfDevices*2, callCounter.get()); } + + @Test + public void noConfiguratorTest() throws Exception { + setUp(); + assertTrue("Device isShareMempory() should return true", openCLDevice.isSharedMemory()); + assertNotEquals("Device name should not be \"Configured\"", "Configured", openCLDevice.getName()); + List<OpenCLPlatform> platforms = OpenCLPlatform.getUncachedOpenCLPlatforms(); + for (OpenCLPlatform platform : platforms) { + for (OpenCLDevice device : platform.getOpenCLDevices()) { + assertTrue("Device isSharedMempory() should return true", device.isSharedMemory()); + assertNotEquals("Device name should not be \"Configured\"", "Configured", device.getName()); + } + } + } + + @Test + public void protectionAgainstRecursiveConfiguresTest() { + OpenCLDevice dev = new OpenCLDevice(null, 101L, Device.TYPE.CPU); + final AtomicInteger callCounter = new AtomicInteger(0); + IOpenCLDeviceConfigurator configurator = new IOpenCLDeviceConfigurator() { + @Override + public void configure(OpenCLDevice device) { + callCounter.incrementAndGet(); + device.configure(); + } + }; + OpenCLDevice.setConfigurator(configurator); + dev.configure(); + + assertEquals("Number of confgure() calls should be one", 1, callCounter.get()); + } + + @Test + public void noExceptionConfiguratorTest() { + final AtomicBoolean called = new AtomicBoolean(false); + OpenCLDevice dev = new OpenCLDevice(null, 101L, Device.TYPE.CPU); + IOpenCLDeviceConfigurator configurator = new IOpenCLDeviceConfigurator() { + @Override + public void configure(OpenCLDevice device) { + called.set(true); + throw new IllegalArgumentException("This exception is part of the test, shouldn't cause test to fail"); + } + }; + OpenCLDevice.setConfigurator(configurator); + dev.configure(); + assertTrue("Configurator should have benn called", called.get()); + } } diff --git a/src/test/java/com/aparapi/runtime/OpenCLDeviceNoConfiguratorTest.java b/src/test/java/com/aparapi/runtime/OpenCLDeviceNoConfiguratorTest.java deleted file mode 100644 index b640d5de1546ae93490e0eea89d8c9e90b77db11..0000000000000000000000000000000000000000 --- a/src/test/java/com/aparapi/runtime/OpenCLDeviceNoConfiguratorTest.java +++ /dev/null @@ -1,90 +0,0 @@ -/** - * Copyright (c) 2016 - 2018 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.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assume.assumeTrue; - -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.atomic.AtomicInteger; - -import org.junit.Test; - -import com.aparapi.device.Device; -import com.aparapi.device.IOpenCLDeviceConfigurator; -import com.aparapi.device.OpenCLDevice; -import com.aparapi.internal.kernel.KernelManager; -import com.aparapi.internal.opencl.OpenCLPlatform; - -/** - * Tests for feature OpenCLDeviceConfigurator set 2/2 - * - * @author CoreRasurae - */ -public class OpenCLDeviceNoConfiguratorTest { - private static OpenCLDevice openCLDevice = null; - - private class CLKernelManager extends KernelManager { - @Override - protected List<Device.TYPE> getPreferredDeviceTypes() { - return Arrays.asList(Device.TYPE.ACC, Device.TYPE.GPU, Device.TYPE.CPU); - } - } - - public void setUp() throws Exception { - KernelManager.setKernelManager(new CLKernelManager()); - Device device = KernelManager.instance().bestDevice(); - if (device == null || !(device instanceof OpenCLDevice)) { - System.out.println("!!!No OpenCLDevice available for running the integration test"); - } - assumeTrue (device != null && device instanceof OpenCLDevice); - openCLDevice = (OpenCLDevice) device; - } - - @Test - public void noConfiguratorTest() throws Exception { - setUp(); - assertTrue("Device isShareMempory() should return true", openCLDevice.isSharedMemory()); - assertNotEquals("Device name should not be \"Configured\"", "Configured", openCLDevice.getName()); - List<OpenCLPlatform> platforms = OpenCLPlatform.getUncachedOpenCLPlatforms(); - for (OpenCLPlatform platform : platforms) { - for (OpenCLDevice device : platform.getOpenCLDevices()) { - assertTrue("Device isSharedMempory() should return true", device.isSharedMemory()); - assertNotEquals("Device name should not be \"Configured\"", "Configured", device.getName()); - } - } - } - - @Test - public void protectionAgainstRecursiveConfiguresTest() { - OpenCLDevice dev = new OpenCLDevice(null, 101L, Device.TYPE.CPU); - final AtomicInteger callCounter = new AtomicInteger(0); - IOpenCLDeviceConfigurator configurator = new IOpenCLDeviceConfigurator() { - @Override - public void configure(OpenCLDevice device) { - callCounter.incrementAndGet(); - device.configure(); - } - }; - OpenCLDevice.setConfigurator(configurator); - dev.configure(); - - assertEquals("Number of confgure() calls should be one", 1, callCounter.get()); - } -} diff --git a/src/test/java/com/aparapi/runtime/OriginalKernelManager.java b/src/test/java/com/aparapi/runtime/OriginalKernelManager.java new file mode 100644 index 0000000000000000000000000000000000000000..423c80346d71b64d0858b96c60c1dc6593666829 --- /dev/null +++ b/src/test/java/com/aparapi/runtime/OriginalKernelManager.java @@ -0,0 +1,25 @@ +/** + * Copyright (c) 2016 - 2018 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 com.aparapi.internal.kernel.KernelManager; + +/** + * Provides a way for re-establishing the default Aparapi KernelManager + * @author CoreRasurae + */ +public class OriginalKernelManager extends KernelManager { +} diff --git a/src/test/java/com/aparapi/runtime/ProfileReportBackwardsCompatTest.java b/src/test/java/com/aparapi/runtime/ProfileReportBackwardsCompatTest.java index a69c3ae230f73479c251b95676ba1fa2030913a7..8ec24e314fe9294454e82a86e8a775aca4fee616 100644 --- a/src/test/java/com/aparapi/runtime/ProfileReportBackwardsCompatTest.java +++ b/src/test/java/com/aparapi/runtime/ProfileReportBackwardsCompatTest.java @@ -15,6 +15,9 @@ */ package com.aparapi.runtime; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeTrue; import java.lang.ref.WeakReference; @@ -28,7 +31,7 @@ import java.util.concurrent.TimeUnit; import java.util.logging.Level; import java.util.logging.Logger; -import static org.junit.Assert.*; +import org.junit.After; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TestName; @@ -57,7 +60,6 @@ public class ProfileReportBackwardsCompatTest { @Rule public TestName name = new TestName(); - private class CLKernelManager extends KernelManager { @Override protected List<Device.TYPE> getPreferredDeviceTypes() { @@ -77,6 +79,11 @@ public class ProfileReportBackwardsCompatTest { } } + @After + public void classTeardown() { + Util.resetKernelManager(); + } + public void setUpBefore() throws Exception { KernelManager.setKernelManager(new CLKernelManager()); Device device = KernelManager.instance().bestDevice(); diff --git a/src/test/java/com/aparapi/runtime/ProfileReportNewAPITest.java b/src/test/java/com/aparapi/runtime/ProfileReportNewAPITest.java index 0abfd26aa3d1f39f9ab22bf656749ea97ef37075..7c25051a5ddafab9509b02142e21ce0099445410 100644 --- a/src/test/java/com/aparapi/runtime/ProfileReportNewAPITest.java +++ b/src/test/java/com/aparapi/runtime/ProfileReportNewAPITest.java @@ -38,6 +38,7 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.logging.Level; import java.util.logging.Logger; +import org.junit.After; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TestName; @@ -68,6 +69,12 @@ public class ProfileReportNewAPITest { public TestName name = new TestName(); + @After + public void classTeardown() { + Util.resetKernelManager(); + } + + private class CLKernelManager extends KernelManager { @Override protected List<Device.TYPE> getPreferredDeviceTypes() { diff --git a/src/test/java/com/aparapi/runtime/Util.java b/src/test/java/com/aparapi/runtime/Util.java index adae0bdf1108a9225834def44029576a1e4fbb47..3ef7593032feed1a47f69355f825acb2c7fee70e 100644 --- a/src/test/java/com/aparapi/runtime/Util.java +++ b/src/test/java/com/aparapi/runtime/Util.java @@ -17,7 +17,13 @@ package com.aparapi.runtime; import java.util.Arrays; -public class Util { +import com.aparapi.internal.kernel.KernelManager; + +public class Util { + public static void resetKernelManager() { + KernelManager.setKernelManager(new OriginalKernelManager()); + } + static void fill(int[] array, Filler _filler) { for (int i = 0; i < array.length; i++) { _filler.fill(array, i);