Search in sources :

Example 31 with IntObject

use of org.apache.sysml.runtime.instructions.cp.IntObject in project incubator-systemml by apache.

the class Task method parseCompactString.

public static Task parseCompactString(String stask) {
    StringTokenizer st = new StringTokenizer(stask.trim(), ".");
    TaskType type = TaskType.valueOf(st.nextToken());
    String meta = st.nextToken();
    Task newTask = new Task(meta, type);
    // iteration data
    String sdata = st.nextToken();
    // remove brackets
    sdata = sdata.substring(1, sdata.length() - 1);
    StringTokenizer st2 = new StringTokenizer(sdata, ",");
    while (st2.hasMoreTokens()) {
        // create new iteration
        String lsdata = st2.nextToken();
        IntObject ldata = new IntObject(Integer.parseInt(lsdata));
        newTask.addIteration(ldata);
    }
    return newTask;
}
Also used : StringTokenizer(java.util.StringTokenizer) IntObject(org.apache.sysml.runtime.instructions.cp.IntObject)

Example 32 with IntObject

use of org.apache.sysml.runtime.instructions.cp.IntObject in project incubator-systemml by apache.

the class Task method toCompactString.

public String toCompactString() {
    StringBuilder sb = new StringBuilder();
    sb.append(_type);
    if (size() > 0) {
        sb.append(".");
        sb.append(_iterVar);
        sb.append(".{");
        int count = 0;
        for (IntObject dat : _iterations) {
            if (count != 0)
                sb.append(",");
            sb.append(dat.getLongValue());
            count++;
        }
        sb.append("}");
    }
    return sb.toString();
}
Also used : IntObject(org.apache.sysml.runtime.instructions.cp.IntObject)

Example 33 with IntObject

use of org.apache.sysml.runtime.instructions.cp.IntObject in project incubator-systemml by apache.

the class TaskPartitionerFactoring method createTasks.

@Override
public long createTasks(LocalTaskQueue<Task> queue) {
    long numCreatedTasks = 0;
    long lFrom = _fromVal.getLongValue();
    long lTo = _toVal.getLongValue();
    long lIncr = _incrVal.getLongValue();
    // number of parallel workers
    int P = _numThreads;
    // total number of iterations
    long N = _numIter;
    // remaining number of iterations
    long R = N;
    // next _numThreads task sizes
    long K = -1;
    // type of iterations: range tasks (similar to run-length encoding) make only sense if taskSize>3
    TaskType type = null;
    try {
        for (long i = lFrom; i <= lTo; ) {
            K = determineNextBatchSize(R, P);
            R -= (K * P);
            type = (ParForProgramBlock.USE_RANGE_TASKS_IF_USEFUL && K > 3) ? TaskType.RANGE : TaskType.SET;
            // for each logical processor
            for (int j = 0; j < P; j++) {
                if (// no more iterations
                i > lTo)
                    break;
                // create new task and add to list of tasks
                Task lTask = new Task(_iterVarName, type);
                // add iterations to task
                if (type == TaskType.SET) {
                    // value based tasks
                    for (long k = 0; k < K && i <= lTo; k++, i += lIncr) lTask.addIteration(new IntObject(i));
                } else {
                    // determine end of task
                    long to = Math.min(i + (K - 1) * lIncr, lTo);
                    // range based tasks
                    // from
                    lTask.addIteration(new IntObject(i));
                    // to
                    lTask.addIteration(new IntObject(to));
                    // increment
                    lTask.addIteration(new IntObject(lIncr));
                    i = to + lIncr;
                }
                // add task to queue (after all iteration added for preventing raise conditions)
                queue.enqueueTask(lTask);
                numCreatedTasks++;
            }
        }
        // mark end of task input stream
        queue.closeInput();
    } catch (Exception ex) {
        throw new DMLRuntimeException(ex);
    }
    return numCreatedTasks;
}
Also used : IntObject(org.apache.sysml.runtime.instructions.cp.IntObject) TaskType(org.apache.sysml.runtime.controlprogram.parfor.Task.TaskType) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 34 with IntObject

use of org.apache.sysml.runtime.instructions.cp.IntObject in project incubator-systemml by apache.

the class TaskPartitionerFactoring method createTasks.

@Override
public List<Task> createTasks() {
    LinkedList<Task> tasks = new LinkedList<>();
    long lFrom = _fromVal.getLongValue();
    long lTo = _toVal.getLongValue();
    long lIncr = _incrVal.getLongValue();
    // number of parallel workers
    int P = _numThreads;
    // total number of iterations
    long N = _numIter;
    // remaining number of iterations
    long R = N;
    // next _numThreads task sizes
    long K = -1;
    // type of iterations: range tasks (similar to run-length encoding) make only sense if taskSize>3
    TaskType type = null;
    for (long i = lFrom; i <= lTo; ) {
        K = determineNextBatchSize(R, P);
        R -= (K * P);
        type = (ParForProgramBlock.USE_RANGE_TASKS_IF_USEFUL && K > 3) ? TaskType.RANGE : TaskType.SET;
        // for each logical processor
        for (int j = 0; j < P; j++) {
            if (// no more iterations
            i > lTo)
                break;
            // create new task and add to list of tasks
            Task lTask = new Task(_iterVarName, type);
            tasks.addLast(lTask);
            // add iterations to task
            if (type == TaskType.SET) {
                // value based tasks
                for (long k = 0; k < K && i <= lTo; k++, i += lIncr) lTask.addIteration(new IntObject(i));
            } else {
                // determine end of task
                long to = Math.min(i + (K - 1) * lIncr, lTo);
                // range based tasks
                // from
                lTask.addIteration(new IntObject(i));
                // to
                lTask.addIteration(new IntObject(to));
                // increment
                lTask.addIteration(new IntObject(lIncr));
                i = to + lIncr;
            }
        }
    }
    return tasks;
}
Also used : IntObject(org.apache.sysml.runtime.instructions.cp.IntObject) TaskType(org.apache.sysml.runtime.controlprogram.parfor.Task.TaskType) LinkedList(java.util.LinkedList)

Example 35 with IntObject

use of org.apache.sysml.runtime.instructions.cp.IntObject in project incubator-systemml by apache.

the class TaskPartitionerFixedsize method createTasks.

@Override
public List<Task> createTasks() {
    LinkedList<Task> tasks = new LinkedList<>();
    // range tasks (similar to run-length encoding) make only sense if taskSize>3
    TaskType type = (ParForProgramBlock.USE_RANGE_TASKS_IF_USEFUL && _taskSize > 3) ? TaskType.RANGE : TaskType.SET;
    long lFrom = _fromVal.getLongValue();
    long lTo = _toVal.getLongValue();
    long lIncr = _incrVal.getLongValue();
    long lfnp1 = _firstnPlus1;
    for (long i = lFrom; i <= lTo; ) {
        // create new task and add to list of tasks
        Task lTask = new Task(_iterVarName, type);
        tasks.addLast(lTask);
        // correction for static partitioner
        int corr = (lfnp1-- > 0) ? 1 : 0;
        // (last task might have less)
        if (type == TaskType.SET) {
            // value based tasks
            for (long j = 0; j < _taskSize + corr && i <= lTo; j++, i += lIncr) lTask.addIteration(new IntObject(i));
        } else {
            // determine end of task
            long to = Math.min(i + (_taskSize - 1 + corr) * lIncr, lTo);
            // range based tasks
            // from
            lTask.addIteration(new IntObject(i));
            // to
            lTask.addIteration(new IntObject(to));
            // increment
            lTask.addIteration(new IntObject(lIncr));
            i = to + lIncr;
        }
    }
    return tasks;
}
Also used : IntObject(org.apache.sysml.runtime.instructions.cp.IntObject) TaskType(org.apache.sysml.runtime.controlprogram.parfor.Task.TaskType) LinkedList(java.util.LinkedList)

Aggregations

IntObject (org.apache.sysml.runtime.instructions.cp.IntObject)47 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)19 MatrixObject (org.apache.sysml.runtime.controlprogram.caching.MatrixObject)15 BooleanObject (org.apache.sysml.runtime.instructions.cp.BooleanObject)11 DoubleObject (org.apache.sysml.runtime.instructions.cp.DoubleObject)11 ScalarObject (org.apache.sysml.runtime.instructions.cp.ScalarObject)11 StringObject (org.apache.sysml.runtime.instructions.cp.StringObject)11 TaskType (org.apache.sysml.runtime.controlprogram.parfor.Task.TaskType)8 Timing (org.apache.sysml.runtime.controlprogram.parfor.stat.Timing)6 Data (org.apache.sysml.runtime.instructions.cp.Data)6 StringTokenizer (java.util.StringTokenizer)5 IOException (java.io.IOException)4 LinkedList (java.util.LinkedList)4 DataType (org.apache.sysml.parser.Expression.DataType)4 ValueType (org.apache.sysml.parser.Expression.ValueType)4 DMLScriptException (org.apache.sysml.runtime.DMLScriptException)4 ProgramBlock (org.apache.sysml.runtime.controlprogram.ProgramBlock)4 UpdateType (org.apache.sysml.runtime.controlprogram.caching.MatrixObject.UpdateType)4 MatrixCharacteristics (org.apache.sysml.runtime.matrix.MatrixCharacteristics)4 MetaDataFormat (org.apache.sysml.runtime.matrix.MetaDataFormat)4