[Swift-commit] r6370 - in branches/faster: libexec resources src/org/griphyn/vdl/engine src/org/griphyn/vdl/karajan/lib
hategan at ci.uchicago.edu
hategan at ci.uchicago.edu
Mon Mar 11 14:58:59 CDT 2013
Author: hategan
Date: 2013-03-11 14:58:59 -0500 (Mon, 11 Mar 2013)
New Revision: 6370
Added:
branches/faster/src/org/griphyn/vdl/karajan/lib/RefCount.java
branches/faster/src/org/griphyn/vdl/karajan/lib/StaticRefCount.java
branches/faster/src/org/griphyn/vdl/karajan/lib/While.java
Modified:
branches/faster/libexec/swift-lib.k
branches/faster/libexec/swift-operators.k
branches/faster/resources/Karajan.stg
branches/faster/src/org/griphyn/vdl/engine/Karajan.java
branches/faster/src/org/griphyn/vdl/karajan/lib/Operators.java
branches/faster/src/org/griphyn/vdl/karajan/lib/ThrottledParallelFor.java
Log:
fixed iterate
Modified: branches/faster/libexec/swift-lib.k
===================================================================
--- branches/faster/libexec/swift-lib.k 2013-03-11 16:59:36 UTC (rev 6369)
+++ branches/faster/libexec/swift-lib.k 2013-03-11 19:58:59 UTC (rev 6370)
@@ -119,6 +119,7 @@
export(tParallelFor, def("org.griphyn.vdl.karajan.lib.ThrottledParallelFor"))
export(throttled, def("org.griphyn.vdl.karajan.lib.Throttled"))
+ export(while, def("org.griphyn.vdl.karajan.lib.While"))
export(appStageins, def("org.griphyn.vdl.karajan.lib.AppStageins"))
export(appStageouts, def("org.griphyn.vdl.karajan.lib.AppStageouts"))
Modified: branches/faster/libexec/swift-operators.k
===================================================================
--- branches/faster/libexec/swift-operators.k 2013-03-11 16:59:36 UTC (rev 6369)
+++ branches/faster/libexec/swift-operators.k 2013-03-11 19:58:59 UTC (rev 6370)
@@ -14,4 +14,6 @@
export(and, def("org.griphyn.vdl.karajan.lib.Operators$And"))
export(or, def("org.griphyn.vdl.karajan.lib.Operators$Or"))
export(not, def("org.griphyn.vdl.karajan.lib.Operators$Not"))
+
+ export(inc, def("org.griphyn.vdl.karajan.lib.Operators$Inc"))
}
\ No newline at end of file
Modified: branches/faster/resources/Karajan.stg
===================================================================
--- branches/faster/resources/Karajan.stg 2013-03-11 16:59:36 UTC (rev 6369)
+++ branches/faster/resources/Karajan.stg 2013-03-11 19:58:59 UTC (rev 6370)
@@ -196,17 +196,17 @@
)
>>
-iterate(declarations,statements,cond,var,cleanups,trace,line) ::= <<
-sys:while($var$, 0) {
+iterate(declarations, statements, cond, var, refs, cleanups, trace, line) ::= <<
+swift:while($var$$if(trace)$, _traceline="$line$"$endif$$if(refs)$, refs="$refs;separator=" "$"$endif$) {
if (swift:getFieldValue($cond$)) {
$sub_comp(declarations=declarations, statements=statements, cleanups=cleanups)$
- next($var$ + 1)
+ next(swiftop:inc($var$))
}
}
>>
foreach(var, in, indexVar, indexVarType, declarations, statements, line, refs, selfClose, cleanups, trace) ::= <<
-swift:tParallelFor(\$, _traceline="$line$"$if(indexVar)$, _kvar="$indexVar$"$endif$, _vvar="$var$"$if(selfClose)$, selfClose=true$endif$$if(refs)$, refs="$refs;separator=" "$"$endif$,
+swift:tParallelFor(\$$if(trace)$, _traceline="$line$"$endif$$if(indexVar)$, _kvar="$indexVar$"$endif$, _vvar="$var$"$if(selfClose)$, selfClose=true$endif$$if(refs)$, refs="$refs;separator=" "$"$endif$,
$! The iterator !$
getArrayIterator($in$)) {
(\$\$, $var$) := each(\$)
Modified: branches/faster/src/org/griphyn/vdl/engine/Karajan.java
===================================================================
--- branches/faster/src/org/griphyn/vdl/engine/Karajan.java 2013-03-11 16:59:36 UTC (rev 6369)
+++ branches/faster/src/org/griphyn/vdl/engine/Karajan.java 2013-03-11 19:58:59 UTC (rev 6370)
@@ -916,7 +916,7 @@
}
public void iterateStat(Iterate iterate, VariableScope scope) throws CompilationException {
- VariableScope loopScope = new VariableScope(this, scope, EnclosureType.LOOP, iterate);
+ VariableScope loopScope = new VariableScope(this, scope, EnclosureType.ALL, iterate);
VariableScope innerScope = new VariableScope(this, loopScope, EnclosureType.LOOP, iterate);
loopScope.addVariable(iterate.getVar(), "int", "Iteration variable", iterate);
Modified: branches/faster/src/org/griphyn/vdl/karajan/lib/Operators.java
===================================================================
--- branches/faster/src/org/griphyn/vdl/karajan/lib/Operators.java 2013-03-11 16:59:36 UTC (rev 6369)
+++ branches/faster/src/org/griphyn/vdl/karajan/lib/Operators.java 2013-03-11 19:58:59 UTC (rev 6370)
@@ -67,7 +67,7 @@
return ((Integer) v).intValue();
}
else {
- throw new ExecutionException(n, "Internal error. Expected an int: " + h);
+ throw new ExecutionException(n, "Internal error. Expected an int: " + v + " (" + h + ")");
}
}
@@ -265,6 +265,14 @@
return r;
}
}
+
+ public static class Inc extends SwiftUnaryOp {
+ @Override
+ protected DSHandle value(AbstractDataNode v) {
+ DSHandle r = new RootDataNode(Types.INT, getInt(this, v) + 1);
+ return r;
+ }
+ }
private static void logBinaryProvenance(String name, DSHandle v1, DSHandle v2, DSHandle result) throws ExecutionException {
if (PROVENANCE_ENABLED) {
Added: branches/faster/src/org/griphyn/vdl/karajan/lib/RefCount.java
===================================================================
--- branches/faster/src/org/griphyn/vdl/karajan/lib/RefCount.java (rev 0)
+++ branches/faster/src/org/griphyn/vdl/karajan/lib/RefCount.java 2013-03-11 19:58:59 UTC (rev 6370)
@@ -0,0 +1,55 @@
+//----------------------------------------------------------------------
+//This code is developed as part of the Java CoG Kit project
+//The terms of the license can be found at http://www.cogkit.org/license
+//This message may not be removed or altered.
+//----------------------------------------------------------------------
+
+/*
+ * Created on Mar 11, 2013
+ */
+package org.griphyn.vdl.karajan.lib;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import k.rt.ExecutionException;
+import k.rt.Stack;
+
+import org.griphyn.vdl.mapping.DSHandle;
+
+class RefCount {
+ public final DSHandle var;
+ public final int count;
+
+ public RefCount(DSHandle var, int count) {
+ this.var = var;
+ this.count = count;
+ }
+
+ public static List<RefCount> build(Stack stack, List<StaticRefCount> srefs) {
+ if (srefs == null) {
+ return null;
+ }
+ List<RefCount> l = new ArrayList<RefCount>(srefs.size());
+ for (StaticRefCount s : srefs) {
+ l.add(new RefCount((DSHandle) s.ref.getValue(stack), s.count));
+ }
+ return l;
+ }
+
+ public static void decRefs(List<RefCount> rcs) throws ExecutionException {
+ if (rcs != null) {
+ for (RefCount rc : rcs) {
+ rc.var.updateWriteRefCount(-rc.count);
+ }
+ }
+ }
+
+ public static void incRefs(List<RefCount> rcs) throws ExecutionException {
+ if (rcs != null) {
+ for (RefCount rc : rcs) {
+ rc.var.updateWriteRefCount(rc.count);
+ }
+ }
+ }
+}
\ No newline at end of file
Added: branches/faster/src/org/griphyn/vdl/karajan/lib/StaticRefCount.java
===================================================================
--- branches/faster/src/org/griphyn/vdl/karajan/lib/StaticRefCount.java (rev 0)
+++ branches/faster/src/org/griphyn/vdl/karajan/lib/StaticRefCount.java 2013-03-11 19:58:59 UTC (rev 6370)
@@ -0,0 +1,48 @@
+//----------------------------------------------------------------------
+//This code is developed as part of the Java CoG Kit project
+//The terms of the license can be found at http://www.cogkit.org/license
+//This message may not be removed or altered.
+//----------------------------------------------------------------------
+
+/*
+ * Created on Mar 11, 2013
+ */
+package org.griphyn.vdl.karajan.lib;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import org.globus.cog.karajan.analyzer.Scope;
+import org.globus.cog.karajan.analyzer.VarRef;
+
+class StaticRefCount {
+ public final VarRef<?> ref;
+ public final int count;
+
+ public StaticRefCount(VarRef<?> ref, int count) {
+ this.ref = ref;
+ this.count = count;
+ }
+
+ public static List<StaticRefCount> build(Scope scope, String refs) {
+ if (refs == null) {
+ return null;
+ }
+ List<StaticRefCount> l = new ArrayList<StaticRefCount>();
+ String name = null;
+ boolean flip = true;
+ StringTokenizer st = new StringTokenizer(refs);
+ while (st.hasMoreTokens()) {
+ if (flip) {
+ name = st.nextToken();
+ }
+ else {
+ int count = Integer.parseInt(st.nextToken());
+ l.add(new StaticRefCount(scope.getVarRef(name), count));
+ }
+ flip = !flip;
+ }
+ return l;
+ }
+}
\ No newline at end of file
Modified: branches/faster/src/org/griphyn/vdl/karajan/lib/ThrottledParallelFor.java
===================================================================
--- branches/faster/src/org/griphyn/vdl/karajan/lib/ThrottledParallelFor.java 2013-03-11 16:59:36 UTC (rev 6369)
+++ branches/faster/src/org/griphyn/vdl/karajan/lib/ThrottledParallelFor.java 2013-03-11 19:58:59 UTC (rev 6370)
@@ -18,10 +18,8 @@
package org.griphyn.vdl.karajan.lib;
import java.io.IOException;
-import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import java.util.StringTokenizer;
import k.rt.ConditionalYield;
import k.rt.ExecutionException;
@@ -40,13 +38,11 @@
import org.globus.cog.karajan.analyzer.CompilerSettings;
import org.globus.cog.karajan.analyzer.Scope;
import org.globus.cog.karajan.analyzer.Signature;
-import org.globus.cog.karajan.analyzer.VarRef;
import org.globus.cog.karajan.compiled.nodes.Node;
import org.globus.cog.karajan.compiled.nodes.UParallelFor;
import org.globus.cog.karajan.parser.WrapperNode;
import org.globus.cog.karajan.util.TypeUtil;
import org.griphyn.vdl.karajan.Pair;
-import org.griphyn.vdl.mapping.DSHandle;
import org.griphyn.vdl.util.VDL2Config;
public class ThrottledParallelFor extends UParallelFor {
@@ -79,38 +75,10 @@
private Tracer forTracer, iterationTracer;
private List<StaticRefCount> srefs;
- private static class StaticRefCount {
- public final VarRef<?> ref;
- public final int count;
-
- public StaticRefCount(VarRef<?> ref, int count) {
- this.ref = ref;
- this.count = count;
- }
- }
-
- private static class RefCount {
- public final DSHandle var;
- public final int count;
-
- public RefCount(DSHandle var, int count) {
- this.var = var;
- this.count = count;
- }
-
- public void inc() {
-
- }
-
- public void dec() {
-
- }
- }
-
@Override
protected Node compileBody(WrapperNode w, Scope argScope, Scope scope)
throws CompilationException {
- srefs = buildStaticRefs(scope);
+ srefs = StaticRefCount.build(scope, this.refs.getValue());
if (_traceline.getValue() != null) {
setLine(Integer.parseInt(_traceline.getValue()));
}
@@ -119,40 +87,7 @@
sc = selfClose.getValue();
return super.compileBody(w, argScope, scope);
}
-
- private List<StaticRefCount> buildStaticRefs(Scope scope) {
- String refs = this.refs.getValue();
- if (refs == null) {
- return null;
- }
- List<StaticRefCount> l = new ArrayList<StaticRefCount>();
- String name = null;
- boolean flip = true;
- StringTokenizer st = new StringTokenizer(refs);
- while (st.hasMoreTokens()) {
- if (flip) {
- name = st.nextToken();
- }
- else {
- int count = Integer.parseInt(st.nextToken());
- l.add(new StaticRefCount(scope.getVarRef(name), count));
- }
- flip = !flip;
- }
- return l;
- }
- private List<RefCount> buildRefs(Stack stack) {
- if (srefs == null) {
- return null;
- }
- List<RefCount> l = new ArrayList<RefCount>(srefs.size());
- for (StaticRefCount s : srefs) {
- l.add(new RefCount((DSHandle) s.ref.getValue(stack), s.count));
- }
- return l;
- }
-
@SuppressWarnings("unchecked")
@Override
protected void runBody(final LWThread thr) {
@@ -173,7 +108,7 @@
ts = new TPFThreadSet(it, getMaxThreads());
}
- drefs = buildRefs(stack);
+ drefs = RefCount.build(stack, srefs);
ts.lock();
fc = stack.frameCount() + 1;
@@ -191,7 +126,7 @@
startRest(thr, ts, fc, drefs);
ts.unlock();
- decRefs(drefs);
+ RefCount.decRefs(drefs);
i++;
case 2:
ts.waitFor();
@@ -242,7 +177,7 @@
}
private boolean startOne(final LWThread thr, final ThreadSet ts, final Object value, final int fcf, List<RefCount> refs) {
- incRefs(refs);
+ RefCount.incRefs(refs);
LWThread ct = thr.fork(new KRunnable() {
@Override
public void run(LWThread thr2) {
@@ -281,23 +216,7 @@
ct.start();
return false;
}
-
- private void decRefs(List<RefCount> rcs) throws ExecutionException {
- if (rcs != null) {
- for (RefCount rc : rcs) {
- rc.var.updateWriteRefCount(-rc.count);
- }
- }
- }
- private void incRefs(List<RefCount> rcs) throws ExecutionException {
- if (rcs != null) {
- for (RefCount rc : rcs) {
- rc.var.updateWriteRefCount(rc.count);
- }
- }
- }
-
private int getMaxThreads() {
if (maxThreadCount < 0) {
@@ -314,7 +233,7 @@
protected Object unwrap(Object value) {
if (value instanceof Pair) {
- Pair p = (Pair) value;
+ Pair<?> p = (Pair<?>) value;
if (_kvar.getValue() != null) {
return _kvar.getValue() + "=" + p.get(0) + ", " + _vvar.getValue() + "=" + Tracer.unwrapHandle(p.get(1));
}
Added: branches/faster/src/org/griphyn/vdl/karajan/lib/While.java
===================================================================
--- branches/faster/src/org/griphyn/vdl/karajan/lib/While.java (rev 0)
+++ branches/faster/src/org/griphyn/vdl/karajan/lib/While.java 2013-03-11 19:58:59 UTC (rev 6370)
@@ -0,0 +1,118 @@
+//----------------------------------------------------------------------
+//This code is developed as part of the Java CoG Kit project
+//The terms of the license can be found at http://www.cogkit.org/license
+//This message may not be removed or altered.
+//----------------------------------------------------------------------
+
+/*
+ * Created on Mar 11, 2013
+ */
+package org.griphyn.vdl.karajan.lib;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import k.rt.SingleValueChannel;
+import k.rt.Stack;
+import k.thr.LWThread;
+import k.thr.Yield;
+
+import org.globus.cog.karajan.analyzer.ArgRef;
+import org.globus.cog.karajan.analyzer.ChannelRef;
+import org.globus.cog.karajan.analyzer.CompilationException;
+import org.globus.cog.karajan.analyzer.DynamicScope;
+import org.globus.cog.karajan.analyzer.Scope;
+import org.globus.cog.karajan.analyzer.Signature;
+import org.globus.cog.karajan.analyzer.Var;
+import org.globus.cog.karajan.analyzer.VarRef;
+import org.globus.cog.karajan.compiled.nodes.InternalFunction;
+import org.globus.cog.karajan.compiled.nodes.Node;
+import org.globus.cog.karajan.parser.WrapperNode;
+import org.griphyn.vdl.mapping.RootDataNode;
+import org.griphyn.vdl.type.Types;
+
+public class While extends InternalFunction {
+
+ private String name;
+ private Node body;
+ private ChannelRef.DynamicSingleValued<Object> c_next;
+
+ private VarRef<Object> var;
+
+ private ArgRef<String> _traceline;
+ private List<StaticRefCount> srefs;
+ private Tracer tracer;
+ private ArgRef<String> refs;
+
+ @Override
+ protected Signature getSignature() {
+ return new Signature(params(identifier("name"), optional("refs", null), optional("_traceline", null), block("body")));
+ }
+
+ protected Node compileBody(WrapperNode w, Scope argScope, Scope scope)
+ throws CompilationException {
+ srefs = StaticRefCount.build(scope, this.refs.getValue());
+ if (_traceline.getValue() != null) {
+ setLine(Integer.parseInt(_traceline.getValue()));
+ }
+ tracer = Tracer.getTracer(this);
+ return super.compileBody(w, argScope, scope);
+ }
+
+ @Override
+ protected void compileBlocks(WrapperNode w, Signature sig, LinkedList<WrapperNode> blocks,
+ Scope scope) throws CompilationException {
+ Var v = scope.addVar(name);
+ var = scope.getVarRef(v);
+ Var.Channel next = scope.addChannel("next");
+ c_next = new ChannelRef.DynamicSingleValued<Object>("next", next.getIndex());
+ DynamicScope ds = new DynamicScope(w, scope);
+ super.compileBlocks(w, sig, blocks, ds);
+ ds.close();
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public void runBody(LWThread thr) {
+ if (body == null) {
+ return;
+ }
+ int i = thr.checkSliceAndPopState();
+ SingleValueChannel<Object> next = (SingleValueChannel<Object>) thr.popState();
+ List<RefCount> drefs = (List<RefCount>) thr.popState();
+ Stack stack = thr.getStack();
+ try {
+ switch(i) {
+ case 0:
+ drefs = RefCount.build(stack, srefs);
+ var.setValue(stack, new RootDataNode(Types.INT, 0));
+ c_next.create(stack);
+ RefCount.incRefs(drefs);
+ next = (SingleValueChannel<Object>) c_next.get(stack);
+ if (tracer.isEnabled()) {
+ tracer.trace(thr, unwrap(next));
+ }
+ i++;
+ case 1:
+ while (true) {
+ body.run(thr);
+ if (next.isEmpty()) {
+ RefCount.decRefs(drefs);
+ break;
+ }
+ Object val = next.removeFirst();
+ if (tracer.isEnabled()) {
+ tracer.trace(thr, unwrap(next));
+ }
+ var.setValue(stack, val);
+ }
+ }
+ }
+ catch (Yield y) {
+ y.getState().push(drefs);
+ y.getState().push(next);
+ y.getState().push(i);
+ throw y;
+ }
+ }
+}
More information about the Swift-commit
mailing list