瀏覽代碼

initial code

kpmy 6 年之前
父節點
當前提交
f544be3da4

+ 4 - 0
.gitignore

@@ -0,0 +1,4 @@
+/target
+/*.iml
+/*.ipr
+/*.iws

+ 116 - 0
pom.xml

@@ -0,0 +1,116 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>in.ocsf.bee.freigeld</groupId>
+    <artifactId>freigeld-core</artifactId>
+    <version>0.0.1-SNAPSHOT</version>
+
+    <properties>
+        <java.version>1.8</java.version>
+        <maven-surefire-plugin.version>2.21.0</maven-surefire-plugin.version>
+        <kotlin.version>1.3.10</kotlin.version>
+        <target>1.8</target>
+    </properties>
+
+    <parent>
+        <groupId>org.springframework.boot</groupId>
+        <artifactId>spring-boot-starter-parent</artifactId>
+        <version>2.0.3.RELEASE</version>
+    </parent>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.springframework.boot</groupId>
+                    <artifactId>spring-boot-starter-tomcat</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-undertow</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.jetbrains.kotlin</groupId>
+            <artifactId>kotlin-stdlib-jdk8</artifactId>
+            <version>${kotlin.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.jetbrains.kotlin</groupId>
+            <artifactId>kotlin-reflect</artifactId>
+            <version>${kotlin.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.jetbrains.kotlinx</groupId>
+            <artifactId>kotlinx-coroutines-core</artifactId>
+            <version>1.1.0</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.fasterxml.jackson.module</groupId>
+            <artifactId>jackson-module-kotlin</artifactId>
+            <version>2.9.4.1</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.aparapi</groupId>
+            <artifactId>aparapi</artifactId>
+            <version>1.8.0</version>
+        </dependency>
+
+    </dependencies>
+
+    <build>
+        <finalName>frei</finalName>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+            </plugin>
+            <plugin>
+                <groupId>org.jetbrains.kotlin</groupId>
+                <artifactId>kotlin-maven-plugin</artifactId>
+                <version>${kotlin.version}</version>
+                <executions>
+                    <execution>
+                        <id>compile</id>
+                        <phase>compile</phase>
+                        <goals>
+                            <goal>compile</goal>
+                        </goals>
+                    </execution>
+                    <execution>
+                        <id>test-compile</id>
+                        <phase>test-compile</phase>
+                        <goals>
+                            <goal>test-compile</goal>
+                        </goals>
+                    </execution>
+                </executions>
+                <configuration>
+                    <compilerPlugins>
+                        <plugin>spring</plugin>
+                    </compilerPlugins>
+                    <jvmTarget>1.8</jvmTarget>
+                </configuration>
+                <dependencies>
+                    <dependency>
+                        <groupId>org.jetbrains.kotlin</groupId>
+                        <artifactId>kotlin-maven-allopen</artifactId>
+                        <version>${kotlin.version}</version>
+                    </dependency>
+                </dependencies>
+            </plugin>
+        </plugins>
+    </build>
+</project>

+ 21 - 0
src/main/java/in/ocsf/bee/freigeld/core/cl/Pt.java

@@ -0,0 +1,21 @@
+package in.ocsf.bee.freigeld.core.cl;
+
+final class Pt {
+        private int x, y;
+
+        public int getX() {
+            return x;
+        }
+
+        public void setX(int x) {
+            this.x = x;
+        }
+
+        public int getY() {
+            return y;
+        }
+
+        public void setY(int y) {
+            this.y = y;
+        }
+    }

+ 61 - 0
src/main/java/in/ocsf/bee/freigeld/core/cl/Sample.java

@@ -0,0 +1,61 @@
+package in.ocsf.bee.freigeld.core.cl;
+
+import com.aparapi.Kernel;
+import com.aparapi.Range;
+import com.aparapi.device.Device;
+import com.aparapi.internal.kernel.KernelManager;
+
+import java.util.logging.Logger;
+
+public class Sample implements Runnable {
+
+    private final Logger log = Logger.getLogger(getClass().getName());
+
+    @Override
+    public void run() {
+        final int R = 1024;
+        final int[] buffer_$constant$ = new int[]{1,2,3,4,5,6,7,8,9};
+
+        final float[] resultF = new float[R];
+        final boolean[] resultB = new boolean[R];
+        final byte[] resultH = new byte[R];
+        final short[] resultS = new short[R];
+        final int[] resultI = new int[R];
+        final long[] resultL = new long[R];
+        final Pt[] resultO = new Pt[R];
+
+        for(int i = 0; i<R; i++)
+            resultO[i] = new Pt();
+
+        Kernel kernel = new Kernel() {
+
+            protected @PrivateMemorySpace(4) short[] myBuffer = new short[4];
+            @Constant int[] myBufferConstant  = new int[]{0, 1, 2, 3};
+            @Local  final int[] buffer = new int[R];
+
+            @Override
+            public void run() {
+                int i = getGlobalId();
+                for(int j = 0; j < myBuffer.length; j++){
+                    myBuffer[j] = (short) j;
+                }
+                buffer[i] = -i;
+                localBarrier();
+                resultB[i] = i % 2 == 0;
+                resultL[i] = buffer_$constant$[i % 4];
+                resultI[i] = myBufferConstant[i % 4];
+                resultS[i] = myBuffer[i % 4];
+                resultH[i] = (byte) buffer[i];
+                resultF[i] = resultI[i];
+                resultO[i].setX(i);
+                resultO[i].setY(i);
+            }
+        };
+        Device device = Device.best();
+        Range range = Range.create(device, R);
+        log.info("opencl run");
+        kernel.execute(range, 1024);
+        log.info("done opencl run");
+    }
+
+}

+ 48 - 0
src/main/kotlin/in/ocsf/bee/freigeld/core/FreiApp.kt

@@ -0,0 +1,48 @@
+package `in`.ocsf.bee.freigeld.core
+
+import `in`.ocsf.bee.freigeld.core.cl.*
+import org.springframework.boot.SpringApplication
+import org.springframework.boot.autoconfigure.SpringBootApplication
+import org.springframework.context.annotation.PropertySource
+import org.springframework.context.annotation.PropertySources
+import org.springframework.web.bind.annotation.RequestMapping
+import org.springframework.web.bind.annotation.RestController
+import sun.misc.Unsafe
+import javax.annotation.PostConstruct
+
+@SpringBootApplication
+@PropertySource("classpath:application.yaml")
+class FreiApp{
+
+    @PostConstruct
+    fun init(){
+
+    }
+}
+
+@RestController
+class DevController{
+
+    @RequestMapping("dev/test0")
+    fun test0() {
+        Sample().run();
+    }
+}
+
+fun main(args: Array<String>) {
+    disableWarning();
+    SpringApplication.run(FreiApp::class.java, *args)
+}
+
+fun disableWarning() {
+    try {
+        val theUnsafe = Unsafe::class.java!!.getDeclaredField("theUnsafe")
+        theUnsafe.setAccessible(true)
+        val u = theUnsafe.get(null) as Unsafe
+        val cls = Class.forName("jdk.internal.module.IllegalAccessLogger")
+        val logger = cls.getDeclaredField("logger")
+        u.putObjectVolatile(cls, u.staticFieldOffset(logger), null)
+    } catch (e: Exception) {
+        // ignore
+    }
+}

+ 2 - 0
src/main/resources/application-dev.yaml

@@ -0,0 +1,2 @@
+server:
+  port: 4200

+ 3 - 0
src/main/resources/application.yaml

@@ -0,0 +1,3 @@
+server:
+  servlet:
+    context-path: /frei

+ 9 - 0
src/main/resources/banner.txt

@@ -0,0 +1,9 @@
+
+  ______        _  _____      _     _
+ |  ____|      (_)/ ____|    | |   | |
+ | |__ _ __ ___ _| |  __  ___| | __| |
+ |  __| '__/ _ \ | | |_ |/ _ \ |/ _` |
+ | |  | | |  __/ | |__| |  __/ | (_| |
+ |_|  |_|  \___|_|\_____|\___|_|\__,_|
+
+