Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ private ArrayList<StatementBlock> rewriteDefaultStatementBlock(DMLProgram prog,
selectFederatedExecutionPlan(sbHop, paramMap);
if(sbHop instanceof FunctionOp) {
String funcName = ((FunctionOp) sbHop).getFunctionName();
Map<String, Hop> funcParamMap = getParamMap((FunctionOp) sbHop);
Map<String, Hop> funcParamMap = FederatedPlannerUtils.getParamMap((FunctionOp) sbHop);
if ( paramMap != null && funcParamMap != null)
funcParamMap.putAll(paramMap);
paramMap = funcParamMap;
Expand All @@ -182,22 +182,6 @@ private ArrayList<StatementBlock> rewriteDefaultStatementBlock(DMLProgram prog,
return new ArrayList<>(Collections.singletonList(sb));
}

/**
* Return parameter map containing the mapping from parameter name to input hop
* for all parameters of the function hop.
* @param funcOp hop for which the mapping of parameter names to input hops are made
* @return parameter map or empty map if function has no parameters
*/
private Map<String,Hop> getParamMap(FunctionOp funcOp){
String[] inputNames = funcOp.getInputVariableNames();
Map<String,Hop> paramMap = new HashMap<>();
if ( inputNames != null ){
for ( int i = 0; i < funcOp.getInput().size(); i++ )
paramMap.put(inputNames[i],funcOp.getInput(i));
}
return paramMap;
}

/**
* Set final fedouts of all hops starting from terminal hops.
*/
Expand Down Expand Up @@ -327,13 +311,21 @@ private void visitFedPlanHop(Hop currentHop, Map<String, Hop> paramMap) {
ArrayList<HopRel> hopRels = getFedPlans(currentHop, paramMap);
// Put NONE HopRel into memo table if no FOUT or LOUT HopRels were added
if(hopRels.isEmpty())
hopRels.add(getNONEHopRel(currentHop));
hopRels.add(getNONEHopRel(currentHop, paramMap));
addTrace(hopRels);
hopRelMemo.put(currentHop, hopRels);
}

private HopRel getNONEHopRel(Hop currentHop){
HopRel noneHopRel = new HopRel(currentHop, FederatedOutput.NONE, hopRelMemo);
private ArrayList<Hop> getHopInputs(Hop currentHop, Map<String, Hop> paramMap){
if ( HopRewriteUtils.isData(currentHop, Types.OpOpData.TRANSIENTREAD) )
return FederatedPlannerUtils.getTransientInputs(currentHop, paramMap, transientWrites);
else
return currentHop.getInput();
}

private HopRel getNONEHopRel(Hop currentHop, Map<String, Hop> paramMap){
ArrayList<Hop> inputs = getHopInputs(currentHop, paramMap);
HopRel noneHopRel = new HopRel(currentHop, FederatedOutput.NONE, hopRelMemo, inputs);
FType[] inputFType = noneHopRel.getInputDependency().stream().map(HopRel::getFType).toArray(FType[]::new);
FType outputFType = getFederatedOut(currentHop, inputFType);
noneHopRel.setFType(outputFType);
Expand All @@ -348,9 +340,7 @@ private HopRel getNONEHopRel(Hop currentHop){
*/
private ArrayList<HopRel> getFedPlans(Hop currentHop, Map<String, Hop> paramMap){
ArrayList<HopRel> hopRels = new ArrayList<>();
ArrayList<Hop> inputHops = currentHop.getInput();
if ( HopRewriteUtils.isData(currentHop, Types.OpOpData.TRANSIENTREAD) )
inputHops = getTransientInputs(currentHop, paramMap);
ArrayList<Hop> inputHops = getHopInputs(currentHop, paramMap);
if ( HopRewriteUtils.isData(currentHop, Types.OpOpData.TRANSIENTWRITE) )
transientWrites.put(currentHop.getName(), currentHop);
if ( HopRewriteUtils.isData(currentHop, Types.OpOpData.FEDERATED) )
Expand Down Expand Up @@ -453,6 +443,8 @@ private void updateExplain(){
private void debugLog(Hop currentHop){
if ( LOG.isDebugEnabled() ){
LOG.debug("Visiting HOP: " + currentHop + " Input size: " + currentHop.getInput().size());
if (currentHop.getPrivacy() != null)
LOG.debug(currentHop.getPrivacy());
int index = 0;
for ( Hop hop : currentHop.getInput()){
if ( hop == null )
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.sysds.hops.fedplanner;

import org.apache.sysds.hops.FunctionOp;
import org.apache.sysds.hops.Hop;
import org.apache.sysds.runtime.DMLRuntimeException;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public class FederatedPlannerUtils {
/**
* Get transient inputs from either paramMap or transientWrites.
* Inputs from paramMap has higher priority than inputs from transientWrites.
* @param currentHop hop for which inputs are read from maps
* @param paramMap of local parameters
* @param transientWrites map of transient writes
* @return inputs of currentHop
*/
public static ArrayList<Hop> getTransientInputs(Hop currentHop, Map<String, Hop> paramMap, Map<String,Hop> transientWrites){
Hop tWriteHop = null;
if ( paramMap != null)
tWriteHop = paramMap.get(currentHop.getName());
if ( tWriteHop == null )
tWriteHop = transientWrites.get(currentHop.getName());
if ( tWriteHop == null )
throw new DMLRuntimeException("Transient write not found for " + currentHop);
else
return new ArrayList<>(Collections.singletonList(tWriteHop));
}

/**
* Return parameter map containing the mapping from parameter name to input hop
* for all parameters of the function hop.
* @param funcOp hop for which the mapping of parameter names to input hops are made
* @return parameter map or empty map if function has no parameters
*/
public static Map<String,Hop> getParamMap(FunctionOp funcOp){
String[] inputNames = funcOp.getInputVariableNames();
Map<String,Hop> paramMap = new HashMap<>();
if ( inputNames != null ){
for ( int i = 0; i < funcOp.getInput().size(); i++ )
paramMap.put(inputNames[i],funcOp.getInput(i));
}
return paramMap;
}
}
Loading