use of org.nd4j.linalg.api.ops.grid.OpDescriptor in project nd4j by deeplearning4j.
the class CudaGridExecutioner method processAsGridOp.
protected void processAsGridOp(Op op, int... dimension) {
/*
We have multiple options here:
1) Op has no relation to lastOp
2) Op has SOME relation to lastOp
3) Op is supposed to blocking
So we either should append this op to future GridOp, form MetaOp, or immediately execute everything
But we don't expect this method called for blocking ops ever, so it's either
*/
// CudaContext context = AtomicAllocator.getInstance().getFlowController().prepareAction(op.z(), op.x(), op.y());
OpDescriptor last = lastOp.get();
if (last != null) {
MetaType type = getMetaOpType(op, dimension);
lastOp.remove();
switch(type) {
case NOT_APPLICABLE:
{
/*
If we can't form MetaOp with new Op here, we should move lastOp to GridOp queue, and update lastOp with current Op
*/
dequeueOp(last);
pushToGrid(last, false);
// || op instanceof ScalarOp
if ((op instanceof TransformOp && op.y() != null) && onCurrentDeviceXYZ(op)) {
enqueueOp(new OpDescriptor(op, dimension));
} else {
pushToGrid(new OpDescriptor(op, dimension), false);
}
}
break;
case PREDICATE:
{
MetaOp metaOp = new PredicateMetaOp(last, new OpDescriptor(op, dimension));
pushToGrid(new OpDescriptor(metaOp), false);
}
break;
case INVERTED_PREDICATE:
{
OpDescriptor currentOp = new OpDescriptor(op, dimension);
// logger.info("Calling for Meta: {}+{}", last.getOp().getClass().getSimpleName(), currentOp.getOp().getClass().getSimpleName());
dequeueOp(last);
dequeueOp(currentOp);
MetaOp metaOp = new InvertedPredicateMetaOp(last, currentOp);
pushToGrid(new OpDescriptor(metaOp), false);
}
break;
case POSTULATE:
{
MetaOp metaOp = new PostulateMetaOp(last, new OpDescriptor(op, dimension));
pushToGrid(new OpDescriptor(metaOp), false);
}
break;
default:
throw new UnsupportedOperationException("Not supported MetaType: [" + type + "]");
}
} else {
// && Nd4j.dataType() != DataBuffer.Type.HALF
if ((op instanceof TransformOp && op.y() != null && onCurrentDeviceXYZ(op))) {
enqueueOp(new OpDescriptor(op, dimension));
} else {
pushToGrid(new OpDescriptor(op, dimension), false);
}
}
// AtomicAllocator.getInstance().getFlowController().registerAction(context, op.z(), op.x(), op.y());
// return op;
}
use of org.nd4j.linalg.api.ops.grid.OpDescriptor in project nd4j by deeplearning4j.
the class CudaGridExecutioner method flushQueue.
/**
* This method forces all currently enqueued ops to be executed immediately
*
* PLEASE NOTE: This call IS non-blocking
*/
public void flushQueue() {
/*
Basically we just want to form GridOp and pass it to native executioner
But since we don't have GridOp interface yet, we'll send everything to underlying CudaExecutioner.
*/
// logger.info("Non-Blocking flush");
// TODO: proper implementation for GridOp creation required here
/*
Deque<OpDescriptor> currentQueue = deviceQueues.get();
if (currentQueue == null)
return;
OpDescriptor op = currentQueue.pollFirst();
while (op != null) {
pushToGrid(op, false);
op = currentQueue.pollFirst();
}
*/
// we need to check,
OpDescriptor op = lastOp.get();
if (op != null) {
if (!experimental.get()) {
// if (!nativeOps.isExperimentalEnabled()) {
// it might be only pairwise transform here for now
// logger.info("Flushing existing lastOp");
lastOp.remove();
dequeueOp(op);
pushToGrid(op, false);
} else {
throw new UnsupportedOperationException("Experimental flush isn't supported yet");
}
} else {
// logger.info("Queue is empty");
}
}
use of org.nd4j.linalg.api.ops.grid.OpDescriptor in project nd4j by deeplearning4j.
the class MetaOpTests method testPredicateReduce1.
/**
* Scalar + reduce along dimension
*
* @throws Exception
*/
@Test
public void testPredicateReduce1() throws Exception {
CudaGridExecutioner executioner = new CudaGridExecutioner();
INDArray arrayX = Nd4j.create(5, 5);
INDArray exp = Nd4j.create(new float[] { 2f, 2f, 2f, 2f, 2f });
ScalarAdd opA = new ScalarAdd(arrayX, 2.0f);
Max opB = new Max(arrayX);
OpDescriptor a = new OpDescriptor(opA);
OpDescriptor b = new OpDescriptor(opB, new int[] { 1 });
executioner.buildZ(opB, b.getDimensions());
ReduceMetaOp metaOp = new ReduceMetaOp(a, b);
executioner.prepareGrid(metaOp);
executioner.exec(metaOp);
INDArray result = opB.z();
assertNotEquals(null, result);
assertEquals(exp, result);
}
Aggregations