Skip to content

Commit 5d2f5c2

Browse files
committed
JavaCL: moved BridJ implementation to trunk (in main OpenCL directory tree)
1 parent 4eebd2a commit 5d2f5c2

File tree

1,768 files changed

+25427
-278928
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,768 files changed

+25427
-278928
lines changed

Blas/.classpath

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry including="**/*.java" kind="src" output="target/test-classes" path="src/test/java"/>
4+
<classpathentry including="**/*.java" kind="src" path="src/main/java"/>
5+
<classpathentry kind="con" path="org.eclipse.iam.jdt.core.mavenClasspathContainer"/>
6+
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
7+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
8+
<classpathentry combineaccessrules="false" kind="src" path="/JavaCL"/>
9+
<classpathentry kind="output" path="target/classes"/>
10+
</classpath>

Blas/.project

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>Blas</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.maven.ide.eclipse.maven2Builder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
<buildCommand>
19+
<name>org.eclipse.iam.jdt.core.mavenIncrementalBuilder</name>
20+
<arguments>
21+
</arguments>
22+
</buildCommand>
23+
</buildSpec>
24+
<natures>
25+
<nature>org.maven.ide.eclipse.maven2Nature</nature>
26+
<nature>org.eclipse.iam.jdt.core.mavenNature</nature>
27+
<nature>org.eclipse.jdt.core.javanature</nature>
28+
</natures>
29+
</projectDescription>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#Thu Jan 28 23:48:19 CET 2010
2+
eclipse.preferences.version=1
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
4+
org.eclipse.jdt.core.compiler.compliance=1.6
5+
org.eclipse.jdt.core.compiler.source=1.6

Blas/javacl-blas-bridj.iml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5" inherit-compiler-output="false">
4+
<output url="file://$MODULE_DIR$/target/classes" />
5+
<output-test url="file://$MODULE_DIR$/target/test-classes" />
6+
<content url="file://$MODULE_DIR$">
7+
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
8+
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" isTestSource="false" />
9+
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
10+
<excludeFolder url="file://$MODULE_DIR$/target" />
11+
</content>
12+
<orderEntry type="inheritedJdk" />
13+
<orderEntry type="sourceFolder" forTests="false" />
14+
<orderEntry type="module" module-name="javacl-bridj" />
15+
<orderEntry type="module" module-name="javacl-core-bridj" />
16+
<orderEntry type="module" module-name="opencl4java-bridj" />
17+
<orderEntry type="library" name="Maven: com.nativelibs4java:bridj:c-only:0.4.2" level="project" />
18+
<orderEntry type="library" name="Maven: org.ujmp:ujmp-core:0.2.4" level="project" />
19+
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.7" level="project" />
20+
</component>
21+
</module>
22+

Blas/pom.xml

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>com.nativelibs4java</groupId>
6+
<artifactId>javacl-blas</artifactId>
7+
<name>JavaCL BLAS / BridJ</name>
8+
<url>http://code.google.com/p/javacl/</url>
9+
<version>1.0.0-RC1</version>
10+
<packaging>jar</packaging>
11+
12+
<parent>
13+
<groupId>com.nativelibs4java</groupId>
14+
<artifactId>opencl4java-parent</artifactId>
15+
<version>1.0.0-RC1</version>
16+
<relativePath>../Parent</relativePath>
17+
</parent>
18+
19+
<dependencies>
20+
21+
<dependency>
22+
<groupId>com.nativelibs4java</groupId>
23+
<artifactId>javacl</artifactId>
24+
<version>${opencl4java.version}</version>
25+
<!--classifier>shaded</classifier-->
26+
<scope>compile</scope>
27+
</dependency>
28+
29+
<dependency>
30+
<groupId>org.ujmp</groupId>
31+
<artifactId>ujmp-core</artifactId>
32+
<version>0.2.4</version>
33+
<scope>compile</scope>
34+
</dependency>
35+
36+
</dependencies>
37+
38+
<build>
39+
<plugins>
40+
41+
<plugin>
42+
<groupId>com.nativelibs4java</groupId>
43+
<artifactId>javacl-generator</artifactId>
44+
<version>${opencl4java.version}</version>
45+
46+
<!--configuration>
47+
<javaOutputDirectory>${project.build.directory}/../src/main/java</javaOutputDirectory>
48+
</configuration-->
49+
<executions>
50+
<execution>
51+
<phase>generate-sources</phase>
52+
<goals>
53+
<goal>compile</goal>
54+
<!--goal>test-compile</goal-->
55+
</goals>
56+
57+
</execution>
58+
</executions>
59+
</plugin>
60+
61+
</plugins>
62+
</build>
63+
</project>
64+
65+
66+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/*
2+
* To change this template, choose Tools | Templates
3+
* and open the template in the editor.
4+
*/
5+
package com.nativelibs4java.opencl.blas;
6+
7+
import com.nativelibs4java.opencl.*;
8+
import com.nativelibs4java.opencl.CLMem.Usage;
9+
import com.nativelibs4java.opencl.util.Primitive;
10+
import org.bridj.Pointer;
11+
12+
/**
13+
*
14+
* @author ochafik
15+
*/
16+
public class CLDefaultMatrix2D<T> implements CLMatrix2D<T> {
17+
protected final Primitive primitive;
18+
protected final Class<T> primitiveClass;
19+
protected final long rows, columns, length;
20+
21+
protected final CLKernels kernels;
22+
protected final CLBuffer<T> buffer;
23+
protected final CLQueue queue;
24+
protected final CLContext context;
25+
protected CLEvents _events = new CLEvents();
26+
27+
public CLDefaultMatrix2D(Primitive primitive, CLBuffer<T> buffer, long rows, long columns, CLKernels kernels) {
28+
this.primitive = primitive;
29+
this.primitiveClass = (Class<T>)primitive.primitiveType;
30+
this.length = rows * columns;
31+
this.buffer = buffer == null ? (CLBuffer)kernels.getContext().createBuffer(Usage.InputOutput, primitive.primitiveType, length) : buffer;
32+
this.kernels = kernels;
33+
this.rows = rows;
34+
this.columns = columns;
35+
this.queue = kernels.getQueue();
36+
this.context = kernels.getContext();
37+
}
38+
39+
public CLMatrix2D<T> blankClone() {
40+
return blankMatrix(getRowCount(), getColumnCount());
41+
}
42+
public CLMatrix2D<T> blankMatrix(long rows, long columns) {
43+
return new CLDefaultMatrix2D<T>(primitive, null, rows, columns, kernels);
44+
}
45+
46+
public long getRowCount() {
47+
return rows;
48+
}
49+
50+
public long getColumnCount() {
51+
return columns;
52+
}
53+
54+
public CLEvents getEvents() {
55+
return _events;
56+
}
57+
58+
public void write(final Pointer<T> b) {
59+
getEvents().performWrite(new CLEvents.Action() {
60+
public CLEvent perform(CLEvent[] events) {
61+
return buffer.write(queue, b, false, events);
62+
}
63+
});
64+
}
65+
66+
public void read(final Pointer<T> b) {
67+
getEvents().performRead(new CLEvents.Action() {
68+
public CLEvent perform(CLEvent[] events) {
69+
return buffer.read(queue, b, true, events);
70+
}
71+
});
72+
}
73+
public Pointer<T> read() {
74+
Pointer<T> out = Pointer.allocateArray(primitiveClass, length);
75+
read(out);
76+
return out;
77+
}
78+
79+
80+
public CLBuffer<T> getBuffer() {
81+
return buffer;
82+
}
83+
84+
public CLContext getContext() {
85+
return context;
86+
}
87+
88+
public synchronized CLQueue getQueue() {
89+
return queue;
90+
}
91+
92+
/*
93+
public synchronized void setQueue(CLQueue queue) {
94+
if (this.queue != null && queue != null) {
95+
if (this.queue.equals(queue))
96+
return;
97+
}
98+
getEvents().waitFor();
99+
this.queue = queue;
100+
}
101+
* */
102+
103+
public Primitive getPrimitive() {
104+
return primitive;
105+
}
106+
107+
public Class<T> getPrimitiveClass() {
108+
return primitiveClass;
109+
}
110+
111+
public CLKernels getKernels() {
112+
return kernels;
113+
}
114+
115+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* To change this template, choose Tools | Templates
3+
* and open the template in the editor.
4+
*/
5+
package com.nativelibs4java.opencl.blas;
6+
7+
import com.nativelibs4java.opencl.CLEvent;
8+
import java.util.ArrayList;
9+
import java.util.List;
10+
11+
/**
12+
*
13+
* @author ochafik
14+
*/
15+
public class CLEvents {
16+
CLEvent lastWriteEvent;
17+
List<CLEvent> readEvents = new ArrayList<CLEvent>();
18+
19+
List<Listener> listeners = new ArrayList<Listener>();
20+
21+
public interface Listener {
22+
void writing(CLEvents evts);
23+
void reading(CLEvents evts);
24+
}
25+
public interface Action {
26+
CLEvent perform(CLEvent[] events);
27+
}
28+
29+
public synchronized void addListener(Listener l) {
30+
listeners.add(l);
31+
}
32+
public synchronized void removeListener(Listener l) {
33+
listeners.remove(l);
34+
}
35+
static final CLEvent[] EMPTY_EVENTS = new CLEvent[0];
36+
protected synchronized CLEvent clearEvents(Action action) {
37+
int nReads = readEvents.size();
38+
boolean hasWrite = lastWriteEvent != null;
39+
int n = nReads + (hasWrite ? 1 : 0);
40+
CLEvent[] evts = n == 0 ? EMPTY_EVENTS : readEvents.toArray(new CLEvent[n]);
41+
if (hasWrite)
42+
evts[nReads] = lastWriteEvent;
43+
CLEvent evt = action.perform(evts);
44+
lastWriteEvent = null;
45+
readEvents.clear();
46+
return evt;
47+
}
48+
public synchronized CLEvent performRead(Action action) {
49+
for (Listener listener : listeners)
50+
listener.writing(this);
51+
CLEvent evt = action.perform(lastWriteEvent == null ? EMPTY_EVENTS : new CLEvent[] { lastWriteEvent });
52+
if (evt != null) {
53+
readEvents.add(evt);
54+
lastWriteEvent = null; // read completed only if the optional write also completed
55+
}
56+
return evt;
57+
}
58+
59+
public synchronized void performRead(Runnable action) {
60+
for (Listener listener : listeners)
61+
listener.reading(this);
62+
waitForRead();
63+
action.run();
64+
}
65+
66+
public synchronized CLEvent performWrite(Action action) {
67+
return lastWriteEvent = clearEvents(action);
68+
}
69+
70+
/**
71+
* Wait until all write operations are completed so that the data is readable.
72+
*/
73+
public synchronized void waitForRead() {
74+
CLEvent.waitFor(lastWriteEvent);
75+
lastWriteEvent = null;
76+
}
77+
/**
78+
* Wait for all associated operations to complete (read or write).
79+
*/
80+
public synchronized void waitFor() {
81+
clearEvents(new Action() {
82+
public CLEvent perform(CLEvent[] evts) {
83+
CLEvent.waitFor(evts);
84+
return null;
85+
}
86+
});
87+
}
88+
}

0 commit comments

Comments
 (0)