├── .cz-config.js
├── .cz.json
├── ATTRIBUTIONS.md
├── CHANGELOG.md
├── CONTRIBUTING.md
├── CONTRIBUTORS.md
├── LICENSE
├── NOTICE
├── Notes.txt
├── QuickReference.pdf
├── README.md
├── examples
└── movie
│ ├── build.xml
│ ├── movie.bat
│ └── src
│ └── com
│ └── amd
│ └── aparapi
│ └── examples
│ └── movie
│ ├── AparapiSolution.java
│ ├── ConvMatrix3x3Editor.java
│ ├── JJMPEGPlayer.java
│ ├── PureJavaSolution.java
│ └── ReferenceSolution.java
├── pom.xml
└── src
├── main
├── java
│ └── com
│ │ └── aparapi
│ │ └── examples
│ │ ├── All.java
│ │ ├── add
│ │ └── Main.java
│ │ ├── afmandelbrot
│ │ ├── AfAparapiUtils.java
│ │ ├── AfBenchmark.java
│ │ ├── AfGUI.java
│ │ ├── AfKernel.java
│ │ └── AfMain.java
│ │ ├── blackscholes
│ │ └── Main.java
│ │ ├── configuration
│ │ ├── AutoCleanUpArraysDemo.java
│ │ ├── CleanUpArraysDemo.java
│ │ ├── ConfigurationDemo.java
│ │ ├── CustomConfigurationDemo.java
│ │ ├── KernelOkayInOpenCL.java
│ │ ├── KernelWithAlternateFallbackAlgorithm.java
│ │ ├── KernelWithoutAlternateFallbackAlgorithm.java
│ │ ├── LegacyConfigurationDemo.java
│ │ ├── ProfilingDemo.java
│ │ └── ProfilingDemoNoBinaryCaching.java
│ │ ├── convolution
│ │ ├── ConvMatrix3x3Editor.java
│ │ ├── Convolution.java
│ │ ├── ConvolutionOpenCL.java
│ │ ├── ConvolutionViewer.java
│ │ └── PureJava.java
│ │ ├── effects
│ │ └── Main.java
│ │ ├── extension
│ │ ├── FFTExample.java
│ │ ├── Histogram.java
│ │ ├── HistogramIdeal.java
│ │ ├── JavaMandelBrot.java
│ │ ├── JavaMandelBrotMultiThread.java
│ │ ├── Mandel.java
│ │ ├── MandelBrot.java
│ │ ├── MandelExample.java
│ │ ├── MandelSimple.java
│ │ ├── Pow4Example.java
│ │ ├── SquareExample.java
│ │ ├── StopWatch.java
│ │ └── SwapExample.java
│ │ ├── info
│ │ └── Main.java
│ │ ├── javaonedemo
│ │ ├── Life.java
│ │ ├── Mandel.java
│ │ └── NBody.java
│ │ ├── life
│ │ └── Main.java
│ │ ├── mandel
│ │ ├── Main.java
│ │ └── Main2D.java
│ │ ├── mapreduce
│ │ └── Main.java
│ │ ├── matrix
│ │ ├── CorrMatrixHost.java
│ │ ├── CorrMatrixKernel.java
│ │ └── Main.java
│ │ ├── mdarray
│ │ ├── BMatMul1D.java
│ │ ├── BMatMul2D.java
│ │ ├── BMatMul3D.java
│ │ ├── DMatMul1D.java
│ │ ├── DMatMul2D.java
│ │ ├── DMatMul3D.java
│ │ ├── FMatMul1D.java
│ │ ├── FMatMul2D.java
│ │ ├── FMatMul3D.java
│ │ ├── IMatMul1D.java
│ │ ├── IMatMul2D.java
│ │ ├── IMatMul3D.java
│ │ ├── LMatMul1D.java
│ │ ├── LMatMul2D.java
│ │ ├── LMatMul3D.java
│ │ ├── MDArray.java
│ │ ├── SMatMul1D.java
│ │ ├── SMatMul2D.java
│ │ ├── SMatMul3D.java
│ │ ├── ZMatMul1D.java
│ │ ├── ZMatMul2D.java
│ │ └── ZMatMul3D.java
│ │ ├── median
│ │ ├── MedianDemo.java
│ │ ├── MedianKernel7x7.java
│ │ └── MedianSettings.java
│ │ ├── nbody
│ │ ├── Local.java
│ │ ├── Main.java
│ │ └── Seq.java
│ │ ├── oopnbody
│ │ ├── Body.java
│ │ ├── Main.java
│ │ └── Perspective.java
│ │ ├── progress
│ │ ├── LongRunningKernel.java
│ │ ├── MultiPassKernelSwingWorkerDemo.java
│ │ └── ProgressAndCancelDemo.java
│ │ └── squares
│ │ └── Main.java
└── resources
│ ├── HistogramKernel.cl
│ ├── convolution.cl
│ ├── duke.jpg
│ ├── fft.cl
│ ├── knight.png
│ ├── log4j.properties
│ ├── mandel.cl
│ ├── mandel2.cl
│ ├── moon.jpg
│ ├── particle.jpg
│ ├── squarer.cl
│ └── testcard.jpg
└── test
└── java
└── com
└── aparapi
└── examples
└── matrix
└── CorrMatrixTest.java
/.cz-config.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | module.exports = {
4 |
5 | types: [
6 | {value: 'feat', name: 'feat: A new feature'},
7 | {value: 'fix', name: 'fix: A bug fix'},
8 | {value: 'docs', name: 'docs: Documentation only changes'},
9 | {value: 'style', name: 'style: Changes that do not affect the meaning of the code\n (white-space, formatting, etc)'},
10 | {value: 'refactor', name: 'refactor: A code change that neither fixes a bug nor adds a feature'},
11 | {value: 'perf', name: 'perf: A code change that improves performance'},
12 | {value: 'test', name: 'test: Adding missing tests or correcting existing tests'},
13 | {value: 'build', name: 'build: Changes that affect the build system or external dependencies (example scopes: maven, gradle, npm, gulp)'},
14 | {value: 'ci', name: 'ci: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)'},
15 | {value: 'chore', name: 'chore: Other changes that dont modify src or test files'},
16 | {value: 'revert', name: 'revert: Reverts a previous commit'}
17 | ],
18 |
19 | scopes: [
20 | {name: 'jni'},
21 | {name: 'internal'},
22 | {name: 'swing'},
23 | {name: 'opencl'}
24 | ],
25 |
26 | scopeOverrides: {
27 | build: [
28 | {name: 'dependencies'},
29 | {name: 'versioning'},
30 | {name: 'release'},
31 | {name: 'build plugin'}
32 | ],
33 | ci: [
34 | {name: 'travis'}
35 | ],
36 | chore: [
37 | {name: 'commitizen'},
38 | {name: 'editorconfig'},
39 | {name: 'git'}
40 | ],
41 | docs: [
42 | {name: 'javadocs'},
43 | {name: 'repo'},
44 | {name: 'maven'}
45 | ]
46 | },
47 |
48 | allowCustomScopes: true,
49 | allowBreakingChanges: ['feat', 'fix', 'docs', 'style', 'refactor', 'perf', 'test', 'build', 'ci', 'chore', 'revert']
50 |
51 | };
52 |
--------------------------------------------------------------------------------
/.cz.json:
--------------------------------------------------------------------------------
1 | { "path": "cz-customizable" }
2 |
--------------------------------------------------------------------------------
/ATTRIBUTIONS.md:
--------------------------------------------------------------------------------
1 | This file contains all attributions and other notices that are required by law.
2 |
3 | ## Copyright Notices
4 |
5 | The following are the list of all recognized copyright notices added by contributors to this project:
6 |
7 | Copyright (c) 2016 - 2018, Syncleus, Inc. All rights reserved.
8 |
9 | Copyright (c) 2010-2011, Advanced Micro Devices, Inc. All rights reserved.
10 |
11 | ## Licenses
12 |
13 | Aparapi is currently licensed under the Apache License version 2. However it is important to note that the project
14 | owners decided to migrate licenses back in 2016. Under legal advice of a lawyer it was determined the new license,
15 | Apache License version 2, and was fully relicensed as such. This software, therefore, may be destributed under
16 | the Apache License with no additional restrictions beyond those expressed in the Apache License. However, since
17 | both the original license and the Apache License require copyright text and original license text to be provided
18 | for reference the original wording of the license shall be included here as follows:
19 |
20 | Copyright (c) 2010-2011, Advanced Micro Devices, Inc.
21 | All rights reserved.
22 |
23 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
24 | following conditions are met:
25 |
26 | Redistributions of source code must retain the above copyright notice, this list of conditions and the following
27 | disclaimer.
28 |
29 | Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
30 | disclaimer in the documentation and/or other materials provided with the distribution.
31 |
32 | Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products
33 | derived from this software without specific prior written permission.
34 |
35 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
36 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
37 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
38 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
39 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
40 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
41 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 |
43 | If you use the software (in whole or in part), you shall adhere to all applicable U.S., European, and other export
44 | laws, including but not limited to the U.S. Export Administration Regulations ("EAR"), (15 C.F.R. Sections 730 through
45 | 774), and E.U. Council Regulation (EC) No 1334/2000 of 22 June 2000. Further, pursuant to Section 740.6 of the EAR,
46 | you hereby certify that, except pursuant to a license granted by the United States Department of Commerce Bureau of
47 | Industry and Security or as otherwise permitted pursuant to a License Exception under the U.S. Export Administration
48 | Regulations ("EAR"), you will not (1) export, re-export or release to a national of a country in Country Groups D:1,
49 | E:1 or E:2 any restricted technology, software, or source code you receive hereunder, or (2) export to Country Groups
50 | D:1, E:1 or E:2 the direct product of such technology or software, if such foreign produced direct product is subject
51 | to national security controls as identified on the Commerce Control List (currently found in Supplement 1 to Part 774
52 | of EAR). For the most current Country Group listings, or for additional information about the EAR or your obligations
53 | under those regulations, please refer to the U.S. Bureau of Industry and Security�s website at http://www.bis.doc.gov/.
54 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Aparapi Examples Changelog
2 |
3 | ## 3.0.0
4 |
5 | * Added an interactive Mandlebrot set explorer along with some related benchmarks.
6 | * Updated the following dependency versions:
7 | ** com.aparapi: aparapi 2.0.0 -> 3.0.0
8 | ** org.apache.commons:commons-lang3 3.9 -> 3.12.0
9 | ** org.apache.lucene:lucene-core 8.3.1 -> 8.9.0
10 | ** com.syncleus:syncleus 7 -> 8
11 |
12 | ## 2.0.0
13 |
14 | * Synced to Aparapi 2.0.0
15 |
16 | ## 1.10.0
17 |
18 | * Synced to Aparapi 1.10.0
19 |
20 | ## 1.9.0
21 |
22 | * Synced to Aparapi 1.9.0
23 |
24 | ## v1.8.0
25 |
26 | * Synced to Aparapi 1.8.0
27 | * Updated dependency org.apache.commons:commons-lang3 from 3.6 to 3.7
28 |
29 |
30 | ## 1.7.0
31 |
32 | * Synced to Aparapi 1.7.0
33 |
34 | ## 1.6.0
35 |
36 | * Synced to Aparapi 1.6.0
37 |
38 | ## 1.5.0
39 |
40 | * Synced to Aparapi 1.5.0
41 |
42 |
43 | ## 1.4.1
44 |
45 | * Synced to Aparapi 1.4.1
46 | * Updated parent pon to v6.
47 | * Removed explicit version on nexus-staging-maven-plugin plugin, relies on parent now.
48 | * createProgram had the wrong signature producing a unsatisfied link exception that is now fixed.
49 | * Fixed several bad references to resource locations.
50 | * Fixed all of the broken examples that werent running.
51 |
52 | ## 1.4.0
53 |
54 | * Synced to Aparapi 1.4.0
55 |
56 | ## 1.3.4
57 |
58 | * Synced to Aparapi 1.3.4
59 | * Updated to aparapi-jni 1.1.2 thus fixing `UnsatisfiedLinkError` which occured only on Windows.
60 |
61 | ## 1.3.3
62 |
63 | * Synced to Aparapi 1.3.3
64 | * Fixed "`CXXABI_1.3.8' not found " error encountered on some older systems.
65 |
66 | ## 1.3.2
67 |
68 | * Synced to Aparapi 1.3.2
69 | * Examples now work on Windows 64bit GPUs.
70 |
71 | ## 1.3.1
72 |
73 | * Synced to Aparapi 1.3.1
74 | * Examples now work on Mac OSX SPUs.
75 |
76 | ## 1.3.0
77 |
78 | * Synced to Aparapi 1.3.0.
79 |
80 | ## 1.2.0
81 |
82 | * Synced to Aparapi 1.2.0.
83 |
84 | ## 1.1.2
85 |
86 | * Synced to Aparapi 1.1.2
87 | * Fixed some bugs causing the OpenCL kernel to be compiled twice.
88 |
89 | ## 1.1.1
90 |
91 | * Synced to Aparapi 1.1.1
92 | * Changed package to com.aparapi
93 |
94 | ## 1.1.0
95 |
96 | * Synced to Aparapi 1.1.0
97 | * Changed group id and package to com.aparapi
98 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | [](http://commitizen.github.io/cz-cli/)
4 | [](http://semver.org/spec/v2.0.0.html)
5 | [](https://gitter.im/Syncleus/aparapi?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
6 |
7 | When contributing to this repository, it is usually a good idea to first discuss the change you
8 | wish to make via issue, email, or any other method with the owners of this repository before
9 | making a change. This could potentially save a lot of wasted hours.
10 |
11 | Please note we have a code of conduct, please follow it in all your interactions with the project.
12 |
13 | ## Development
14 |
15 | ### Commit Message Format
16 |
17 | Starting version 1.3.3 and later all commits on the Syncleus Aparapi repository follow the
18 | [Conventional Changelog standard](https://github.com/conventional-changelog/conventional-changelog-eslint/blob/master/convention.md).
19 | It is a very simple format so you can still write commit messages by hand. However it is
20 | highly recommended developers install [Commitizen](https://commitizen.github.io/cz-cli/),
21 | it extends the git command and will make writing commit messages a breeze. All the Aparapi
22 | repositories are configured with local Commitizen configuration scripts.
23 |
24 | Getting Commitizen installed is usually trivial, just install it via npm. You will also
25 | need to install the cz-customizable adapter which the Aparapi repository is configured
26 | to use.
27 |
28 | ```bash
29 |
30 | npm install -g commitizen@2.8.6 cz-customizable@4.0.0
31 | ```
32 |
33 | Below is an example of Commitizen in action. It replaces your usual `git commit` command
34 | with `git cz` instead. The new command takes all the same arguments however it leads you
35 | through an interactive process to generate the commit message.
36 |
37 | 
38 |
39 | Commit messages are used to automatically generate our changelogs, and to ensure
40 | commits are searchable in a useful way. So please use the Commitizen tool and adhere to
41 | the commit message standard or else we cannot accept Pull Requests without editing
42 | them first.
43 |
44 | Below is an example of a properly formated commit message.
45 |
46 | ```
47 | chore(Commitizen): Made repository Commitizen friendly.
48 |
49 | Added standard Commitizen configuration files to the repo along with all the custom rules.
50 |
51 | ISSUES CLOSED: #31
52 | ```
53 |
54 | ### Pull Request Process
55 |
56 | 1. Ensure that install or build dependencies do not appear in any commits in your code branch.
57 | 2. Ensure all commit messages follow the [Conventional Changelog](https://github.com/conventional-changelog/conventional-changelog-eslint/blob/master/convention.md)
58 | standard explained earlier.
59 | 3. Update the CONTRIBUTORS.md file to add your name to it if it isn't already there (one entry
60 | per person).
61 | 4. Adjust the project version to the new version that this Pull Request would represent. The
62 | versioning scheme we use is [Semantic Versioning](http://semver.org/).
63 | 5. Your pull request will either be approved or feedback will be given on what needs to be
64 | fixed to get approval. We usually review and comment on Pull Requests within 48 hours.
65 |
66 | ### Making a Release
67 |
68 | Only administrators with privilages to push to the Aparapi Maven Central account can deploy releases. If this isn't you
69 | then you can just skip this section.
70 |
71 | First ensure the package is prepared for the release process:
72 |
73 | * Make sure any references to the version number in the readme is updated
74 | * Version number in dependency maven snippet.
75 | * Add new version to javadoc version list.
76 | * Ensure that none of the dependencies used are snapshots.
77 | * Update the changelog file.
78 | * Check that all Aparapi libraries used as dependencies point to the latest version.
79 | * After making the release go to the aparapi-docker project and push an image for the new aparapi version
80 |
81 | Next lets take a few steps to do the actual release:
82 |
83 | 1. Update everything listed above. Do **not** drop the package version's `-SNAPSHOT` suffix in master.
84 | 2. Create a release branch, but make sure never to push this branch to the server: `git checkout -b release`.
85 | 3. Update the README.md again to ensure travis badge and javadoc badge point to static tag and not latest.
86 | 4. Drop the `-SNAPSHOT` suffix from the package version.
87 | 5. Commit the current changes using a generic commit message such as `build(release): version 1.2.3`.
88 | 6. Fully test the software before deploying, run all tests and install locally to test against the examples package.
89 | You can install the package locally with `mvn clean install`.
90 | 7. Once satisfied the package is stable deploy it to maven central by executing `mvn -P sign clean package deploy`.
91 | 8. If deployment was successful then create a new tag for the current version with the following command:
92 | `git tag -a v1.2.3 -m "Version 1.2.3"`.
93 | 9. Push the newly created tags to the server: `git push origin v1.2.3:v1.2.3`.
94 | 10. Go to Github and go to the release. Update the description with the changelog for the version and upload
95 | all the artifacts in the target folder.
96 | 10. Checkout master again and then delete the release branch: `git branch -D release`.
97 | 11. Bump the snapshot version of the package to the next expected version, commiting the changes and pushing.
98 | 12. Deploy the new snapshot to the snapshot repository (no need to sign): `mvn clean deploy`.
99 |
--------------------------------------------------------------------------------
/CONTRIBUTORS.md:
--------------------------------------------------------------------------------
1 | # Contributors
2 |
3 | * Jeffrey Phillips Freeman Main class. main.result
.
AutoCleanUpArraysDemo class.
32 | * 33 | * @author freemo 34 | * @version $Id: $Id 35 | */ 36 | public class AutoCleanUpArraysDemo { 37 | /** 38 | *main.
39 | * 40 | * @param ignored an array of {@link java.lang.String} objects. 41 | */ 42 | public static void main(String[] ignored) { 43 | 44 | System.setProperty("com.aparapi.dumpProfileOnExecution", "true"); 45 | 46 | int size = 1024; 47 | int[] rgbs = new int[size * size]; 48 | Main.MandelKernel kernel = new Main.MandelKernel(size, size, rgbs); 49 | kernel.setAutoCleanUpArrays(true); 50 | kernel.execute(size * size); 51 | System.out.println("length = " + kernel.getRgbs().length); 52 | kernel.resetImage(size, size, rgbs); 53 | kernel.execute(size * size); 54 | System.out.println("length = " + kernel.getRgbs().length); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/aparapi/examples/configuration/CleanUpArraysDemo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 - 2018 Syncleus, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * This product currently only contains code developed by authors 18 | * of specific components, as identified by the source code files. 19 | * 20 | * Since product implements StAX API, it has dependencies to StAX API 21 | * classes. 22 | * 23 | * For additional credits (generally to people who reported problems) 24 | * see CREDITS file. 25 | */ 26 | package com.aparapi.examples.configuration; 27 | 28 | import com.aparapi.examples.mandel.Main; 29 | 30 | /** 31 | *CleanUpArraysDemo class.
32 | * 33 | * @author freemo 34 | * @version $Id: $Id 35 | */ 36 | public class CleanUpArraysDemo { 37 | /** 38 | *main.
39 | * 40 | * @param ignored an array of {@link java.lang.String} objects. 41 | */ 42 | public static void main(String[] ignored) { 43 | 44 | System.setProperty("com.aparapi.enableVerboseJNI", "true"); 45 | System.setProperty("com.aparapi.enableVerboseJNIOpenCLResourceTracking", "true"); 46 | System.setProperty("com.aparapi.enableExecutionModeReporting", "true"); 47 | System.setProperty("com.aparapi.dumpProfileOnExecution", "true"); 48 | 49 | int size = 1024; 50 | int[] rgbs = new int[size * size]; 51 | Main.MandelKernel kernel = new Main.MandelKernel(size, size, rgbs); 52 | kernel.execute(size * size); 53 | System.out.println("length = " + kernel.getRgbs().length); 54 | System.out.println("Cleaning up arrays"); 55 | kernel.cleanUpArrays(); 56 | System.out.println("length = " + kernel.getRgbs().length); 57 | kernel.resetImage(size, size, rgbs); 58 | kernel.execute(size * size); 59 | System.out.println("length = " + kernel.getRgbs().length); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/com/aparapi/examples/configuration/ConfigurationDemo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 - 2018 Syncleus, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * This product currently only contains code developed by authors 18 | * of specific components, as identified by the source code files. 19 | * 20 | * Since product implements StAX API, it has dependencies to StAX API 21 | * classes. 22 | * 23 | * For additional credits (generally to people who reported problems) 24 | * see CREDITS file. 25 | */ 26 | package com.aparapi.examples.configuration; 27 | 28 | import com.aparapi.*; 29 | import com.aparapi.internal.kernel.*; 30 | 31 | import java.util.*; 32 | 33 | /** 34 | * Tests device selection via {@link com.aparapi.internal.kernel.KernelManager}. 35 | * 36 | * @author freemo 37 | * @version $Id: $Id 38 | */ 39 | public class ConfigurationDemo { 40 | /** 41 | *main.
42 | * 43 | * @param ignored an array of {@link java.lang.String} objects. 44 | */ 45 | public static void main(String[] ignored) { 46 | StringBuilder report; 47 | 48 | Listmain.
43 | * 44 | * @param ignored an array of {@link java.lang.String} objects. 45 | */ 46 | public static void main(String[] ignored) { 47 | System.setProperty("com.aparapi.dumpProfilesOnExit", "true"); 48 | KernelManager manager = new KernelManager() { 49 | @Override 50 | protected Listmain.
42 | * 43 | * @param ignored an array of {@link java.lang.String} objects. 44 | */ 45 | @SuppressWarnings("deprecation") 46 | public static void main(String[] ignored) { 47 | System.setProperty("com.aparapi.executionMode", "GPU,CPU,SEQ"); 48 | System.setProperty("com.aparapi.dumpProfilesOnExit", "true"); 49 | 50 | KernelWithAlternateFallbackAlgorithm kernel = new KernelWithAlternateFallbackAlgorithm(); 51 | kernel.setExecutionMode(Kernel.EXECUTION_MODE.GPU); 52 | int globalRange = 1; 53 | kernel.execute(globalRange); 54 | 55 | StringBuilder report = new StringBuilder("\n"); 56 | KernelManager.instance().reportDeviceUsage(report, true); 57 | System.out.println(report); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/aparapi/examples/configuration/ProfilingDemo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 - 2018 Syncleus, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * This product currently only contains code developed by authors 18 | * of specific components, as identified by the source code files. 19 | * 20 | * Since product implements StAX API, it has dependencies to StAX API 21 | * classes. 22 | * 23 | * For additional credits (generally to people who reported problems) 24 | * see CREDITS file. 25 | */ 26 | package com.aparapi.examples.configuration; 27 | 28 | import com.aparapi.examples.mandel.Main; 29 | import com.aparapi.*; 30 | import com.aparapi.internal.kernel.*; 31 | 32 | /** 33 | * Demonstrate new enhanced profiling capability, profiling the kernel from the blackscholes sample. 34 | * 35 | * @author freemo 36 | * @version $Id: $Id 37 | */ 38 | public class ProfilingDemo { 39 | 40 | private static com.aparapi.examples.blackscholes.Main.BlackScholesKernel kernel; 41 | 42 | /** 43 | *main.
44 | * 45 | * @param ignored an array of {@link java.lang.String} objects. 46 | */ 47 | public static void main(String[] ignored) { 48 | 49 | final int size = 1024; 50 | newBlackScholesKernel(size); 51 | 52 | // first execute an arbitrary Kernel (not the one we are profiling!) a few times to ensure class loading and initial JIT optimisations have 53 | // been performed before we start the profiling 54 | int warmups = 5; 55 | for (int i = 0; i < warmups; ++i) { 56 | runWarmup(); 57 | } 58 | 59 | String tableHeader = KernelDeviceProfile.getTableHeader(); 60 | 61 | boolean newKernel = false; 62 | 63 | runOnce(size, newKernel); 64 | System.out.println("First run:"); 65 | printLastProfile(tableHeader); 66 | 67 | 68 | int reps = 20; 69 | 70 | System.out.println("\nSubsequent runs using same kernel:"); 71 | for (int rep = 0; rep < reps; ++rep) { 72 | runOnce(size, newKernel); 73 | printLastProfile(tableHeader); 74 | } 75 | 76 | newKernel = true; 77 | System.out.println("\nSubsequent runs using new kernels:"); 78 | for (int rep = 0; rep < reps; ++rep) { 79 | runOnce(size, newKernel); 80 | printLastProfile(tableHeader); 81 | } 82 | 83 | // Note. You will see from the output that there is a substantial cost to Kernel creation (vs Kernel reuse), almost entirely due to KernelRunner#initJNI 84 | 85 | } 86 | 87 | private static void printLastProfile(String tableHeader) { 88 | KernelProfile profile = KernelManager.instance().getProfile(com.aparapi.examples.blackscholes.Main.BlackScholesKernel.class); 89 | KernelDeviceProfile deviceProfile = profile.getLastDeviceProfile(); 90 | String row = deviceProfile.getLastAsTableRow(); 91 | System.out.println(tableHeader); 92 | System.out.println(row); 93 | } 94 | 95 | private static void runOnce(int size, boolean newKernel) { 96 | if (newKernel) { 97 | newBlackScholesKernel(size); 98 | } 99 | kernel.execute(size); 100 | } 101 | 102 | private static void runWarmup() { 103 | int[] rgb = new int[512 * 512]; 104 | Kernel warmupKernel = new Main.MandelKernel(512, 512, rgb); 105 | warmupKernel.execute(512 * 512); 106 | } 107 | 108 | private static void newBlackScholesKernel(int size) { 109 | if (kernel != null) { 110 | kernel.dispose(); 111 | } 112 | System.gc(); 113 | kernel = new com.aparapi.examples.blackscholes.Main.BlackScholesKernel(size); 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /src/main/java/com/aparapi/examples/configuration/ProfilingDemoNoBinaryCaching.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 - 2018 Syncleus, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * This product currently only contains code developed by authors 18 | * of specific components, as identified by the source code files. 19 | * 20 | * Since product implements StAX API, it has dependencies to StAX API 21 | * classes. 22 | * 23 | * For additional credits (generally to people who reported problems) 24 | * see CREDITS file. 25 | */ 26 | package com.aparapi.examples.configuration; 27 | 28 | import com.aparapi.internal.kernel.*; 29 | 30 | /** 31 | * Created by Barney on 13/09/2015. 32 | * 33 | * @author freemo 34 | * @version $Id: $Id 35 | */ 36 | public class ProfilingDemoNoBinaryCaching { 37 | 38 | /** 39 | *main.
40 | * 41 | * @param ignored an array of {@link java.lang.String} objects. 42 | */ 43 | public static void main(String[] ignored) { 44 | KernelRunner.BINARY_CACHING_DISABLED = true; 45 | ProfilingDemo.main(null); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/aparapi/examples/convolution/ConvolutionOpenCL.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 - 2018 Syncleus, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * This product currently only contains code developed by authors 18 | * of specific components, as identified by the source code files. 19 | * 20 | * Since product implements StAX API, it has dependencies to StAX API 21 | * classes. 22 | * 23 | * For additional credits (generally to people who reported problems) 24 | * see CREDITS file. 25 | */ 26 | /* 27 | Copyright (c) 2010-2011, Advanced Micro Devices, Inc. 28 | All rights reserved. 29 | 30 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the 31 | following conditions are met: 32 | 33 | Redistributions of source code must retain the above copyright notice, this list of conditions and the following 34 | disclaimer. 35 | 36 | Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following 37 | disclaimer in the documentation and/or other materials provided with the distribution. 38 | 39 | Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products 40 | derived from this software without specific prior written permission. 41 | 42 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 43 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 44 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 45 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 46 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 47 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 48 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 49 | 50 | If you use the software (in whole or in part), you shall adhere to all applicable U.S., European, and other export 51 | laws, including but not limited to the U.S. Export Administration Regulations ("EAR"), (15 C.F.R. Sections 730 through 52 | 774), and E.U. Council Regulation (EC) No 1334/2000 of 22 June 2000. Further, pursuant to Section 740.6 of the EAR, 53 | you hereby certify that, except pursuant to a license granted by the United States Department of Commerce Bureau of 54 | Industry and Security or as otherwise permitted pursuant to a License Exception under the U.S. Export Administration 55 | Regulations ("EAR"), you will not (1) export, re-export or release to a national of a country in Country Groups D:1, 56 | E:1 or E:2 any restricted technology, software, or source code you receive hereunder, or (2) export to Country Groups 57 | D:1, E:1 or E:2 the direct product of such technology or software, if such foreign produced direct product is subject 58 | to national security controls as identified on the Commerce Control List (currently found in Supplement 1 to Part 774 59 | of EAR). For the most current Country Group listings, or for additional information about the EAR or your obligations 60 | under those regulations, please refer to the U.S. Bureau of Industry and Security's website at http://www.bis.doc.gov/. 61 | 62 | */ 63 | 64 | package com.aparapi.examples.convolution; 65 | 66 | import com.aparapi.*; 67 | import com.aparapi.device.*; 68 | import com.aparapi.internal.kernel.*; 69 | import com.aparapi.opencl.*; 70 | import com.aparapi.opencl.OpenCL.*; 71 | 72 | import java.io.*; 73 | import java.net.URISyntaxException; 74 | 75 | /** 76 | *ConvolutionOpenCL class.
77 | * 78 | * @author freemo 79 | * @version $Id: $Id 80 | */ 81 | public class ConvolutionOpenCL{ 82 | 83 | @Resource("convolution.cl") interface Convolution extends OpenCLmain.
95 | * 96 | * @param _args an array of {@link java.lang.String} objects. 97 | */ 98 | public static void main(final String[] _args) { 99 | final File file; 100 | try{ 101 | file = new File(ConvolutionOpenCL.class.getResource("/testcard.jpg").toURI()); 102 | } catch (URISyntaxException e) { 103 | throw new IllegalStateException("could not get testcard", e); 104 | } 105 | 106 | final OpenCLDevice openclDevice = (OpenCLDevice) KernelManager.instance().bestDevice(); 107 | 108 | final Convolution convolution = openclDevice.bind(Convolution.class); 109 | final float convMatrix3x3[] = new float[] { 110 | 0f, 111 | -10f, 112 | 0f, 113 | -10f, 114 | 40f, 115 | -10f, 116 | 0f, 117 | -10f, 118 | 0f, 119 | }; 120 | 121 | new ConvolutionViewer(file, convMatrix3x3){ 122 | Range range = null; 123 | 124 | @Override protected void applyConvolution(float[] _convMatrix3x3, byte[] _inBytes, byte[] _outBytes, int _width, 125 | int _height) { 126 | if (range == null) { 127 | range = openclDevice.createRange(_width * _height * 3); 128 | } 129 | 130 | convolution.applyConvolution(range, _convMatrix3x3, _inBytes, _outBytes, _width, _height); 131 | } 132 | }; 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /src/main/java/com/aparapi/examples/convolution/PureJava.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 - 2018 Syncleus, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * This product currently only contains code developed by authors 18 | * of specific components, as identified by the source code files. 19 | * 20 | * Since product implements StAX API, it has dependencies to StAX API 21 | * classes. 22 | * 23 | * For additional credits (generally to people who reported problems) 24 | * see CREDITS file. 25 | */ 26 | /* 27 | Copyright (c) 2010-2011, Advanced Micro Devices, Inc. 28 | All rights reserved. 29 | 30 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the 31 | following conditions are met: 32 | 33 | Redistributions of source code must retain the above copyright notice, this list of conditions and the following 34 | disclaimer. 35 | 36 | Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following 37 | disclaimer in the documentation and/or other materials provided with the distribution. 38 | 39 | Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products 40 | derived from this software without specific prior written permission. 41 | 42 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 43 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 44 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 45 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 46 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 47 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 48 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 49 | 50 | If you use the software (in whole or in part), you shall adhere to all applicable U.S., European, and other export 51 | laws, including but not limited to the U.S. Export Administration Regulations ("EAR"), (15 C.F.R. Sections 730 through 52 | 774), and E.U. Council Regulation (EC) No 1334/2000 of 22 June 2000. Further, pursuant to Section 740.6 of the EAR, 53 | you hereby certify that, except pursuant to a license granted by the United States Department of Commerce Bureau of 54 | Industry and Security or as otherwise permitted pursuant to a License Exception under the U.S. Export Administration 55 | Regulations ("EAR"), you will not (1) export, re-export or release to a national of a country in Country Groups D:1, 56 | E:1 or E:2 any restricted technology, software, or source code you receive hereunder, or (2) export to Country Groups 57 | D:1, E:1 or E:2 the direct product of such technology or software, if such foreign produced direct product is subject 58 | to national security controls as identified on the Commerce Control List (currently found in Supplement 1 to Part 774 59 | of EAR). For the most current Country Group listings, or for additional information about the EAR or your obligations 60 | under those regulations, please refer to the U.S. Bureau of Industry and Security's website at http://www.bis.doc.gov/. 61 | 62 | */ 63 | 64 | package com.aparapi.examples.convolution; 65 | 66 | import java.io.File; 67 | import java.net.URISyntaxException; 68 | 69 | import com.aparapi.Kernel; 70 | 71 | /** 72 | *PureJava class.
73 | * 74 | * @author freemo 75 | * @version $Id: $Id 76 | */ 77 | public class PureJava{ 78 | 79 | final static class ImageConvolution extends Kernel{ 80 | private float convMatrix3x3[]; 81 | 82 | private int width, height; 83 | 84 | private byte imageIn[], imageOut[]; 85 | 86 | public void processPixel(int x, int y, int w, int h) { 87 | float accum = 0f; 88 | int count = 0; 89 | for (int dx = -3; dx < 6; dx += 3) { 90 | for (int dy = -1; dy < 2; dy += 1) { 91 | int rgb = 0xff & imageIn[((y + dy) * w) + (x + dx)]; 92 | 93 | accum += rgb * convMatrix3x3[count++]; 94 | } 95 | } 96 | byte value = (byte) (max(0, min((int) accum, 255))); 97 | imageOut[y * w + x] = value; 98 | 99 | } 100 | 101 | @Override public void run() { 102 | int x = getGlobalId(0) % (width * 3); 103 | int y = getGlobalId(0) / (width * 3); 104 | 105 | if (x > 3 && x < (width * 3 - 3) && y > 1 && y < (height - 1)) { 106 | processPixel(x, y, width * 3, height); 107 | } 108 | 109 | } 110 | 111 | public void applyConvolution(float[] _convMatrix3x3, byte[] _imageIn, byte[] _imageOut, int _width, int _height) { 112 | imageIn = _imageIn; 113 | imageOut = _imageOut; 114 | width = _width; 115 | height = _height; 116 | convMatrix3x3 = _convMatrix3x3; 117 | 118 | execute(3 * width * height); 119 | } 120 | 121 | } 122 | 123 | /** 124 | *main.
125 | * 126 | * @param _args an array of {@link java.lang.String} objects. 127 | */ 128 | public static void main(final String[] _args) { 129 | final File file; 130 | try{ 131 | file = new File(PureJava.class.getResource("/testcard.jpg").toURI()); 132 | } catch (URISyntaxException e) { 133 | throw new IllegalStateException("could not get testcard", e); 134 | } 135 | 136 | final ImageConvolution convolution = new ImageConvolution(); 137 | 138 | float convMatrix3x3[] = new float[] { 139 | 0f, 140 | -10f, 141 | 0f, 142 | -10f, 143 | 40f, 144 | -10f, 145 | 0f, 146 | -10f, 147 | 0f, 148 | }; 149 | 150 | new ConvolutionViewer(file, convMatrix3x3){ 151 | @Override protected void applyConvolution(float[] _convMatrix3x3, byte[] _inBytes, byte[] _outBytes, int _width, 152 | int _height) { 153 | convolution.applyConvolution(_convMatrix3x3, _inBytes, _outBytes, _width, _height); 154 | } 155 | }; 156 | 157 | } 158 | 159 | } 160 | -------------------------------------------------------------------------------- /src/main/java/com/aparapi/examples/extension/FFTExample.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 - 2018 Syncleus, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * This product currently only contains code developed by authors 18 | * of specific components, as identified by the source code files. 19 | * 20 | * Since product implements StAX API, it has dependencies to StAX API 21 | * classes. 22 | * 23 | * For additional credits (generally to people who reported problems) 24 | * see CREDITS file. 25 | */ 26 | package com.aparapi.examples.extension; 27 | 28 | import com.aparapi.*; 29 | import com.aparapi.device.*; 30 | import com.aparapi.internal.kernel.*; 31 | import com.aparapi.opencl.*; 32 | import com.aparapi.opencl.OpenCL.*; 33 | 34 | import java.util.*; 35 | 36 | /** 37 | *FFTExample class.
38 | * 39 | * @author freemo 40 | * @version $Id: $Id 41 | */ 42 | public class FFTExample{ 43 | 44 | @Resource("fft.cl") 45 | interface FFT extends OpenCLHistogram class.
37 | * 38 | * @author freemo 39 | * @version $Id: $Id 40 | */ 41 | public class Histogram{ 42 | 43 | @Resource("HistogramKernel.cl") interface HistogramKernel extends OpenCLmain.
61 | * 62 | * @param args an array of {@link java.lang.String} objects. 63 | */ 64 | public static void main(String[] args) { 65 | final int WIDTH = 1024 * 16; 66 | final int HEIGHT = 1024 * 8; 67 | final int BIN_SIZE = 128; 68 | final int GROUP_SIZE = 128; 69 | final int SUB_HISTOGRAM_COUNT = ((WIDTH * HEIGHT) / (GROUP_SIZE * BIN_SIZE)); 70 | 71 | final byte[] data = new byte[WIDTH * HEIGHT]; 72 | for (int i = 0; i < (WIDTH * HEIGHT); i++) { 73 | data[i] = (byte) ((Math.random() * BIN_SIZE) / 2); 74 | } 75 | final byte[] sharedArray = new byte[GROUP_SIZE * BIN_SIZE]; 76 | final int[] binResult = new int[SUB_HISTOGRAM_COUNT * BIN_SIZE]; 77 | System.out.println("binResult size=" + binResult.length); 78 | final int[] histo = new int[BIN_SIZE]; 79 | final int[] refHisto = new int[BIN_SIZE]; 80 | final Kernel k = new Kernel(){ 81 | 82 | @Override public void run() { 83 | final int j = getGlobalId(0); 84 | for (int i = 0; i < SUB_HISTOGRAM_COUNT; ++i) { 85 | histo[j] += binResult[(i * BIN_SIZE) + j]; 86 | } 87 | } 88 | 89 | }; 90 | final Device device = k.getTargetDevice(); 91 | final Range range2 = device.createRange(BIN_SIZE); 92 | k.execute(range2); 93 | 94 | final Range range = Range.create((WIDTH * HEIGHT) / BIN_SIZE, GROUP_SIZE); 95 | 96 | if (device instanceof OpenCLDevice) { 97 | final OpenCLDevice openclDevice = (OpenCLDevice) device; 98 | 99 | final HistogramKernel histogram = openclDevice.bind(HistogramKernel.class); 100 | 101 | final StopWatch timer = new StopWatch(); 102 | timer.start(); 103 | 104 | histogram.histogram256(range, data, sharedArray, binResult, BIN_SIZE); 105 | final boolean java = false; 106 | final boolean aparapiKernel = false; 107 | if (java) { 108 | // Calculate final histogram bin 109 | for (int j = 0; j < BIN_SIZE; ++j) { 110 | for (int i = 0; i < SUB_HISTOGRAM_COUNT; ++i) { 111 | histo[j] += binResult[(i * BIN_SIZE) + j]; 112 | } 113 | } 114 | } else if (aparapiKernel) { 115 | k.execute(range2); 116 | } else { 117 | histogram.bin256(range2, histo, binResult, SUB_HISTOGRAM_COUNT); 118 | } 119 | timer.print("opencl"); 120 | timer.start(); 121 | for (int i = 0; i < (WIDTH * HEIGHT); i++) { 122 | refHisto[data[i]]++; 123 | } 124 | timer.print("java"); 125 | for (int i = 0; i < 128; i++) { 126 | if (refHisto[i] != histo[i]) { 127 | System.out.println(i + " " + histo[i] + " " + refHisto[i]); 128 | } 129 | } 130 | } 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /src/main/java/com/aparapi/examples/extension/HistogramIdeal.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 - 2018 Syncleus, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * This product currently only contains code developed by authors 18 | * of specific components, as identified by the source code files. 19 | * 20 | * Since product implements StAX API, it has dependencies to StAX API 21 | * classes. 22 | * 23 | * For additional credits (generally to people who reported problems) 24 | * see CREDITS file. 25 | */ 26 | package com.aparapi.examples.extension; 27 | 28 | import com.aparapi.Range; 29 | import com.aparapi.device.Device; 30 | import com.aparapi.device.OpenCLDevice; 31 | import com.aparapi.internal.kernel.*; 32 | import com.aparapi.opencl.OpenCL; 33 | 34 | /** 35 | *HistogramIdeal class.
36 | * 37 | * @author freemo 38 | * @version $Id: $Id 39 | */ 40 | public class HistogramIdeal{ 41 | 42 | // @Resource("com/amd/aparapi/sample/extension/HistogramKernel.cl") 43 | interface HistogramKernel extends OpenCLmain.
61 | * 62 | * @param args an array of {@link java.lang.String} objects. 63 | */ 64 | public static void main(String[] args) { 65 | final int WIDTH = 1024 * 16; 66 | final int HEIGHT = 1024 * 8; 67 | final int BIN_SIZE = 128; 68 | final int GROUP_SIZE = 128; 69 | final int SUB_HISTOGRAM_COUNT = ((WIDTH * HEIGHT) / (GROUP_SIZE * BIN_SIZE)); 70 | 71 | final byte[] data = new byte[WIDTH * HEIGHT]; 72 | for (int i = 0; i < (WIDTH * HEIGHT); i++) { 73 | data[i] = (byte) ((Math.random() * BIN_SIZE) / 2); 74 | } 75 | final byte[] sharedArray = new byte[GROUP_SIZE * BIN_SIZE]; 76 | final int[] binResult = new int[SUB_HISTOGRAM_COUNT * BIN_SIZE]; 77 | System.out.println("binResult size=" + binResult.length); 78 | final int[] histo = new int[BIN_SIZE]; 79 | final int[] refHisto = new int[BIN_SIZE]; 80 | final Device device = KernelManager.instance().bestDevice(); 81 | 82 | if (device != null) { 83 | System.out.println(((OpenCLDevice) device).getOpenCLPlatform().getName()); 84 | final Range rangeBinSize = device.createRange(BIN_SIZE); 85 | 86 | final Range range = Range.create((WIDTH * HEIGHT) / BIN_SIZE, GROUP_SIZE); 87 | 88 | if (device instanceof OpenCLDevice) { 89 | final OpenCLDevice openclDevice = (OpenCLDevice) device; 90 | 91 | final HistogramKernel histogram = openclDevice.bind(HistogramKernel.class, Histogram.class.getClassLoader() 92 | .getResourceAsStream("HistogramKernel.cl")); 93 | long start = System.nanoTime(); 94 | histogram.begin()// 95 | .put(data)// 96 | .histogram256(range, data, sharedArray, binResult, BIN_SIZE)// 97 | // by leaving binResult on the GPU we can save two 1Mb transfers 98 | .bin256(rangeBinSize, histo, binResult, SUB_HISTOGRAM_COUNT)// 99 | .get(histo)// 100 | .end(); 101 | System.out.println("opencl " + ((System.nanoTime() - start) / 1000000)); 102 | start = System.nanoTime(); 103 | for (int i = 0; i < (WIDTH * HEIGHT); i++) { 104 | refHisto[data[i]]++; 105 | } 106 | System.out.println("java " + ((System.nanoTime() - start) / 1000000)); 107 | for (int i = 0; i < 128; i++) { 108 | if (refHisto[i] != histo[i]) { 109 | System.out.println(i + " " + histo[i] + " " + refHisto[i]); 110 | } 111 | } 112 | 113 | } 114 | } else { 115 | System.out.println("no GPU device"); 116 | } 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /src/main/java/com/aparapi/examples/extension/JavaMandelBrot.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 - 2018 Syncleus, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * This product currently only contains code developed by authors 18 | * of specific components, as identified by the source code files. 19 | * 20 | * Since product implements StAX API, it has dependencies to StAX API 21 | * classes. 22 | * 23 | * For additional credits (generally to people who reported problems) 24 | * see CREDITS file. 25 | */ 26 | package com.aparapi.examples.extension; 27 | 28 | import com.aparapi.*; 29 | import com.aparapi.device.*; 30 | import com.aparapi.internal.kernel.*; 31 | import com.aparapi.opencl.*; 32 | 33 | /** 34 | *JavaMandelBrot class.
35 | * 36 | * @author freemo 37 | * @version $Id: $Id 38 | */ 39 | public class JavaMandelBrot extends OpenCLAdapterJavaMandelBrotMultiThread class.
38 | * 39 | * @author freemo 40 | * @version $Id: $Id 41 | */ 42 | public class JavaMandelBrotMultiThread extends OpenCLAdaptercreateMandleBrot.
56 | * 57 | * @param range a {@link com.aparapi.Range} object. 58 | * @param scale a float. 59 | * @param offsetx a float. 60 | * @param offsety a float. 61 | * @param rgb an array of {@link int} objects. 62 | * @return a {@link com.aparapi.examples.extension.Mandel} object. 63 | */ 64 | Mandel createMandleBrot(// 65 | Range range,// 66 | @Arg("scale") float scale, // 67 | @Arg("offsetx") float offsetx, // 68 | @Arg("offsety") float offsety, // 69 | @GlobalWriteOnly("rgb") int[] rgb); 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/com/aparapi/examples/extension/MandelBrot.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 - 2018 Syncleus, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * This product currently only contains code developed by authors 18 | * of specific components, as identified by the source code files. 19 | * 20 | * Since product implements StAX API, it has dependencies to StAX API 21 | * classes. 22 | * 23 | * For additional credits (generally to people who reported problems) 24 | * see CREDITS file. 25 | */ 26 | package com.aparapi.examples.extension; 27 | 28 | import com.aparapi.*; 29 | import com.aparapi.device.*; 30 | import com.aparapi.internal.kernel.*; 31 | import com.aparapi.opencl.*; 32 | import com.aparapi.opencl.OpenCL.Resource; 33 | 34 | /** 35 | * An example Aparapi application which displays a view of the Mandelbrot set and lets the user zoom in to a particular point. 36 | * 37 | * When the user clicks on the view, this example application will zoom in to the clicked point and zoom out there after. 38 | * On GPU, additional computing units will offer a better viewing experience. On the other hand on CPU, this example 39 | * application might suffer with sub-optimal frame refresh rate as compared to GPU. 40 | * 41 | * @author gfrost 42 | * @version $Id: $Id 43 | */ 44 | 45 | @Resource("mandel2.cl") 46 | public interface MandelBrot extends OpenCLcreateMandleBrot.
49 | * 50 | * @param range a {@link com.aparapi.Range} object. 51 | * @param scale a float. 52 | * @param offsetx a float. 53 | * @param offsety a float. 54 | * @param rgb an array of {@link int} objects. 55 | * @return a {@link com.aparapi.examples.extension.MandelBrot} object. 56 | */ 57 | MandelBrot createMandleBrot(// 58 | Range range,// 59 | @Arg("scale") float scale, // 60 | @Arg("offsetx") float offsetx, // 61 | @Arg("offsety") float offsety, // 62 | @GlobalWriteOnly("rgb") int[] rgb); 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/aparapi/examples/extension/Pow4Example.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 - 2018 Syncleus, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * This product currently only contains code developed by authors 18 | * of specific components, as identified by the source code files. 19 | * 20 | * Since product implements StAX API, it has dependencies to StAX API 21 | * classes. 22 | * 23 | * For additional credits (generally to people who reported problems) 24 | * see CREDITS file. 25 | */ 26 | package com.aparapi.examples.extension; 27 | 28 | import com.aparapi.Range; 29 | import com.aparapi.device.Device; 30 | import com.aparapi.device.OpenCLDevice; 31 | import com.aparapi.internal.kernel.*; 32 | import com.aparapi.opencl.OpenCL; 33 | import com.aparapi.opencl.OpenCL.Resource; 34 | 35 | /** 36 | *Pow4Example class.
37 | * 38 | * @author freemo 39 | * @version $Id: $Id 40 | */ 41 | public class Pow4Example{ 42 | 43 | @Resource("squarer.cl") 44 | interface Squarer extends OpenCLmain.
54 | * 55 | * @param args an array of {@link java.lang.String} objects. 56 | */ 57 | public static void main(String[] args) { 58 | 59 | final int size = 32; 60 | final float[] in = new float[size]; 61 | for (int i = 0; i < size; i++) { 62 | in[i] = i; 63 | } 64 | final float[] squares = new float[size]; 65 | final Range range = Range.create(size); 66 | 67 | final Device device = KernelManager.instance().bestDevice(); 68 | 69 | if (device instanceof OpenCLDevice) { 70 | final OpenCLDevice openclDevice = (OpenCLDevice) device; 71 | 72 | final Squarer squarer = openclDevice.bind(Squarer.class); 73 | squarer.square(range, in, squares); 74 | 75 | for (int i = 0; i < size; i++) { 76 | System.out.println(in[i] + " " + squares[i]); 77 | } 78 | 79 | squarer.square(range, squares, in); 80 | 81 | for (int i = 0; i < size; i++) { 82 | System.out.println(i + " " + squares[i] + " " + in[i]); 83 | } 84 | } 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/com/aparapi/examples/extension/SquareExample.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 - 2018 Syncleus, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * This product currently only contains code developed by authors 18 | * of specific components, as identified by the source code files. 19 | * 20 | * Since product implements StAX API, it has dependencies to StAX API 21 | * classes. 22 | * 23 | * For additional credits (generally to people who reported problems) 24 | * see CREDITS file. 25 | */ 26 | package com.aparapi.examples.extension; 27 | 28 | import com.aparapi.ProfileInfo; 29 | import com.aparapi.Range; 30 | import com.aparapi.device.Device; 31 | import com.aparapi.device.OpenCLDevice; 32 | import com.aparapi.internal.kernel.*; 33 | import com.aparapi.opencl.OpenCL; 34 | import com.aparapi.opencl.OpenCL.Resource; 35 | import com.aparapi.opencl.OpenCL.Source; 36 | import java.util.List; 37 | 38 | /** 39 | *SquareExample class.
40 | * 41 | * @author freemo 42 | * @version $Id: $Id 43 | */ 44 | public class SquareExample{ 45 | 46 | interface Squarer extends OpenCLmain.
79 | * 80 | * @param args an array of {@link java.lang.String} objects. 81 | */ 82 | public static void main(String[] args) { 83 | final int size = 32; 84 | final float[] in = new float[size]; 85 | 86 | for (int i = 0; i < size; i++) { 87 | in[i] = i; 88 | } 89 | 90 | final float[] squares = new float[size]; 91 | final float[] quads = new float[size]; 92 | final Range range = Range.create(size); 93 | 94 | final Device device = KernelManager.instance().bestDevice(); 95 | 96 | if (device instanceof OpenCLDevice) { 97 | final OpenCLDevice openclDevice = (OpenCLDevice) device; 98 | 99 | for (int l=0; l<5; l++){ 100 | 101 | final SquarerWithResource squarer = openclDevice.bind(SquarerWithResource.class); 102 | squarer.square(range, in, squares); 103 | 104 | for (int i = 0; i < size; i++) { 105 | System.out.println(l+" "+in[i] + " " + squares[i]); 106 | } 107 | 108 | squarer.square(range, squares, quads); 109 | 110 | for (int i = 0; i < size; i++) { 111 | System.out.println(l+" "+ in[i] + " " + squares[i] + " " + quads[i]); 112 | } 113 | final ListStopWatch class.
30 | * 31 | * @author freemo 32 | * @version $Id: $Id 33 | */ 34 | public class StopWatch{ 35 | long start = 0L; 36 | 37 | /** 38 | *start.
39 | */ 40 | public void start() { 41 | start = System.nanoTime(); 42 | } 43 | 44 | /** 45 | *print.
46 | * 47 | * @param _str a {@link java.lang.String} object. 48 | */ 49 | public void print(String _str) { 50 | long end = (System.nanoTime() - start) / 1000000; 51 | System.out.println(_str + " " + end); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/aparapi/examples/extension/SwapExample.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 - 2018 Syncleus, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * This product currently only contains code developed by authors 18 | * of specific components, as identified by the source code files. 19 | * 20 | * Since product implements StAX API, it has dependencies to StAX API 21 | * classes. 22 | * 23 | * For additional credits (generally to people who reported problems) 24 | * see CREDITS file. 25 | */ 26 | package com.aparapi.examples.extension; 27 | 28 | import com.aparapi.Range; 29 | import com.aparapi.device.Device; 30 | import com.aparapi.device.OpenCLDevice; 31 | import com.aparapi.internal.kernel.*; 32 | import com.aparapi.opencl.OpenCL; 33 | 34 | /** 35 | *SwapExample class.
36 | * 37 | * @author freemo 38 | * @version $Id: $Id 39 | */ 40 | public class SwapExample{ 41 | 42 | interface Swapper extends OpenCLmain.
56 | * 57 | * @param args an array of {@link java.lang.String} objects. 58 | */ 59 | public static void main(String[] args) { 60 | 61 | final int size = 32; 62 | final float[] lhs = new float[size]; 63 | for (int i = 0; i < size; i++) { 64 | lhs[i] = i; 65 | } 66 | final float[] rhs = new float[size]; 67 | final Range range = Range.create(size); 68 | 69 | final Device device = KernelManager.instance().bestDevice(); 70 | 71 | if (device instanceof OpenCLDevice) { 72 | final OpenCLDevice openclDevice = (OpenCLDevice) device; 73 | 74 | final Swapper swapper = openclDevice.bind(Swapper.class); 75 | for (int i = 0; i < size; i++) { 76 | System.out.println(lhs[i] + " " + rhs[i]); 77 | } 78 | 79 | swapper.swap(range, lhs, rhs); 80 | 81 | for (int i = 0; i < size; i++) { 82 | System.out.println(lhs[i] + " " + rhs[i]); 83 | } 84 | 85 | swapper.swap(range, lhs, rhs); 86 | 87 | for (int i = 0; i < size; i++) { 88 | System.out.println(lhs[i] + " " + rhs[i]); 89 | } 90 | 91 | swapper.swap(range, rhs, lhs); 92 | 93 | for (int i = 0; i < size; i++) { 94 | System.out.println(lhs[i] + " " + rhs[i]); 95 | } 96 | 97 | } 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /src/main/java/com/aparapi/examples/info/Main.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 - 2018 Syncleus, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * This product currently only contains code developed by authors 18 | * of specific components, as identified by the source code files. 19 | * 20 | * Since product implements StAX API, it has dependencies to StAX API 21 | * classes. 22 | * 23 | * For additional credits (generally to people who reported problems) 24 | * see CREDITS file. 25 | */ 26 | /* 27 | Copyright (c) 2010-2011, Advanced Micro Devices, Inc. 28 | All rights reserved. 29 | 30 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the 31 | following conditions are met: 32 | 33 | Redistributions of source code must retain the above copyright notice, this list of conditions and the following 34 | disclaimer. 35 | 36 | Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following 37 | disclaimer in the documentation and/or other materials provided with the distribution. 38 | 39 | Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products 40 | derived from this software without specific prior written permission. 41 | 42 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 43 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 44 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 45 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 46 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 47 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 48 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 49 | 50 | If you use the software (in whole or in part), you shall adhere to all applicable U.S., European, and other export 51 | laws, including but not limited to the U.S. Export Administration Regulations ("EAR"), (15 C.F.R. Sections 730 through 52 | 774), and E.U. Council Regulation (EC) No 1334/2000 of 22 June 2000. Further, pursuant to Section 740.6 of the EAR, 53 | you hereby certify that, except pursuant to a license granted by the United States Department of Commerce Bureau of 54 | Industry and Security or as otherwise permitted pursuant to a License Exception under the U.S. Export Administration 55 | Regulations ("EAR"), you will not (1) export, re-export or release to a national of a country in Country Groups D:1, 56 | E:1 or E:2 any restricted technology, software, or source code you receive hereunder, or (2) export to Country Groups 57 | D:1, E:1 or E:2 the direct product of such technology or software, if such foreign produced direct product is subject 58 | to national security controls as identified on the Commerce Control List (currently found in Supplement 1 to Part 774 59 | of EAR). For the most current Country Group listings, or for additional information about the EAR or your obligations 60 | under those regulations, please refer to the U.S. Bureau of Industry and Security's website at http://www.bis.doc.gov/. 61 | 62 | */ 63 | 64 | package com.aparapi.examples.info; 65 | 66 | import com.aparapi.device.*; 67 | import com.aparapi.internal.kernel.*; 68 | import com.aparapi.internal.opencl.*; 69 | 70 | import java.util.*; 71 | 72 | /** 73 | *Main class.
74 | * 75 | * @author freemo 76 | * @version $Id: $Id 77 | */ 78 | public class Main{ 79 | /** 80 | *main.
81 | * 82 | * @param _args an array of {@link java.lang.String} objects. 83 | */ 84 | public static void main(String[] _args) { 85 | System.out.println("com.aparapi.examples.info.Main"); 86 | ListMain class.
25 | * 26 | * @author freemo 27 | * @version $Id: $Id 28 | */ 29 | public class Main { 30 | /** 31 | *main.
32 | * 33 | * @param args an array of {@link java.lang.String} objects. 34 | */ 35 | public static void main(String[] args) { 36 | int size = 1048576; 37 | final int count = 3; 38 | final int[] V = new int[size]; 39 | 40 | //lets fill in V randomly... 41 | for (int i = 0; i < size; i++) { 42 | //random number either 0, 1, or 2 43 | V[i] = (int) (Math.random() * 3); 44 | } 45 | 46 | //this will hold our values between the phases. 47 | int[][] totals = new int[count][size]; 48 | 49 | /////////////// 50 | // MAP PHASE // 51 | /////////////// 52 | final int[][] kernelTotals = totals; 53 | Kernel mapKernel = new Kernel() { 54 | @Override 55 | public void run() { 56 | int gid = getGlobalId(); 57 | int value = V[gid]; 58 | for(int index = 0; index < count; index++) { 59 | if (value == index) 60 | kernelTotals[index][gid] = 1; 61 | } 62 | } 63 | }; 64 | mapKernel.execute(Range.create(size)); 65 | mapKernel.dispose(); 66 | totals = kernelTotals; 67 | 68 | ////////////////// 69 | // REDUCE PHASE // 70 | ////////////////// 71 | while (size > 1) { 72 | int nextSize = size / 2; 73 | final int[][] currentTotals = totals; 74 | final int[][] nextTotals = new int[count][nextSize]; 75 | Kernel reduceKernel = new Kernel() { 76 | @Override 77 | public void run() { 78 | int gid = getGlobalId(); 79 | for(int index = 0; index < count; index++) { 80 | nextTotals[index][gid] = currentTotals[index][gid * 2] + currentTotals[index][gid * 2 + 1]; 81 | } 82 | } 83 | }; 84 | reduceKernel.execute(Range.create(nextSize)); 85 | reduceKernel.dispose(); 86 | 87 | totals = nextTotals; 88 | size = nextSize; 89 | } 90 | assert size == 1; 91 | 92 | ///////////////////////////// 93 | // Done, just print it out // 94 | ///////////////////////////// 95 | int[] results = new int[3]; 96 | results[0] = totals[0][0]; 97 | results[1] = totals[1][0]; 98 | results[2] = totals[2][0]; 99 | 100 | System.out.println(Arrays.toString(results)); 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /src/main/java/com/aparapi/examples/mdarray/BMatMul1D.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 - 2018 Syncleus, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * This product currently only contains code developed by authors 18 | * of specific components, as identified by the source code files. 19 | * 20 | * Since product implements StAX API, it has dependencies to StAX API 21 | * classes. 22 | * 23 | * For additional credits (generally to people who reported problems) 24 | * see CREDITS file. 25 | */ 26 | package com.aparapi.examples.mdarray; 27 | 28 | import com.aparapi.Kernel; 29 | 30 | class BMatMul1D extends Kernel{ 31 | byte[] A; 32 | 33 | byte[] B; 34 | 35 | byte[] C; 36 | 37 | int N; 38 | 39 | /** 40 | *Constructor for BMatMul1D.
41 | * 42 | * @param A an array of {@link byte} objects. 43 | * @param B an array of {@link byte} objects. 44 | * @param C an array of {@link byte} objects. 45 | * @param N a int. 46 | */ 47 | public BMatMul1D(byte[] A, byte[] B, byte[] C, int N) { 48 | this.A = A; 49 | this.B = B; 50 | this.C = C; 51 | this.N = N; 52 | } 53 | 54 | /** {@inheritDoc} */ 55 | @Override public void run() { 56 | int id = getGlobalId(); 57 | int i = id / N; 58 | int j = id % N; 59 | for (int k = 0; k < N; k++) { 60 | C[i * N + j] += (byte) (A[i * N + k] * B[k * N + j]); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/aparapi/examples/mdarray/BMatMul2D.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 - 2018 Syncleus, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * This product currently only contains code developed by authors 18 | * of specific components, as identified by the source code files. 19 | * 20 | * Since product implements StAX API, it has dependencies to StAX API 21 | * classes. 22 | * 23 | * For additional credits (generally to people who reported problems) 24 | * see CREDITS file. 25 | */ 26 | package com.aparapi.examples.mdarray; 27 | 28 | import com.aparapi.Kernel; 29 | 30 | class BMatMul2D extends Kernel{ 31 | byte[][] A; 32 | 33 | byte[][] B; 34 | 35 | byte[][] C; 36 | 37 | int N; 38 | 39 | /** 40 | *Constructor for BMatMul2D.
41 | * 42 | * @param A an array of {@link byte} objects. 43 | * @param B an array of {@link byte} objects. 44 | * @param C an array of {@link byte} objects. 45 | * @param N a int. 46 | */ 47 | public BMatMul2D(byte[][] A, byte[][] B, byte[][] C, int N) { 48 | this.A = A; 49 | this.B = B; 50 | this.C = C; 51 | this.N = N; 52 | } 53 | 54 | /** {@inheritDoc} */ 55 | @Override public void run() { 56 | int id = getGlobalId(); 57 | int i = id / N; 58 | int j = id % N; 59 | for (int k = 0; k < N; k++) { 60 | C[i][j] += (byte) (A[i][k] * B[k][j]); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/aparapi/examples/mdarray/BMatMul3D.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 - 2018 Syncleus, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * This product currently only contains code developed by authors 18 | * of specific components, as identified by the source code files. 19 | * 20 | * Since product implements StAX API, it has dependencies to StAX API 21 | * classes. 22 | * 23 | * For additional credits (generally to people who reported problems) 24 | * see CREDITS file. 25 | */ 26 | package com.aparapi.examples.mdarray; 27 | 28 | import com.aparapi.Kernel; 29 | 30 | class BMatMul3D extends Kernel{ 31 | byte[][][] A; 32 | 33 | byte[][][] B; 34 | 35 | byte[][][] C; 36 | 37 | int N; 38 | 39 | /** 40 | *Constructor for BMatMul3D.
41 | * 42 | * @param A an array of {@link byte} objects. 43 | * @param B an array of {@link byte} objects. 44 | * @param C an array of {@link byte} objects. 45 | * @param N a int. 46 | */ 47 | public BMatMul3D(byte[][][] A, byte[][][] B, byte[][][] C, int N) { 48 | this.A = A; 49 | this.B = B; 50 | this.C = C; 51 | this.N = N; 52 | } 53 | 54 | /** {@inheritDoc} */ 55 | @Override public void run() { 56 | int id = getGlobalId(); 57 | int i = id / (N * N); 58 | int j = (id / N) % N; 59 | int k = id % N; 60 | int a0 = A.length; 61 | int a1 = A[0].length; 62 | int a2 = A[0][0].length; 63 | for (int l = 0; l < N; l++) { 64 | C[i][j][k] += (byte) (A[i][j][l] * B[l][j][k]); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/com/aparapi/examples/mdarray/DMatMul1D.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 - 2018 Syncleus, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * This product currently only contains code developed by authors 18 | * of specific components, as identified by the source code files. 19 | * 20 | * Since product implements StAX API, it has dependencies to StAX API 21 | * classes. 22 | * 23 | * For additional credits (generally to people who reported problems) 24 | * see CREDITS file. 25 | */ 26 | package com.aparapi.examples.mdarray; 27 | 28 | import com.aparapi.Kernel; 29 | 30 | class DMatMul1D extends Kernel{ 31 | double[] A; 32 | 33 | double[] B; 34 | 35 | double[] C; 36 | 37 | int N; 38 | 39 | /** 40 | *Constructor for DMatMul1D.
41 | * 42 | * @param A an array of {@link double} objects. 43 | * @param B an array of {@link double} objects. 44 | * @param C an array of {@link double} objects. 45 | * @param N a int. 46 | */ 47 | public DMatMul1D(double[] A, double[] B, double[] C, int N) { 48 | this.A = A; 49 | this.B = B; 50 | this.C = C; 51 | this.N = N; 52 | } 53 | 54 | /** {@inheritDoc} */ 55 | @Override public void run() { 56 | int id = getGlobalId(); 57 | int i = id / N; 58 | int j = id % N; 59 | for (int k = 0; k < N; k++) { 60 | C[i * N + j] += A[i * N + k] * B[k * N + j]; 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/aparapi/examples/mdarray/DMatMul2D.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 - 2018 Syncleus, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * This product currently only contains code developed by authors 18 | * of specific components, as identified by the source code files. 19 | * 20 | * Since product implements StAX API, it has dependencies to StAX API 21 | * classes. 22 | * 23 | * For additional credits (generally to people who reported problems) 24 | * see CREDITS file. 25 | */ 26 | package com.aparapi.examples.mdarray; 27 | 28 | import com.aparapi.Kernel; 29 | 30 | class DMatMul2D extends Kernel{ 31 | double[][] A; 32 | 33 | double[][] B; 34 | 35 | double[][] C; 36 | 37 | int N; 38 | 39 | /** 40 | *Constructor for DMatMul2D.
41 | * 42 | * @param A an array of {@link double} objects. 43 | * @param B an array of {@link double} objects. 44 | * @param C an array of {@link double} objects. 45 | * @param N a int. 46 | */ 47 | public DMatMul2D(double[][] A, double[][] B, double[][] C, int N) { 48 | this.A = A; 49 | this.B = B; 50 | this.C = C; 51 | this.N = N; 52 | } 53 | 54 | /** {@inheritDoc} */ 55 | @Override public void run() { 56 | int id = getGlobalId(); 57 | int i = id / N; 58 | int j = id % N; 59 | for (int k = 0; k < N; k++) { 60 | C[i][j] += A[i][k] * B[k][j]; 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/aparapi/examples/mdarray/DMatMul3D.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 - 2018 Syncleus, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * This product currently only contains code developed by authors 18 | * of specific components, as identified by the source code files. 19 | * 20 | * Since product implements StAX API, it has dependencies to StAX API 21 | * classes. 22 | * 23 | * For additional credits (generally to people who reported problems) 24 | * see CREDITS file. 25 | */ 26 | package com.aparapi.examples.mdarray; 27 | 28 | import com.aparapi.Kernel; 29 | 30 | class DMatMul3D extends Kernel{ 31 | double[][][] A; 32 | 33 | double[][][] B; 34 | 35 | double[][][] C; 36 | 37 | int N; 38 | 39 | /** 40 | *Constructor for DMatMul3D.
41 | * 42 | * @param A an array of {@link double} objects. 43 | * @param B an array of {@link double} objects. 44 | * @param C an array of {@link double} objects. 45 | * @param N a int. 46 | */ 47 | public DMatMul3D(double[][][] A, double[][][] B, double[][][] C, int N) { 48 | this.A = A; 49 | this.B = B; 50 | this.C = C; 51 | this.N = N; 52 | } 53 | 54 | /** {@inheritDoc} */ 55 | @Override public void run() { 56 | int id = getGlobalId(); 57 | int i = id / (N * N); 58 | int j = (id / N) % N; 59 | int k = id % N; 60 | for (int l = 0; l < N; l++) { 61 | C[i][j][k] += A[i][j][l] * B[l][j][k]; 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/com/aparapi/examples/mdarray/FMatMul1D.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 - 2018 Syncleus, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * This product currently only contains code developed by authors 18 | * of specific components, as identified by the source code files. 19 | * 20 | * Since product implements StAX API, it has dependencies to StAX API 21 | * classes. 22 | * 23 | * For additional credits (generally to people who reported problems) 24 | * see CREDITS file. 25 | */ 26 | package com.aparapi.examples.mdarray; 27 | 28 | import com.aparapi.Kernel; 29 | 30 | class FMatMul1D extends Kernel{ 31 | float[] A; 32 | 33 | float[] B; 34 | 35 | float[] C; 36 | 37 | int N; 38 | 39 | /** 40 | *Constructor for FMatMul1D.
41 | * 42 | * @param A an array of {@link float} objects. 43 | * @param B an array of {@link float} objects. 44 | * @param C an array of {@link float} objects. 45 | * @param N a int. 46 | */ 47 | public FMatMul1D(float[] A, float[] B, float[] C, int N) { 48 | this.A = A; 49 | this.B = B; 50 | this.C = C; 51 | this.N = N; 52 | } 53 | 54 | /** {@inheritDoc} */ 55 | @Override public void run() { 56 | int id = getGlobalId(); 57 | int i = id / N; 58 | int j = id % N; 59 | for (int k = 0; k < N; k++) { 60 | C[i * N + j] += A[i * N + k] * B[k * N + j]; 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/aparapi/examples/mdarray/FMatMul2D.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 - 2018 Syncleus, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * This product currently only contains code developed by authors 18 | * of specific components, as identified by the source code files. 19 | * 20 | * Since product implements StAX API, it has dependencies to StAX API 21 | * classes. 22 | * 23 | * For additional credits (generally to people who reported problems) 24 | * see CREDITS file. 25 | */ 26 | package com.aparapi.examples.mdarray; 27 | 28 | import com.aparapi.Kernel; 29 | 30 | class FMatMul2D extends Kernel{ 31 | float[][] A; 32 | 33 | float[][] B; 34 | 35 | float[][] C; 36 | 37 | int N; 38 | 39 | /** 40 | *Constructor for FMatMul2D.
41 | * 42 | * @param A an array of {@link float} objects. 43 | * @param B an array of {@link float} objects. 44 | * @param C an array of {@link float} objects. 45 | * @param N a int. 46 | */ 47 | public FMatMul2D(float[][] A, float[][] B, float[][] C, int N) { 48 | this.A = A; 49 | this.B = B; 50 | this.C = C; 51 | this.N = N; 52 | } 53 | 54 | /** {@inheritDoc} */ 55 | @Override public void run() { 56 | int id = getGlobalId(); 57 | int i = id / N; 58 | int j = id % N; 59 | for (int k = 0; k < N; k++) { 60 | C[i][j] += A[i][k] * B[k][j]; 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/aparapi/examples/mdarray/FMatMul3D.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 - 2018 Syncleus, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * This product currently only contains code developed by authors 18 | * of specific components, as identified by the source code files. 19 | * 20 | * Since product implements StAX API, it has dependencies to StAX API 21 | * classes. 22 | * 23 | * For additional credits (generally to people who reported problems) 24 | * see CREDITS file. 25 | */ 26 | package com.aparapi.examples.mdarray; 27 | 28 | import com.aparapi.Kernel; 29 | 30 | class FMatMul3D extends Kernel{ 31 | float[][][] A; 32 | 33 | float[][][] B; 34 | 35 | float[][][] C; 36 | 37 | int N; 38 | 39 | /** 40 | *Constructor for FMatMul3D.
41 | * 42 | * @param A an array of {@link float} objects. 43 | * @param B an array of {@link float} objects. 44 | * @param C an array of {@link float} objects. 45 | * @param N a int. 46 | */ 47 | public FMatMul3D(float[][][] A, float[][][] B, float[][][] C, int N) { 48 | this.A = A; 49 | this.B = B; 50 | this.C = C; 51 | this.N = N; 52 | } 53 | 54 | /** {@inheritDoc} */ 55 | @Override public void run() { 56 | int id = getGlobalId(); 57 | int i = id / (N * N); 58 | int j = (id / N) % N; 59 | int k = id % N; 60 | for (int l = 0; l < N; l++) { 61 | C[i][j][k] += A[i][j][l] * B[l][j][k]; 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/com/aparapi/examples/mdarray/IMatMul1D.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 - 2018 Syncleus, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * This product currently only contains code developed by authors 18 | * of specific components, as identified by the source code files. 19 | * 20 | * Since product implements StAX API, it has dependencies to StAX API 21 | * classes. 22 | * 23 | * For additional credits (generally to people who reported problems) 24 | * see CREDITS file. 25 | */ 26 | package com.aparapi.examples.mdarray; 27 | 28 | import com.aparapi.Kernel; 29 | 30 | class IMatMul1D extends Kernel{ 31 | int[] A; 32 | 33 | int[] B; 34 | 35 | int[] C; 36 | 37 | int N; 38 | 39 | /** 40 | *Constructor for IMatMul1D.
41 | * 42 | * @param A an array of {@link int} objects. 43 | * @param B an array of {@link int} objects. 44 | * @param C an array of {@link int} objects. 45 | * @param N a int. 46 | */ 47 | public IMatMul1D(int[] A, int[] B, int[] C, int N) { 48 | this.A = A; 49 | this.B = B; 50 | this.C = C; 51 | this.N = N; 52 | } 53 | 54 | /** {@inheritDoc} */ 55 | @Override public void run() { 56 | int id = getGlobalId(); 57 | int i = id / N; 58 | int j = id % N; 59 | for (int k = 0; k < N; k++) { 60 | C[i * N + j] += A[i * N + k] * B[k * N + j]; 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/aparapi/examples/mdarray/IMatMul2D.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 - 2018 Syncleus, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * This product currently only contains code developed by authors 18 | * of specific components, as identified by the source code files. 19 | * 20 | * Since product implements StAX API, it has dependencies to StAX API 21 | * classes. 22 | * 23 | * For additional credits (generally to people who reported problems) 24 | * see CREDITS file. 25 | */ 26 | package com.aparapi.examples.mdarray; 27 | 28 | import com.aparapi.Kernel; 29 | 30 | class IMatMul2D extends Kernel{ 31 | int[][] A; 32 | 33 | int[][] B; 34 | 35 | int[][] C; 36 | 37 | int N; 38 | 39 | /** 40 | *Constructor for IMatMul2D.
41 | * 42 | * @param A an array of {@link int} objects. 43 | * @param B an array of {@link int} objects. 44 | * @param C an array of {@link int} objects. 45 | * @param N a int. 46 | */ 47 | public IMatMul2D(int[][] A, int[][] B, int[][] C, int N) { 48 | this.A = A; 49 | this.B = B; 50 | this.C = C; 51 | this.N = N; 52 | } 53 | 54 | /** {@inheritDoc} */ 55 | @Override public void run() { 56 | int id = getGlobalId(); 57 | int i = id / N; 58 | int j = id % N; 59 | for (int k = 0; k < N; k++) { 60 | C[i][j] += A[i][k] * B[k][j]; 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/aparapi/examples/mdarray/IMatMul3D.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 - 2018 Syncleus, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * This product currently only contains code developed by authors 18 | * of specific components, as identified by the source code files. 19 | * 20 | * Since product implements StAX API, it has dependencies to StAX API 21 | * classes. 22 | * 23 | * For additional credits (generally to people who reported problems) 24 | * see CREDITS file. 25 | */ 26 | package com.aparapi.examples.mdarray; 27 | 28 | import com.aparapi.Kernel; 29 | 30 | class IMatMul3D extends Kernel{ 31 | int[][][] A; 32 | 33 | int[][][] B; 34 | 35 | int[][][] C; 36 | 37 | int N; 38 | 39 | /** 40 | *Constructor for IMatMul3D.
41 | * 42 | * @param A an array of {@link int} objects. 43 | * @param B an array of {@link int} objects. 44 | * @param C an array of {@link int} objects. 45 | * @param N a int. 46 | */ 47 | public IMatMul3D(int[][][] A, int[][][] B, int[][][] C, int N) { 48 | this.A = A; 49 | this.B = B; 50 | this.C = C; 51 | this.N = N; 52 | } 53 | 54 | /** {@inheritDoc} */ 55 | @Override public void run() { 56 | int id = getGlobalId(); 57 | int i = id / (N * N); 58 | int j = (id / N) % N; 59 | int k = id % N; 60 | for (int l = 0; l < N; l++) { 61 | C[i][j][k] += A[i][j][l] * B[l][j][k]; 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/com/aparapi/examples/mdarray/LMatMul1D.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 - 2018 Syncleus, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * This product currently only contains code developed by authors 18 | * of specific components, as identified by the source code files. 19 | * 20 | * Since product implements StAX API, it has dependencies to StAX API 21 | * classes. 22 | * 23 | * For additional credits (generally to people who reported problems) 24 | * see CREDITS file. 25 | */ 26 | package com.aparapi.examples.mdarray; 27 | 28 | import com.aparapi.Kernel; 29 | 30 | class LMatMul1D extends Kernel{ 31 | long[] A; 32 | 33 | long[] B; 34 | 35 | long[] C; 36 | 37 | int N; 38 | 39 | /** 40 | *Constructor for LMatMul1D.
41 | * 42 | * @param A an array of {@link long} objects. 43 | * @param B an array of {@link long} objects. 44 | * @param C an array of {@link long} objects. 45 | * @param N a int. 46 | */ 47 | public LMatMul1D(long[] A, long[] B, long[] C, int N) { 48 | this.A = A; 49 | this.B = B; 50 | this.C = C; 51 | this.N = N; 52 | } 53 | 54 | /** {@inheritDoc} */ 55 | @Override public void run() { 56 | int id = getGlobalId(); 57 | int i = id / N; 58 | int j = id % N; 59 | for (int k = 0; k < N; k++) { 60 | C[i * N + j] += A[i * N + k] * B[k * N + j]; 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/aparapi/examples/mdarray/LMatMul2D.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 - 2018 Syncleus, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * This product currently only contains code developed by authors 18 | * of specific components, as identified by the source code files. 19 | * 20 | * Since product implements StAX API, it has dependencies to StAX API 21 | * classes. 22 | * 23 | * For additional credits (generally to people who reported problems) 24 | * see CREDITS file. 25 | */ 26 | package com.aparapi.examples.mdarray; 27 | 28 | import com.aparapi.Kernel; 29 | 30 | class LMatMul2D extends Kernel{ 31 | long[][] A; 32 | 33 | long[][] B; 34 | 35 | long[][] C; 36 | 37 | int N; 38 | 39 | /** 40 | *Constructor for LMatMul2D.
41 | * 42 | * @param A an array of {@link long} objects. 43 | * @param B an array of {@link long} objects. 44 | * @param C an array of {@link long} objects. 45 | * @param N a int. 46 | */ 47 | public LMatMul2D(long[][] A, long[][] B, long[][] C, int N) { 48 | this.A = A; 49 | this.B = B; 50 | this.C = C; 51 | this.N = N; 52 | } 53 | 54 | /** {@inheritDoc} */ 55 | @Override public void run() { 56 | int id = getGlobalId(); 57 | int i = id / N; 58 | int j = id % N; 59 | for (int k = 0; k < N; k++) { 60 | C[i][j] += A[i][k] * B[k][j]; 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/aparapi/examples/mdarray/LMatMul3D.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 - 2018 Syncleus, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * This product currently only contains code developed by authors 18 | * of specific components, as identified by the source code files. 19 | * 20 | * Since product implements StAX API, it has dependencies to StAX API 21 | * classes. 22 | * 23 | * For additional credits (generally to people who reported problems) 24 | * see CREDITS file. 25 | */ 26 | package com.aparapi.examples.mdarray; 27 | 28 | import com.aparapi.Kernel; 29 | 30 | class LMatMul3D extends Kernel{ 31 | long[][][] A; 32 | 33 | long[][][] B; 34 | 35 | long[][][] C; 36 | 37 | int N; 38 | 39 | /** 40 | *Constructor for LMatMul3D.
41 | * 42 | * @param A an array of {@link long} objects. 43 | * @param B an array of {@link long} objects. 44 | * @param C an array of {@link long} objects. 45 | * @param N a int. 46 | */ 47 | public LMatMul3D(long[][][] A, long[][][] B, long[][][] C, int N) { 48 | this.A = A; 49 | this.B = B; 50 | this.C = C; 51 | this.N = N; 52 | } 53 | 54 | /** {@inheritDoc} */ 55 | @Override public void run() { 56 | int id = getGlobalId(); 57 | int i = id / (N * N); 58 | int j = (id / N) % N; 59 | int k = id % N; 60 | for (int l = 0; l < N; l++) { 61 | C[i][j][k] += A[i][j][l] * B[l][j][k]; 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/com/aparapi/examples/mdarray/SMatMul1D.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 - 2018 Syncleus, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * This product currently only contains code developed by authors 18 | * of specific components, as identified by the source code files. 19 | * 20 | * Since product implements StAX API, it has dependencies to StAX API 21 | * classes. 22 | * 23 | * For additional credits (generally to people who reported problems) 24 | * see CREDITS file. 25 | */ 26 | package com.aparapi.examples.mdarray; 27 | 28 | import com.aparapi.Kernel; 29 | 30 | class SMatMul1D extends Kernel{ 31 | short[] A; 32 | 33 | short[] B; 34 | 35 | short[] C; 36 | 37 | int N; 38 | 39 | /** 40 | *Constructor for SMatMul1D.
41 | * 42 | * @param A an array of {@link short} objects. 43 | * @param B an array of {@link short} objects. 44 | * @param C an array of {@link short} objects. 45 | * @param N a int. 46 | */ 47 | public SMatMul1D(short[] A, short[] B, short[] C, int N) { 48 | this.A = A; 49 | this.B = B; 50 | this.C = C; 51 | this.N = N; 52 | } 53 | 54 | /** {@inheritDoc} */ 55 | @Override public void run() { 56 | int id = getGlobalId(); 57 | int i = id / N; 58 | int j = id % N; 59 | for (int k = 0; k < N; k++) { 60 | C[i * N + j] += (short) (A[i * N + k] * B[k * N + j]); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/aparapi/examples/mdarray/SMatMul2D.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 - 2018 Syncleus, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * This product currently only contains code developed by authors 18 | * of specific components, as identified by the source code files. 19 | * 20 | * Since product implements StAX API, it has dependencies to StAX API 21 | * classes. 22 | * 23 | * For additional credits (generally to people who reported problems) 24 | * see CREDITS file. 25 | */ 26 | package com.aparapi.examples.mdarray; 27 | 28 | import com.aparapi.Kernel; 29 | 30 | class SMatMul2D extends Kernel{ 31 | short[][] A; 32 | 33 | short[][] B; 34 | 35 | short[][] C; 36 | 37 | int N; 38 | 39 | /** 40 | *Constructor for SMatMul2D.
41 | * 42 | * @param A an array of {@link short} objects. 43 | * @param B an array of {@link short} objects. 44 | * @param C an array of {@link short} objects. 45 | * @param N a int. 46 | */ 47 | public SMatMul2D(short[][] A, short[][] B, short[][] C, int N) { 48 | this.A = A; 49 | this.B = B; 50 | this.C = C; 51 | this.N = N; 52 | } 53 | 54 | /** {@inheritDoc} */ 55 | @Override public void run() { 56 | int id = getGlobalId(); 57 | int i = id / N; 58 | int j = id % N; 59 | for (int k = 0; k < N; k++) { 60 | C[i][j] += (short) (A[i][k] * B[k][j]); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/aparapi/examples/mdarray/SMatMul3D.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 - 2018 Syncleus, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * This product currently only contains code developed by authors 18 | * of specific components, as identified by the source code files. 19 | * 20 | * Since product implements StAX API, it has dependencies to StAX API 21 | * classes. 22 | * 23 | * For additional credits (generally to people who reported problems) 24 | * see CREDITS file. 25 | */ 26 | package com.aparapi.examples.mdarray; 27 | 28 | import com.aparapi.Kernel; 29 | 30 | class SMatMul3D extends Kernel{ 31 | short[][][] A; 32 | 33 | short[][][] B; 34 | 35 | short[][][] C; 36 | 37 | int N; 38 | 39 | /** 40 | *Constructor for SMatMul3D.
41 | * 42 | * @param A an array of {@link short} objects. 43 | * @param B an array of {@link short} objects. 44 | * @param C an array of {@link short} objects. 45 | * @param N a int. 46 | */ 47 | public SMatMul3D(short[][][] A, short[][][] B, short[][][] C, int N) { 48 | this.A = A; 49 | this.B = B; 50 | this.C = C; 51 | this.N = N; 52 | } 53 | 54 | /** {@inheritDoc} */ 55 | @Override public void run() { 56 | int id = getGlobalId(); 57 | int i = id / (N * N); 58 | int j = (id / N) % N; 59 | int k = id % N; 60 | for (int l = 0; l < N; l++) { 61 | C[i][j][k] += (short) (A[i][j][l] * B[l][j][k]); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/com/aparapi/examples/mdarray/ZMatMul1D.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 - 2018 Syncleus, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * This product currently only contains code developed by authors 18 | * of specific components, as identified by the source code files. 19 | * 20 | * Since product implements StAX API, it has dependencies to StAX API 21 | * classes. 22 | * 23 | * For additional credits (generally to people who reported problems) 24 | * see CREDITS file. 25 | */ 26 | package com.aparapi.examples.mdarray; 27 | 28 | import com.aparapi.Kernel; 29 | 30 | class ZMatMul1D extends Kernel{ 31 | boolean[] A; 32 | 33 | boolean[] B; 34 | 35 | boolean[] C; 36 | 37 | int N; 38 | 39 | /** 40 | *Constructor for ZMatMul1D.
41 | * 42 | * @param A an array of {@link boolean} objects. 43 | * @param B an array of {@link boolean} objects. 44 | * @param C an array of {@link boolean} objects. 45 | * @param N a int. 46 | */ 47 | public ZMatMul1D(boolean[] A, boolean[] B, boolean[] C, int N) { 48 | this.A = A; 49 | this.B = B; 50 | this.C = C; 51 | this.N = N; 52 | } 53 | 54 | /** {@inheritDoc} */ 55 | @Override public void run() { 56 | int id = getGlobalId(); 57 | int i = id / N; 58 | int j = id % N; 59 | for (int k = 0; k < N; k++) { 60 | C[i * N + j] ^= A[i * N + k] & B[k * N + j]; 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/aparapi/examples/mdarray/ZMatMul2D.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 - 2018 Syncleus, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * This product currently only contains code developed by authors 18 | * of specific components, as identified by the source code files. 19 | * 20 | * Since product implements StAX API, it has dependencies to StAX API 21 | * classes. 22 | * 23 | * For additional credits (generally to people who reported problems) 24 | * see CREDITS file. 25 | */ 26 | package com.aparapi.examples.mdarray; 27 | 28 | import com.aparapi.Kernel; 29 | 30 | class ZMatMul2D extends Kernel{ 31 | boolean[][] A; 32 | 33 | boolean[][] B; 34 | 35 | boolean[][] C; 36 | 37 | int N; 38 | 39 | /** 40 | *Constructor for ZMatMul2D.
41 | * 42 | * @param A an array of {@link boolean} objects. 43 | * @param B an array of {@link boolean} objects. 44 | * @param C an array of {@link boolean} objects. 45 | * @param N a int. 46 | */ 47 | public ZMatMul2D(boolean[][] A, boolean[][] B, boolean[][] C, int N) { 48 | this.A = A; 49 | this.B = B; 50 | this.C = C; 51 | this.N = N; 52 | } 53 | 54 | /** {@inheritDoc} */ 55 | @Override public void run() { 56 | int id = getGlobalId(); 57 | int i = id / N; 58 | int j = id % N; 59 | for (int k = 0; k < N; k++) { 60 | C[i][j] ^= A[i][k] & B[k][j]; 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/aparapi/examples/mdarray/ZMatMul3D.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 - 2018 Syncleus, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * This product currently only contains code developed by authors 18 | * of specific components, as identified by the source code files. 19 | * 20 | * Since product implements StAX API, it has dependencies to StAX API 21 | * classes. 22 | * 23 | * For additional credits (generally to people who reported problems) 24 | * see CREDITS file. 25 | */ 26 | package com.aparapi.examples.mdarray; 27 | 28 | import com.aparapi.Kernel; 29 | 30 | class ZMatMul3D extends Kernel{ 31 | boolean[][][] A; 32 | 33 | boolean[][][] B; 34 | 35 | boolean[][][] C; 36 | 37 | int N; 38 | 39 | /** 40 | *Constructor for ZMatMul3D.
41 | * 42 | * @param A an array of {@link boolean} objects. 43 | * @param B an array of {@link boolean} objects. 44 | * @param C an array of {@link boolean} objects. 45 | * @param N a int. 46 | */ 47 | public ZMatMul3D(boolean[][][] A, boolean[][][] B, boolean[][][] C, int N) { 48 | this.A = A; 49 | this.B = B; 50 | this.C = C; 51 | this.N = N; 52 | } 53 | 54 | /** {@inheritDoc} */ 55 | @Override public void run() { 56 | int id = getGlobalId(); 57 | int i = id / (N * N); 58 | int j = (id / N) % N; 59 | int k = id % N; 60 | for (int l = 0; l < N; l++) { 61 | C[i][j][k] ^= A[i][j][l] & B[l][j][k]; 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/com/aparapi/examples/median/MedianDemo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 - 2018 Syncleus, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * This product currently only contains code developed by authors 18 | * of specific components, as identified by the source code files. 19 | * 20 | * Since product implements StAX API, it has dependencies to StAX API 21 | * classes. 22 | * 23 | * For additional credits (generally to people who reported problems) 24 | * see CREDITS file. 25 | */ 26 | package com.aparapi.examples.median; 27 | 28 | import com.aparapi.internal.kernel.*; 29 | 30 | import javax.imageio.*; 31 | import javax.swing.*; 32 | import java.awt.*; 33 | import java.awt.image.*; 34 | import java.io.*; 35 | import java.net.URISyntaxException; 36 | 37 | /** 38 | * Demonstrate use of __private namespaces and @NoCL annotations. 39 | * 40 | * @author freemo 41 | * @version $Id: $Id 42 | */ 43 | public class MedianDemo { 44 | /** ConstanttestImage
*/
45 | public static BufferedImage testImage;
46 |
47 | static {
48 | try {
49 | File imageFile = new File(MedianDemo.class.getResource("/testcard.jpg").toURI()).getCanonicalFile();
50 | if (imageFile.exists()) {
51 | testImage = ImageIO.read(imageFile);
52 | }
53 | } catch (IOException | URISyntaxException e) {
54 | throw new IllegalStateException("Could not open image", e);
55 | }
56 | }
57 |
58 | /**
59 | * main.
60 | * 61 | * @param ignored an array of {@link java.lang.String} objects. 62 | */ 63 | public static void main(String[] ignored) { 64 | final int size = 5; 65 | System.setProperty("com.aparapi.dumpProfilesOnExit", "true"); 66 | boolean verbose = false; 67 | if (verbose) 68 | { 69 | System.setProperty("com.aparapi.enableVerboseJNI", "true"); 70 | System.setProperty("com.aparapi.dumpFlags", "true"); 71 | System.setProperty("com.aparapi.enableShowGeneratedOpenCL", "true"); 72 | System.setProperty("com.aparapi.enableVerboseJNIOpenCLResourceTracking", "true"); 73 | System.setProperty("com.aparapi.enableExecutionModeReporting", "true"); 74 | } 75 | 76 | System.out.println(KernelManager.instance().bestDevice()); 77 | 78 | int[] argbs = testImage.getRGB(0, 0, testImage.getWidth(), testImage.getHeight(), null, 0, testImage.getWidth()); 79 | MedianKernel7x7 kernel = createMedianKernel(argbs); 80 | 81 | kernel.processImages(new MedianSettings(size)); 82 | BufferedImage out = new BufferedImage(testImage.getWidth(), testImage.getHeight(), BufferedImage.TYPE_INT_RGB); 83 | out.setRGB(0, 0, testImage.getWidth(), testImage.getHeight(), kernel._destPixels, 0, testImage.getWidth()); 84 | ImageIcon icon1 = new ImageIcon(testImage); 85 | JLabel label1 = new JLabel(icon1); 86 | ImageIcon icon2 = new ImageIcon(out); 87 | JLabel label2 = new JLabel(icon2); 88 | JFrame frame = new JFrame("Test Median"); 89 | frame.setLayout(new FlowLayout()); 90 | frame.getContentPane().add(label1); 91 | frame.getContentPane().add(label2); 92 | frame.pack(); 93 | frame.setLocationRelativeTo(null); 94 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 95 | frame.setVisible(true); 96 | 97 | StringBuilder builder = new StringBuilder(); 98 | KernelManager.instance().reportDeviceUsage(builder, true); 99 | System.out.println(builder); 100 | 101 | int reps = 50; 102 | final boolean newKernel = false; 103 | for (int rep = 0; rep < reps; ++rep) { 104 | if (newKernel) { 105 | kernel.dispose(); 106 | kernel = createMedianKernel(argbs); 107 | } 108 | long start = System.nanoTime(); 109 | kernel.processImages(new MedianSettings(size)); 110 | long elapsed = System.nanoTime() - start; 111 | System.out.println("elapsed = " + elapsed / 1000000f + "ms"); 112 | } 113 | 114 | builder = new StringBuilder(); 115 | KernelManager.instance().reportDeviceUsage(builder, true); 116 | System.out.println(builder); 117 | } 118 | 119 | private static MedianKernel7x7 createMedianKernel(int[] argbs) { 120 | MedianKernel7x7 kernel = new MedianKernel7x7(); 121 | kernel._imageTypeOrdinal = MedianKernel7x7.RGB; 122 | kernel._sourceWidth = testImage.getWidth(); 123 | kernel._sourceHeight = testImage.getHeight(); 124 | kernel._sourcePixels = argbs; 125 | kernel._destPixels = new int[argbs.length]; 126 | return kernel; 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /src/main/java/com/aparapi/examples/median/MedianSettings.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 - 2018 Syncleus, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * This product currently only contains code developed by authors 18 | * of specific components, as identified by the source code files. 19 | * 20 | * Since product implements StAX API, it has dependencies to StAX API 21 | * classes. 22 | * 23 | * For additional credits (generally to people who reported problems) 24 | * see CREDITS file. 25 | */ 26 | package com.aparapi.examples.median; 27 | 28 | /** 29 | *MedianSettings class.
30 | * 31 | * @author freemo 32 | * @version $Id: $Id 33 | */ 34 | public class MedianSettings { 35 | public final int windowWidth; 36 | public final int windowHeight; 37 | 38 | /** 39 | *Constructor for MedianSettings.
40 | * 41 | * @param windowSize a int. 42 | */ 43 | public MedianSettings(int windowSize) { 44 | this(windowSize, windowSize); 45 | } 46 | 47 | /** 48 | *Constructor for MedianSettings.
49 | * 50 | * @param windowWidth a int. 51 | * @param windowHeight a int. 52 | */ 53 | public MedianSettings(int windowWidth, int windowHeight) { 54 | this.windowWidth = windowWidth; 55 | this.windowHeight = windowHeight; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/aparapi/examples/oopnbody/Body.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 - 2018 Syncleus, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * This product currently only contains code developed by authors 18 | * of specific components, as identified by the source code files. 19 | * 20 | * Since product implements StAX API, it has dependencies to StAX API 21 | * classes. 22 | * 23 | * For additional credits (generally to people who reported problems) 24 | * see CREDITS file. 25 | */ 26 | package com.aparapi.examples.oopnbody; 27 | 28 | 29 | /** 30 | *Body class.
31 | * 32 | * @author freemo 33 | * @version $Id: $Id 34 | */ 35 | public final class Body{ 36 | /** ConstantallBodies
*/
37 | public static Body[] allBodies;
38 |
39 | final private boolean isHeavy;
40 |
41 | /**
42 | * Constructor for Body.
43 | * 44 | * @param x a float. 45 | * @param y a float. 46 | * @param z a float. 47 | * @param _m a float. 48 | * @param isHeavy a boolean. 49 | */ 50 | public Body(float x, float y, float z, float _m, boolean isHeavy) { 51 | this.x = x; 52 | this.y = y; 53 | this.z = z; 54 | m = _m; 55 | this.isHeavy = isHeavy; 56 | } 57 | 58 | float x, y, z, m, vx, vy, vz; 59 | 60 | /** 61 | *isHeavy.
62 | * 63 | * @return a boolean. 64 | */ 65 | public boolean isHeavy() { 66 | return isHeavy; 67 | } 68 | 69 | /** 70 | *Getter for the field x
.
Getter for the field y
.
Getter for the field z
.
getRadius.
98 | * 99 | * @return a float. 100 | */ 101 | public float getRadius() { 102 | return (float) Math.sqrt(x * x + y * y + z* z); 103 | } 104 | 105 | /** 106 | *getTheta.
107 | * 108 | * @return a float. 109 | */ 110 | public float getTheta() { 111 | return (float) Math.acos(z / getRadius()); 112 | } 113 | 114 | /** 115 | *getPhi.
116 | * 117 | * @return a float. 118 | */ 119 | public float getPhi() { 120 | return (float) Math.atan(y / x); 121 | } 122 | 123 | /** 124 | *Getter for the field vx
.
Getter for the field vy
.
Getter for the field vz
.
Getter for the field m
.
Setter for the field m
.
Setter for the field x
.
Setter for the field y
.
Setter for the field z
.
setRadius.
197 | * 198 | * @param radius a float. 199 | */ 200 | public void setRadius(float radius) { 201 | final float theta = getTheta(); 202 | final float phi = getPhi(); 203 | x = (float) (radius * Math.cos(theta) * Math.sin(phi)); 204 | y = (float) (radius * Math.sin(theta) * Math.sin(phi)); 205 | z = (float) (radius * Math.cos(phi)); 206 | } 207 | 208 | /** 209 | *setTheta.
210 | * 211 | * @param theta a float. 212 | */ 213 | public void setTheta(float theta) { 214 | final float radius = getRadius(); 215 | final float phi = getPhi(); 216 | x = (float) (radius * Math.cos(theta) * Math.sin(phi)); 217 | y = (float) (radius * Math.sin(theta) * Math.sin(phi)); 218 | z = (float) (radius * Math.cos(phi)); 219 | } 220 | 221 | /** 222 | *setPhi.
223 | * 224 | * @param phi a float. 225 | */ 226 | public void setPhi(float phi) { 227 | final float radius = getRadius(); 228 | final float theta = getTheta(); 229 | x = (float) (radius * Math.cos(theta) * Math.sin(phi)); 230 | y = (float) (radius * Math.sin(theta) * Math.sin(phi)); 231 | z = (float) (radius * Math.cos(phi)); 232 | } 233 | 234 | /** 235 | *Setter for the field vx
.
Setter for the field vy
.
Setter for the field vz
.
RANGE=20000
*/
39 | public static final int RANGE = 20000;
40 | private static final int REPETITIONS = 1 * 1000 * 1000;
41 |
42 | public final long[] data = new long[RANGE];
43 |
44 | /** {@inheritDoc} */
45 | @Override
46 | public void run() {
47 | int id = getGlobalId();
48 | if (id == 0) {
49 | report();
50 | }
51 | for (int rep = 0; rep < REPETITIONS; ++rep) {
52 | data[id] += (int) sqrt(1);
53 | }
54 | }
55 |
56 | /**
57 | * report.
58 | */ 59 | @NoCL 60 | public void report() { 61 | int passId = getPassId(); 62 | System.out.println("Java execution: passId = " + passId); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/com/aparapi/examples/progress/MultiPassKernelSwingWorkerDemo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 - 2018 Syncleus, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * This product currently only contains code developed by authors 18 | * of specific components, as identified by the source code files. 19 | * 20 | * Since product implements StAX API, it has dependencies to StAX API 21 | * classes. 22 | * 23 | * For additional credits (generally to people who reported problems) 24 | * see CREDITS file. 25 | */ 26 | package com.aparapi.examples.progress; 27 | 28 | import com.aparapi.*; 29 | import com.aparapi.internal.kernel.*; 30 | import com.aparapi.util.swing.MultiPassKernelSwingWorker; 31 | 32 | import javax.swing.*; 33 | import javax.swing.plaf.nimbus.NimbusLookAndFeel; 34 | import java.awt.*; 35 | import java.awt.event.ActionEvent; 36 | import java.awt.event.ActionListener; 37 | 38 | /** 39 | * Demonstrates progress tracking and cancellation for multi-pass kernels, via {@link com.aparapi.util.swing.MultiPassKernelSwingWorker}. 40 | * 41 | * @author freemo 42 | * @version $Id: $Id 43 | */ 44 | public class MultiPassKernelSwingWorkerDemo { 45 | 46 | private static final int PASS_COUNT = 200; 47 | private static JButton startButton; 48 | private static JButton cancelButton; 49 | private static JProgressBar progress; 50 | private static JLabel status = new JLabel("Press Start", JLabel.CENTER); 51 | private static LongRunningKernel kernel; 52 | private static MultiPassKernelSwingWorker worker; 53 | 54 | private static final boolean TEST_JTP = false; 55 | 56 | /** 57 | *main.
58 | * 59 | * @param ignored an array of {@link java.lang.String} objects. 60 | * @throws java.lang.Exception if any. 61 | */ 62 | public static void main(String[] ignored) throws Exception { 63 | if (TEST_JTP) { 64 | KernelManager.setKernelManager(KernelManagers.JTP_ONLY); 65 | } 66 | kernel = new LongRunningKernel(); 67 | 68 | UIManager.setLookAndFeel(NimbusLookAndFeel.class.getName()); 69 | JPanel rootPanel = new JPanel(); 70 | rootPanel.setLayout(new BorderLayout()); 71 | JPanel buttons = new JPanel(new FlowLayout(FlowLayout.CENTER)); 72 | startButton = new JButton("Start"); 73 | cancelButton = new JButton("Cancel"); 74 | startButton.setEnabled(true); 75 | startButton.addActionListener(new ActionListener() { 76 | @Override 77 | public void actionPerformed(ActionEvent e) { 78 | start(); 79 | } 80 | }); 81 | cancelButton.setEnabled(false); 82 | cancelButton.addActionListener(new ActionListener() { 83 | @Override 84 | public void actionPerformed(ActionEvent e) { 85 | cancel(); 86 | } 87 | }); 88 | buttons.add(startButton); 89 | buttons.add(cancelButton); 90 | rootPanel.add(buttons, BorderLayout.SOUTH); 91 | 92 | progress = new JProgressBar(new DefaultBoundedRangeModel(0, 0, 0, PASS_COUNT)); 93 | 94 | rootPanel.add(status, BorderLayout.CENTER); 95 | rootPanel.add(progress, BorderLayout.NORTH); 96 | 97 | JFrame frame = new JFrame("MultiPassKernelSwingWorker Demo"); 98 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 99 | frame.getContentPane().add(rootPanel); 100 | frame.pack(); 101 | frame.setLocationRelativeTo(null); 102 | frame.setVisible(true); 103 | } 104 | 105 | private static MultiPassKernelSwingWorker createWorker() { 106 | return new MultiPassKernelSwingWorker(kernel) { 107 | @Override 108 | protected void executeKernel(Kernel kernel) { 109 | int range; 110 | if (TEST_JTP) { 111 | range = LongRunningKernel.RANGE / 1000; 112 | } else { 113 | range = LongRunningKernel.RANGE; 114 | } 115 | kernel.execute(range, PASS_COUNT); 116 | } 117 | 118 | @Override 119 | protected void updatePassId(int passId) { 120 | updateProgress(passId); 121 | } 122 | 123 | @Override 124 | protected void done() { 125 | updateProgress(KernelRunner.PASS_ID_COMPLETED_EXECUTION); 126 | startButton.setEnabled(true); 127 | cancelButton.setEnabled(false); 128 | } 129 | }; 130 | } 131 | 132 | private static void start() { 133 | if (!SwingUtilities.isEventDispatchThread()) { 134 | throw new IllegalStateException(); 135 | } 136 | 137 | startButton.setEnabled(false); 138 | cancelButton.setEnabled(true); 139 | worker = createWorker(); 140 | worker.execute(); 141 | System.out.println("Started execution of MultiPassKernelSwingWorker"); 142 | } 143 | 144 | private static void updateProgress(int passId) { 145 | int progressValue; 146 | if (passId >= 0) { 147 | progressValue = passId; 148 | status.setText("passId = " + passId); 149 | } else if (passId == KernelRunner.PASS_ID_PREPARING_EXECUTION) { 150 | progressValue = 0; 151 | status.setText("Preparing"); 152 | } else if (passId == KernelRunner.PASS_ID_COMPLETED_EXECUTION) { 153 | progressValue = PASS_COUNT; 154 | status.setText("Complete"); 155 | } else { 156 | progressValue = 0; 157 | status.setText("Illegal status " + passId); 158 | } 159 | progress.getModel().setValue(progressValue); 160 | } 161 | 162 | private static void cancel() { 163 | worker.cancelExecution(); 164 | } 165 | } 166 | 167 | -------------------------------------------------------------------------------- /src/main/java/com/aparapi/examples/squares/Main.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 - 2018 Syncleus, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * This product currently only contains code developed by authors 18 | * of specific components, as identified by the source code files. 19 | * 20 | * Since product implements StAX API, it has dependencies to StAX API 21 | * classes. 22 | * 23 | * For additional credits (generally to people who reported problems) 24 | * see CREDITS file. 25 | */ 26 | /* 27 | Copyright (c) 2010-2011, Advanced Micro Devices, Inc. 28 | All rights reserved. 29 | 30 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the 31 | following conditions are met: 32 | 33 | Redistributions of source code must retain the above copyright notice, this list of conditions and the following 34 | disclaimer. 35 | 36 | Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following 37 | disclaimer in the documentation and/or other materials provided with the distribution. 38 | 39 | Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products 40 | derived from this software without specific prior written permission. 41 | 42 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 43 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 44 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 45 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 46 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 47 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 48 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 49 | 50 | If you use the software (in whole or in part), you shall adhere to all applicable U.S., European, and other export 51 | laws, including but not limited to the U.S. Export Administration Regulations ("EAR"), (15 C.F.R. Sections 730 through 52 | 774), and E.U. Council Regulation (EC) No 1334/2000 of 22 June 2000. Further, pursuant to Section 740.6 of the EAR, 53 | you hereby certify that, except pursuant to a license granted by the United States Department of Commerce Bureau of 54 | Industry and Security or as otherwise permitted pursuant to a License Exception under the U.S. Export Administration 55 | Regulations ("EAR"), you will not (1) export, re-export or release to a national of a country in Country Groups D:1, 56 | E:1 or E:2 any restricted technology, software, or source code you receive hereunder, or (2) export to Country Groups 57 | D:1, E:1 or E:2 the direct product of such technology or software, if such foreign produced direct product is subject 58 | to national security controls as identified on the Commerce Control List (currently found in Supplement 1 to Part 774 59 | of EAR). For the most current Country Group listings, or for additional information about the EAR or your obligations 60 | under those regulations, please refer to the U.S. Bureau of Industry and Security's website at http://www.bis.doc.gov/. 61 | 62 | */ 63 | 64 | package com.aparapi.examples.squares; 65 | 66 | import com.aparapi.Kernel; 67 | import com.aparapi.Range; 68 | 69 | /** 70 | * An example Aparapi application which computes and displays squares of a set of 512 input values. 71 | * While executing on GPU using Aparpi framework, each square value is computed in a separate kernel invocation and 72 | * can thus maximize performance by optimally utilizing all GPU computing units 73 | * 74 | * @author gfrost 75 | * @version $Id: $Id 76 | */ 77 | public class Main{ 78 | 79 | /** 80 | *main.
81 | * 82 | * @param _args an array of {@link java.lang.String} objects. 83 | */ 84 | public static void main(String[] _args) { 85 | 86 | final int size = 512; 87 | 88 | /** Input float array for which square values need to be computed. */ 89 | final float[] values = new float[size]; 90 | 91 | /** Initialize input array. */ 92 | for (int i = 0; i < size; i++) { 93 | values[i] = i; 94 | } 95 | 96 | /** Output array which will be populated with square values of corresponding input array elements. */ 97 | final float[] squares = new float[size]; 98 | 99 | /** Aparapi Kernel which computes squares of input array elements and populates them in corresponding elements of 100 | * output array. 101 | **/ 102 | Kernel kernel = new Kernel(){ 103 | @Override public void run() { 104 | int gid = getGlobalId(); 105 | squares[gid] = values[gid] * values[gid]; 106 | } 107 | }; 108 | 109 | // Execute Kernel. 110 | 111 | kernel.execute(Range.create(512)); 112 | 113 | // Report target execution mode: GPU or JTP (Java Thread Pool). 114 | System.out.println("Device = " + kernel.getTargetDevice().getShortDescription()); 115 | 116 | // Display computed square values. 117 | for (int i = 0; i < size; i++) { 118 | System.out.printf("%6.0f %8.0f\n", values[i], squares[i]); 119 | } 120 | 121 | // Dispose Kernel resources. 122 | kernel.dispose(); 123 | } 124 | 125 | } 126 | -------------------------------------------------------------------------------- /src/main/resources/convolution.cl: -------------------------------------------------------------------------------- 1 | void processPixel(__global float* _convMatrix3x3, __global char* _imageIn, __global char* _imageOut, int _width, int _height, int _x, int _y){ 2 | float accum = 0.0f; 3 | int count = 0; 4 | for (int dx = -3; dx<6; dx+=3){ 5 | for (int dy = -1; dy<2; dy++){ 6 | int rgb = 0xff & _imageIn[(((_y + dy) * _width) + (_x + dx))]; 7 | accum = accum + ((float)rgb * _convMatrix3x3[count++]); 8 | } 9 | } 10 | char value = (char )max(0, min((int)accum, 255)); 11 | _imageOut[(_y * _width) + _x] = value; 12 | return; 13 | } 14 | 15 | __kernel void applyConvolution( 16 | __global float *_convMatrix3x3, // only read from kernel 17 | __global char *_imageIn, // only read from kernel 18 | __global char *_imageOut, // only written to (never read) from kernel 19 | int _width, 20 | int _height 21 | ){ 22 | int x = get_global_id(0) % (_width * 3); 23 | int y = get_global_id(0) / (_width * 3); 24 | if (x>3 && x<((_width * 3) - 3) && y>1 && y<(_height - 1)){ 25 | processPixel(_convMatrix3x3, _imageIn, _imageOut, _width*3, _height, x, y); 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /src/main/resources/duke.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Syncleus/aparapi-examples/66a48dc5b4f0f81640cb6be3046426bb02860734/src/main/resources/duke.jpg -------------------------------------------------------------------------------- /src/main/resources/knight.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Syncleus/aparapi-examples/66a48dc5b4f0f81640cb6be3046426bb02860734/src/main/resources/knight.png -------------------------------------------------------------------------------- /src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # Root logger option 2 | log4j.rootLogger=DEBUG, stdout 3 | 4 | # Direct log messages to stdout 5 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 6 | log4j.appender.stdout.Target=System.out 7 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 8 | log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n -------------------------------------------------------------------------------- /src/main/resources/mandel.cl: -------------------------------------------------------------------------------- 1 | #define MAX_ITERATIONS 64 2 | 3 | __constant const int pallette[]={ 4 | -65536, 5 | -59392, 6 | -53248, 7 | -112640, 8 | -106752, 9 | -166144, 10 | -160256, 11 | -219904, 12 | -279552, 13 | -339200, 14 | -399104, 15 | -985344, 16 | -2624000, 17 | -4197376, 18 | -5770496, 19 | -7343872, 20 | -8851712, 21 | -10425088, 22 | -11932928, 23 | -13375232, 24 | -14817792, 25 | -16260096, 26 | -16719602, 27 | -16720349, 28 | -16721097, 29 | -16721846, 30 | -16722595, 31 | -16723345, 32 | -16724351, 33 | -16725102, 34 | -16726110, 35 | -16727119, 36 | -16728129, 37 | -16733509, 38 | -16738889, 39 | -16744269, 40 | -16749138, 41 | -16754006, 42 | -16758619, 43 | -16762976, 44 | -16767077, 45 | -16771178, 46 | -16774767, 47 | -16514932, 48 | -15662970, 49 | -14942079, 50 | -14221189, 51 | -13631371, 52 | -13107088, 53 | -12648342, 54 | -12320669, 55 | -11992995, 56 | -11796393, 57 | -11665328, 58 | -11993019, 59 | -12386248, 60 | -12845011, 61 | -13303773, 62 | -13762534, 63 | -14286830, 64 | -14745588, 65 | -15269881, 66 | -15728637, 67 | -16252927, 68 | 0 69 | }; 70 | 71 | __kernel void createMandleBrot( 72 | float scale, 73 | float offsetx, 74 | float offsety, 75 | __global int *rgb 76 | ){ 77 | int gid = get_global_id(0) + get_global_id(1)*get_global_size(0); 78 | float x = ((((float)(get_global_id(0)) * scale) - ((scale / 2.0f) * (float)get_global_size(0))) / (float)get_global_size(0)) + offsetx; 79 | float y = ((((float)(get_global_id(1)) * scale) - ((scale / 2.0f) * (float)get_global_size(1))) / (float)get_global_size(1)) + offsety; 80 | int count = 0; 81 | float zx = x; 82 | float zy = y; 83 | float new_zx = 0.0f; 84 | for (; count