From 214bb2696edb9eccd8f619d19985d069b91d8564 Mon Sep 17 00:00:00 2001
From: Gary Frost <frost.gary@gmail.com>
Date: Thu, 6 Sep 2012 01:18:43 +0000
Subject: [PATCH]

---
 samples/add/.classpath                        |  8 ++
 samples/add/.project                          | 17 +++++
 samples/add/add.bat                           |  6 ++
 samples/add/add.sh                            |  5 ++
 samples/add/build.xml                         | 20 +++++
 .../src/com/amd/aparapi/sample/add/Main.java  | 76 +++++++++++++++++++
 6 files changed, 132 insertions(+)
 create mode 100644 samples/add/.classpath
 create mode 100644 samples/add/.project
 create mode 100644 samples/add/add.bat
 create mode 100644 samples/add/add.sh
 create mode 100644 samples/add/build.xml
 create mode 100644 samples/add/src/com/amd/aparapi/sample/add/Main.java

diff --git a/samples/add/.classpath b/samples/add/.classpath
new file mode 100644
index 00000000..2b3d4294
--- /dev/null
+++ b/samples/add/.classpath
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
+	<classpathentry combineaccessrules="false" kind="src" path="/com.amd.aparapi"/>
+	<classpathentry kind="output" path="classes"/>
+</classpath>
diff --git a/samples/add/.project b/samples/add/.project
new file mode 100644
index 00000000..11a89faa
--- /dev/null
+++ b/samples/add/.project
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>add</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>
diff --git a/samples/add/add.bat b/samples/add/add.bat
new file mode 100644
index 00000000..b8ae70f6
--- /dev/null
+++ b/samples/add/add.bat
@@ -0,0 +1,6 @@
+java ^
+ -Djava.library.path=../../com.amd.aparapi.jni/dist ^
+ -Dcom.amd.aparapi.executionMode=%1 ^
+ -classpath ../../com.amd.aparapi/dist/aparapi.jar;add.jar ^
+ com.amd.aparapi.sample.add.Main
+
diff --git a/samples/add/add.sh b/samples/add/add.sh
new file mode 100644
index 00000000..df37f681
--- /dev/null
+++ b/samples/add/add.sh
@@ -0,0 +1,5 @@
+java \
+ -Djava.library.path=../../com.amd.aparapi.jni/dist \
+ -Dcom.amd.aparapi.executionMode=%1 \
+ -classpath ../../com.amd.aparapi/dist/aparapi.jar:add.jar \
+ com.amd.aparapi.sample.add.Main
diff --git a/samples/add/build.xml b/samples/add/build.xml
new file mode 100644
index 00000000..2b0d1eee
--- /dev/null
+++ b/samples/add/build.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0"?>
+
+<project name="add" default="build" basedir=".">
+   <target name="build" depends="clean">
+      <mkdir dir="classes"/>
+      <javac srcdir="src" destdir="classes" debug="on" includeantruntime="false" >
+         <classpath>
+            <pathelement path="../../com.amd.aparapi/dist/aparapi.jar"/>
+         </classpath>
+      </javac>
+      <jar jarfile="${ant.project.name}.jar" basedir="classes"/>
+   </target>
+
+   <target name="clean">
+      <delete dir="classes"/>
+      <delete file="${ant.project.name}.jar"/>
+   </target>
+
+
+</project>
diff --git a/samples/add/src/com/amd/aparapi/sample/add/Main.java b/samples/add/src/com/amd/aparapi/sample/add/Main.java
new file mode 100644
index 00000000..a362a10e
--- /dev/null
+++ b/samples/add/src/com/amd/aparapi/sample/add/Main.java
@@ -0,0 +1,76 @@
+/*
+Copyright (c) 2010-2011, Advanced Micro Devices, Inc.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
+following conditions are met:
+
+Redistributions of source code must retain the above copyright notice, this list of conditions and the following
+disclaimer. 
+
+Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
+disclaimer in the documentation and/or other materials provided with the distribution. 
+
+Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products
+derived from this software without specific prior written permission. 
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+If you use the software (in whole or in part), you shall adhere to all applicable U.S., European, and other export
+laws, including but not limited to the U.S. Export Administration Regulations ("EAR"), (15 C.F.R. Sections 730 through
+774), and E.U. Council Regulation (EC) No 1334/2000 of 22 June 2000.  Further, pursuant to Section 740.6 of the EAR,
+you hereby certify that, except pursuant to a license granted by the United States Department of Commerce Bureau of 
+Industry and Security or as otherwise permitted pursuant to a License Exception under the U.S. Export Administration 
+Regulations ("EAR"), you will not (1) export, re-export or release to a national of a country in Country Groups D:1,
+E:1 or E:2 any restricted technology, software, or source code you receive hereunder, or (2) export to Country Groups
+D:1, E:1 or E:2 the direct product of such technology or software, if such foreign produced direct product is subject
+to national security controls as identified on the Commerce Control List (currently found in Supplement 1 to Part 774
+of EAR).  For the most current Country Group listings, or for additional information about the EAR or your obligations
+under those regulations, please refer to the U.S. Bureau of Industry and Security's website at http://www.bis.doc.gov/. 
+
+*/
+
+package com.amd.aparapi.sample.add;
+
+import com.amd.aparapi.Kernel;
+import com.amd.aparapi.Range;
+
+public class Main{
+
+   public static void main(String[] _args) {
+
+      final int size = 512;
+
+      final float[] a = new float[size];
+      final float[] b = new float[size];
+
+      for (int i = 0; i < size; i++) {
+         a[i] = (float)(Math.random()*100);
+         b[i] = (float)(Math.random()*100);
+      }
+
+      final float[] sum = new float[size];
+
+      Kernel kernel = new Kernel(){
+         @Override public void run() {
+            int gid = getGlobalId();
+            sum[gid] = a[gid] + b[gid];
+         }
+      };
+
+      kernel.execute(Range.create(512));
+
+      for (int i = 0; i < size; i++) {
+         System.out.printf("%6.2f + %6.2f = %8.2f\n", a[i], b[i], sum[i]);
+      }
+
+      kernel.dispose();
+   }
+
+}
-- 
GitLab