|
|
@ -446,51 +446,8 @@ StrategyRec CostPooling::ChoseStr(const std::vector<double> &cost_op, StrategyRe
|
|
|
|
return str;
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Get optimal strategy for Add
|
|
|
|
|
|
|
|
StrategyRec CostAdd::GetOptimalStr(const Graph::NodeType &node,
|
|
|
|
|
|
|
|
const std::vector<std::pair<std::string, StrategyRec>> &node_name_to_strategy,
|
|
|
|
|
|
|
|
const Graph &graph) {
|
|
|
|
|
|
|
|
int tensor_n = static_cast<int>(node.tensor_parm.tensor_shape.shape_n * node.tensor_parm.tensor_str.str_n);
|
|
|
|
|
|
|
|
int tensor_c = static_cast<int>(node.tensor_parm.tensor_shape.shape_c * node.tensor_parm.tensor_str.str_c);
|
|
|
|
|
|
|
|
int tensor_h = static_cast<int>(node.tensor_parm.tensor_shape.shape_h * node.tensor_parm.tensor_str.str_h);
|
|
|
|
|
|
|
|
int tensor_w = static_cast<int>(node.tensor_parm.tensor_shape.shape_w * node.tensor_parm.tensor_str.str_w);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<double> cost_op;
|
|
|
|
|
|
|
|
std::vector<std::vector<float>> mode;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (tensor_n < 2) {
|
|
|
|
|
|
|
|
cost_op.push_back(DOUBLE_MAX);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
cost_op.push_back(cost_in_ + CostRedis(node, node_name_to_strategy,
|
|
|
|
|
|
|
|
mode = {{0.5, 1, 1, 1}, {0.5, 1, 1, 1}, {0.5, 1, 1, 1}}, graph));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (tensor_c < 2) {
|
|
|
|
|
|
|
|
cost_op.push_back(DOUBLE_MAX);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
cost_op.push_back(cost_in_ + CostRedis(node, node_name_to_strategy,
|
|
|
|
|
|
|
|
mode = {{1, 0.5, 1, 1}, {1, 0.5, 1, 1}, {1, 0.5, 1, 1}}, graph));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (tensor_h < 2) {
|
|
|
|
|
|
|
|
cost_op.push_back(DOUBLE_MAX);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
cost_op.push_back(cost_in_ + CostRedis(node, node_name_to_strategy,
|
|
|
|
|
|
|
|
mode = {{1, 1, 0.5, 1}, {1, 1, 0.5, 1}, {1, 1, 0.5, 1}}, graph));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (tensor_w < 2) {
|
|
|
|
|
|
|
|
cost_op.push_back(DOUBLE_MAX);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
cost_op.push_back(cost_in_ + CostRedis(node, node_name_to_strategy,
|
|
|
|
|
|
|
|
mode = {{1, 1, 1, 0.5}, {1, 1, 1, 0.5}, {1, 1, 1, 0.5}}, graph));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ChoseStr(cost_op, node.apply.str);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Chose strategy for Add
|
|
|
|
// Chose strategy for Add
|
|
|
|
StrategyRec CostAdd::ChoseStr(const std::vector<double> &cost_op, StrategyRec str) {
|
|
|
|
StrategyRec CostTensorAdd::ChoseStr(const std::vector<double> &cost_op, StrategyRec str) {
|
|
|
|
uint64_t min_position = min_element(cost_op.begin(), cost_op.end()) - cost_op.begin();
|
|
|
|
uint64_t min_position = min_element(cost_op.begin(), cost_op.end()) - cost_op.begin();
|
|
|
|
if (cost_op[min_position] > (DOUBLE_MAX - 0.1)) {
|
|
|
|
if (cost_op[min_position] > (DOUBLE_MAX - 0.1)) {
|
|
|
|
return str;
|
|
|
|
return str;
|
|
|
@ -540,49 +497,6 @@ StrategyRec CostReshape::GetOptimalStr(const Graph::NodeType &node) const { retu
|
|
|
|
|
|
|
|
|
|
|
|
StrategyRec CostReshape::ChoseStr(StrategyRec str) const { return str; }
|
|
|
|
StrategyRec CostReshape::ChoseStr(StrategyRec str) const { return str; }
|
|
|
|
|
|
|
|
|
|
|
|
// Get optimal strategy for Biasadd
|
|
|
|
|
|
|
|
StrategyRec CostBiasAdd::GetOptimalStr(const Graph::NodeType &node,
|
|
|
|
|
|
|
|
const std::vector<std::pair<std::string, StrategyRec>> &node_name_to_strategy,
|
|
|
|
|
|
|
|
const Graph &graph) {
|
|
|
|
|
|
|
|
int tensor_n = static_cast<int>(node.tensor_parm.tensor_shape.shape_n * node.tensor_parm.tensor_str.str_n);
|
|
|
|
|
|
|
|
int tensor_c = static_cast<int>(node.tensor_parm.tensor_shape.shape_c * node.tensor_parm.tensor_str.str_c);
|
|
|
|
|
|
|
|
int tensor_h = static_cast<int>(node.tensor_parm.tensor_shape.shape_h * node.tensor_parm.tensor_str.str_h);
|
|
|
|
|
|
|
|
int tensor_w = static_cast<int>(node.tensor_parm.tensor_shape.shape_w * node.tensor_parm.tensor_str.str_w);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<double> cost_op;
|
|
|
|
|
|
|
|
std::vector<std::vector<float>> mode;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (tensor_n < 2) {
|
|
|
|
|
|
|
|
cost_op.push_back(DOUBLE_MAX);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
cost_op.push_back(cost_in_ + CostRedis(node, node_name_to_strategy,
|
|
|
|
|
|
|
|
mode = {{0.5, 1, 1, 1}, {0.5, 1, 1, 1}, {0.5, 1, 1, 1}}, graph));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (tensor_c < 2) {
|
|
|
|
|
|
|
|
cost_op.push_back(DOUBLE_MAX);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
cost_op.push_back(cost_in_ + CostRedis(node, node_name_to_strategy,
|
|
|
|
|
|
|
|
mode = {{1, 0.5, 1, 1}, {1, 0.5, 1, 1}, {1, 0.5, 1, 1}}, graph));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (tensor_h < 2) {
|
|
|
|
|
|
|
|
cost_op.push_back(DOUBLE_MAX);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
cost_op.push_back(cost_in_ + CostRedis(node, node_name_to_strategy,
|
|
|
|
|
|
|
|
mode = {{1, 1, 0.5, 1}, {1, 1, 0.5, 1}, {1, 1, 0.5, 1}}, graph));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (tensor_w < 2) {
|
|
|
|
|
|
|
|
cost_op.push_back(DOUBLE_MAX);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
cost_op.push_back(cost_in_ + CostRedis(node, node_name_to_strategy,
|
|
|
|
|
|
|
|
mode = {{1, 1, 1, 0.5}, {1, 1, 1, 0.5}, {1, 1, 1, 0.5}}, graph));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ChoseStr(cost_op, node.apply.str);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Chose strategy for BiasAdd
|
|
|
|
// Chose strategy for BiasAdd
|
|
|
|
StrategyRec CostBiasAdd::ChoseStr(const std::vector<double> &cost_op, StrategyRec str) {
|
|
|
|
StrategyRec CostBiasAdd::ChoseStr(const std::vector<double> &cost_op, StrategyRec str) {
|
|
|
|
uint64_t min_position = min_element(cost_op.begin(), cost_op.end()) - cost_op.begin();
|
|
|
|
uint64_t min_position = min_element(cost_op.begin(), cost_op.end()) - cost_op.begin();
|
|
|
@ -629,7 +543,7 @@ StrategyRec CostBiasAdd::ChoseStr(const std::vector<double> &cost_op, StrategyRe
|
|
|
|
return str;
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Get optimal strategy for Common OPs: ReLU and Softmax
|
|
|
|
// Get optimal strategy for Common OPs
|
|
|
|
StrategyRec CostCommon::GetOptimalStr(const Graph::NodeType &node,
|
|
|
|
StrategyRec CostCommon::GetOptimalStr(const Graph::NodeType &node,
|
|
|
|
const std::vector<std::pair<std::string, StrategyRec>> &node_name_to_strategy,
|
|
|
|
const std::vector<std::pair<std::string, StrategyRec>> &node_name_to_strategy,
|
|
|
|
const Graph &graph) {
|
|
|
|
const Graph &graph) {
|
|
|
|