Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Oneflow-Inc/oneflow into …
Browse files Browse the repository at this point in the history
…add_check_of_placement_constructor
  • Loading branch information
clackhan committed Dec 14, 2021
2 parents c432c52 + 08d63df commit 9430475
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 180 deletions.
2 changes: 0 additions & 2 deletions ci/test/1node_op_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,3 @@ then
else
echo "deadlock unsolved, skipping multi-card eager"
fi

ONEFLOW_TEST_MULTI_PROCESS=1 python3 test/ops/test_multi_process.py --failfast --verbose
3 changes: 3 additions & 0 deletions cmake/oneflow.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,9 @@ if(BUILD_PYTHON)
target_include_directories(oneflow_internal PRIVATE ${Python_INCLUDE_DIRS} ${Python_NumPy_INCLUDE_DIRS})

target_compile_definitions(oneflow_internal PRIVATE ONEFLOW_CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE})
if(WITH_MLIR)
add_dependencies(check-oneflow oneflow_internal)
endif(WITH_MLIR)

set(gen_pip_args "")
if (BUILD_CUDA)
Expand Down
23 changes: 6 additions & 17 deletions oneflow/ir/include/OneFlow/OneFlowBase.td
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,18 @@

include "OneFlow/OneFlowDialect.td"
include "OneFlow/OneFlowInterfaces.td"

include "mlir/IR/SymbolInterfaces.td"
include "mlir/Interfaces/SideEffectInterfaces.td"

def SI32ArrayAttr : TypedArrayAttrBase<SI32Attr,
"signed 32-bit integer array attribute"> {
let constBuilderCall = "$_builder.getArrayAttr(llvm::to_vector<8>(llvm::map_range(values, [this](int32_t v) -> Attribute { return builder_.getSI32IntegerAttr($0); })))";
}
def SI32ArrayAttr : TypedArrayAttrBase<SI32Attr, "signed 32-bit integer array attribute"> {}

def SI64ArrayAttr : TypedArrayAttrBase<SI64Attr,
"signed 64-bit integer array attribute"> {
let constBuilderCall = "$_builder.getArrayAttr(llvm::to_vector<8>(llvm::map_range(values, [this](int64_t v) -> Attribute { return builder_.getSI64IntegerAttr($0); })))";
}
def SI64ArrayAttr : TypedArrayAttrBase<SI64Attr, "signed 64-bit integer array attribute"> {}

def DTArrayAttr : TypedArrayAttrBase<OneFlow_DataType,
"signed 64-bit integer array attribute"> {
let constBuilderCall = "$_builder.getArrayAttr(llvm::to_vector<8>(llvm::map_range(values, [this](auto v) -> Attribute { return DataTypeAttr::get($0); })))";
}
def ShapeAttr : TypedArrayAttrBase<SI64Attr, ""> {}

def ShapeArrayAttr : TypedArrayAttrBase<AnyI64ElementsAttr,
""> {
let constBuilderCall = "$_builder.getArrayAttr(llvm::to_vector<8>(llvm::map_range(values, [this](auto v) -> Attribute { return DenseIntElementsAttr::get($0); })))";
}
def DTArrayAttr : TypedArrayAttrBase<OneFlow_DataType, ""> {}

def ShapeArrayAttr : TypedArrayAttrBase<ShapeAttr, ""> {}

def OneFlow_IsOpConfCompatible : NativeOpTrait<"IsOpConfCompatible">;
def OneFlow_IsImportCompatible : NativeOpTrait<"IsImportCompatible">;
Expand Down
2 changes: 1 addition & 1 deletion oneflow/ir/include/OneFlow/OneFlowOpTraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class TensorSource : public TraitBase<ConcreteType, TensorSource> {
static StringRef getNdSbpAttrName() { return "nd_sbp"; }

static LogicalResult verifyTrait(Operation* op) {
if (!op->hasAttrOfType<DenseIntElementsAttr>(getShapeAttrName())) {
if (!op->hasAttrOfType<ArrayAttr>(getShapeAttrName())) {
return op->emitError("expected operation to have attribute: " + getShapeAttrName());
}
if (!op->hasAttrOfType<IntegerAttr>(getDataTypeAttrName())) {
Expand Down
6 changes: 3 additions & 3 deletions oneflow/ir/include/OneFlow/OneFlowOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def OneFlow_VariableOp : OneFlow_ConcreteSystemOp<"variable", [OneFlow_TensorSou
let input = (ins);
let output = (outs AnyType:$output);
let custom_attrs = (ins
AnyI64ElementsAttr:$shape,
ShapeAttr:$shape,
OptionalAttr<OneFlow_DataType>:$data_type,
DefaultValuedAttr<StrAttr, "\"weight\"">:$model_name,
DefaultValuedAttr<F32Attr, "0.0f">:$l1_regularization,
Expand All @@ -131,7 +131,7 @@ def OneFlow_InputOp : OneFlow_ConcreteSystemOp<"input", [OneFlow_TensorSource]>
let input = (ins AnyType:$input);
let output = (outs AnyType:$output);
let custom_attrs = (ins
OptionalAttr<AnyI64ElementsAttr>:$shape,
OptionalAttr<ShapeAttr>:$shape,
OptionalAttr<OneFlow_DataType>:$data_type,
OptionalAttr<BoolAttr>:$is_dynamic,
OptionalAttr<StrArrayAttr>:$nd_sbp,
Expand All @@ -149,7 +149,7 @@ def OneFlow_OutputOp : OneFlow_ConcreteSystemOp<"output", [OneFlow_TensorSource]
let input = (ins AnyType:$input);
let output = (outs AnyType:$output);
let custom_attrs = (ins
OptionalAttr<AnyI64ElementsAttr>:$shape,
OptionalAttr<ShapeAttr>:$shape,
OptionalAttr<OneFlow_DataType>:$data_type,
OptionalAttr<BoolAttr>:$is_dynamic,
OptionalAttr<StrArrayAttr>:$nd_sbp,
Expand Down
2 changes: 1 addition & 1 deletion oneflow/ir/oneflow-gen-ods/oneflow-gen-ods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ std::string GetMLIRAttrTypeName(const AttrType& attr_type) {
} else if (attr_type == ::oneflow::kAtString) {
return "StrAttr";
} else if (attr_type == ::oneflow::kAtShape) {
return "AnyI64ElementsAttr";
return "ShapeAttr";
} else if (attr_type == ::oneflow::kAtDataType) {
return "OneFlow_DataType";
} else if (attr_type == ::oneflow::kAtListInt32) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class Importer {
return GetBuilder().getArrayAttr(attrs);
}

DenseIntElementsAttr DenseIntElementsAttrFromShape(const ::oneflow::ShapeProto& shape);
ArrayAttr GetAttrFromShape(const ::oneflow::ShapeProto& shape);
llvm::Optional<Type> GetTypeFromOneFlowDataType(::oneflow::DataType dt);
OpBuilder& GetBuilder() { return builder_; }
MLIRContext* GetMLIRContext() { return context_; }
Expand Down
65 changes: 29 additions & 36 deletions oneflow/ir/oneflow-translate/lib/OneFlow/Importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,17 +190,14 @@ llvm::Optional<mlir::oneflow::DataTypeAttr> GetDataTypeAttr(MLIRContext* context
}
}

DenseIntElementsAttr Importer::DenseIntElementsAttrFromShape(const ::oneflow::ShapeProto& shape) {
ArrayRef<int64_t> values = {shape.dim().begin(), shape.dim().end()};
RankedTensorType tt = RankedTensorType::get({static_cast<int64_t>(values.size())},
GetBuilder().getIntegerType(64, true));
;
return DenseIntElementsAttr::get(tt, values);
ArrayAttr Importer::GetAttrFromShape(const ::oneflow::ShapeProto& shape) {
return GetBuilder().getArrayAttr(llvm::to_vector<8>(llvm::map_range(
shape.dim(), [this](int64_t v) -> Attribute { return getSI64IntegerAttr(v); })));
}

void WriteDenseIntElementsToShape(mlir::Attribute& attr, ::oneflow::ShapeProto* shape) {
for (auto int_v : attr.dyn_cast<DenseIntElementsAttr>().getValues<int64_t>()) {
shape->add_dim(int_v);
void WriteAttrToShape(mlir::Attribute& attr, ::oneflow::ShapeProto* shape) {
for (auto v : attr.dyn_cast<ArrayAttr>().getValue()) {
shape->add_dim(v.dyn_cast<IntegerAttr>().getSInt());
}
}

Expand Down Expand Up @@ -235,8 +232,7 @@ LogicalResult Importer::namedAttributesFromUserOp(const ::oneflow::OperatorConf&
DEFINE_ONE_ELIF(at_string, getStringAttr)
#undef DEFINE_ONE_ELIF
else if (value.has_at_shape()) {
attr_vec.emplace_back(
GetBuilder().getNamedAttr(name, DenseIntElementsAttrFromShape(value.at_shape())));
attr_vec.emplace_back(GetBuilder().getNamedAttr(name, GetAttrFromShape(value.at_shape())));
}
#define DEFINE_ONE_ELIF(at_key, get_attr, field) \
else if (value.has_##at_key()) { \
Expand Down Expand Up @@ -276,9 +272,9 @@ LogicalResult Importer::namedAttributesFromUserOp(const ::oneflow::OperatorConf&
name, GetBuilder().getArrayAttr(llvm::to_vector<8>(dt_attr_list))));
}
else if (value.has_at_list_shape()) {
auto dense_attr_list = llvm::map_range(
value.at_list_shape().val(),
[&](const ::oneflow::ShapeProto& s) { return DenseIntElementsAttrFromShape(s); });
auto dense_attr_list =
llvm::map_range(value.at_list_shape().val(),
[&](const ::oneflow::ShapeProto& s) { return GetAttrFromShape(s); });
std::vector<mlir::Attribute> dense_attr_vector{dense_attr_list.begin(),
dense_attr_list.end()};
attr_vec.emplace_back(
Expand Down Expand Up @@ -738,7 +734,7 @@ LogicalResult Importer::ConvertUserOpAttributes(Operation* op,
} else if (attr_type == ::oneflow::kAtString) {
user_attr.set_at_string(attr.dyn_cast<StringAttr>().getValue().str());
} else if (attr_type == ::oneflow::kAtShape) {
WriteDenseIntElementsToShape(attr, user_attr.mutable_at_shape());
WriteAttrToShape(attr, user_attr.mutable_at_shape());
} else if (attr_type == ::oneflow::kAtDataType) {
::oneflow::DataType dt = ::oneflow::kInvalidDataType;
if (succeeded(ConvertDT(attr, dt))) {
Expand Down Expand Up @@ -777,11 +773,9 @@ LogicalResult Importer::ConvertUserOpAttributes(Operation* op,
}
}
} else if (attr_type == ::oneflow::kAtListShape) {
for (auto s : attr.dyn_cast<ArrayAttr>().getValue()) {
for (auto shape_attr : attr.dyn_cast<ArrayAttr>().getValue()) {
::oneflow::ShapeProto* shape_ptr = user_attr.mutable_at_list_shape()->add_val();
for (auto int_v : s.dyn_cast<DenseIntElementsAttr>().getValues<int64_t>()) {
shape_ptr->mutable_dim()->Add(int_v);
}
WriteAttrToShape(shape_attr, shape_ptr);
}
} else if (attr_type == ::oneflow::kAtListString) {
// attr like nd_sbp requires the existence of list even it is empty
Expand Down Expand Up @@ -823,11 +817,12 @@ LogicalResult ConvertVariableOpConf(Operation* op, oneflow::VariableOpAdaptor& a
auto* var_op_conf = op_conf->mutable_variable_conf();
var_op_conf->set_out("out");

for (const auto& elem : adaptor.shape()) {
var_op_conf->mutable_shape()->mutable_dim()->Add(elem.getSExtValue());
if (auto shape_attr =
op->getAttrOfType<ArrayAttr>(OpTrait::TensorSource<void>::getShapeAttrName())) {
WriteAttrToShape(shape_attr, var_op_conf->mutable_shape());
}

if (op->hasAttr("data_type")) {
if (op->hasAttr(OpTrait::TensorSource<void>::getDataTypeAttrName())) {
::oneflow::DataType dt = ::oneflow::DataType::kInvalidDataType;
if (failed(ConvertDT(adaptor.data_type(), dt))) { return failure(); }
var_op_conf->set_data_type(dt);
Expand Down Expand Up @@ -875,23 +870,22 @@ LogicalResult ConvertInputOpConf(Operation* op, oneflow::InputOpAdaptor& adaptor
auto* input_op_conf = op_conf->mutable_input_conf();
input_op_conf->set_out("out");

if (op->hasAttr("shape")) {
for (auto elem : adaptor.shape()) {
input_op_conf->mutable_blob_conf()->mutable_shape()->add_dim(elem.getSExtValue());
}
if (auto shape_attr =
op->getAttrOfType<ArrayAttr>(OpTrait::TensorSource<void>::getShapeAttrName())) {
WriteAttrToShape(shape_attr, input_op_conf->mutable_blob_conf()->mutable_shape());
}

if (op->hasAttr("data_type")) {
if (op->hasAttr(OpTrait::TensorSource<void>::getDataTypeAttrName())) {
::oneflow::DataType dt = ::oneflow::DataType::kInvalidDataType;
if (failed(ConvertDT(adaptor.data_type(), dt))) { return failure(); }
input_op_conf->mutable_blob_conf()->set_data_type(dt);
}

if (op->hasAttr("is_dynamic")) {
if (op->hasAttr(OpTrait::TensorSource<void>::getIsDynamicAttrName())) {
input_op_conf->mutable_blob_conf()->set_is_dynamic(adaptor.is_dynamic().getValue());
}

if (op->hasAttr("nd_sbp")) {
if (op->hasAttr(OpTrait::TensorSource<void>::getNdSbpAttrName())) {
if (failed(ParseNdSbpFromAttr(adaptor.nd_sbp(),
input_op_conf->mutable_blob_conf()->mutable_nd_sbp()))) {
return failure();
Expand Down Expand Up @@ -919,23 +913,22 @@ LogicalResult ConvertOutputOpConf(Operation* op, oneflow::OutputOpAdaptor& adapt
auto* output_op_conf = op_conf->mutable_output_conf();
output_op_conf->set_out("out");

if (op->hasAttr("shape")) {
for (auto elem : adaptor.shape()) {
output_op_conf->mutable_blob_conf()->mutable_shape()->add_dim(elem.getSExtValue());
}
if (auto shape_attr =
op->getAttrOfType<ArrayAttr>(OpTrait::TensorSource<void>::getShapeAttrName())) {
WriteAttrToShape(shape_attr, output_op_conf->mutable_blob_conf()->mutable_shape());
}

if (op->hasAttr("data_type")) {
if (op->hasAttr(OpTrait::TensorSource<void>::getDataTypeAttrName())) {
::oneflow::DataType dt = ::oneflow::DataType::kInvalidDataType;
if (failed(ConvertDT(adaptor.data_type(), dt))) { return failure(); }
output_op_conf->mutable_blob_conf()->set_data_type(dt);
}

if (op->hasAttr("is_dynamic")) {
if (op->hasAttr(OpTrait::TensorSource<void>::getIsDynamicAttrName())) {
output_op_conf->mutable_blob_conf()->set_is_dynamic(adaptor.is_dynamic().getValue());
}

if (op->hasAttr("nd_sbp")) {
if (op->hasAttr(OpTrait::TensorSource<void>::getNdSbpAttrName())) {
if (failed(ParseNdSbpFromAttr(adaptor.nd_sbp(),
output_op_conf->mutable_blob_conf()->mutable_nd_sbp()))) {
return failure();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,7 @@ LogicalResult JobImporter::ProcessVariableOp(const ::oneflow::OperatorConf& op_c
attr_vec.emplace_back(GetBuilder().getNamedAttr(
OpTrait::IsImportCompatible<void>::getOutputLBNsAttr(), output_lbns_attr));
// attr shape
auto shape_attr = GetBuilder().getI64VectorAttr(
{op_conf.variable_conf().shape().dim().begin(), op_conf.variable_conf().shape().dim().end()});
auto shape_attr = GetAttrFromShape(op_conf.variable_conf().shape());
auto shape_named_attr =
GetBuilder().getNamedAttr(OpTrait::TensorSource<void>::getShapeAttrName(), shape_attr);
attr_vec.emplace_back(shape_named_attr);
Expand Down Expand Up @@ -361,9 +360,7 @@ LogicalResult JobImporter::ProcessInputOp(const ::oneflow::OperatorConf& op_conf
OpTrait::IsImportCompatible<void>::getOutputLBNsAttr(), output_lbns_attr));
// attr shape
if (op_conf.input_conf().blob_conf().has_shape()) {
auto shape_attr =
GetBuilder().getI64VectorAttr({op_conf.input_conf().blob_conf().shape().dim().begin(),
op_conf.input_conf().blob_conf().shape().dim().end()});
auto shape_attr = GetAttrFromShape(op_conf.input_conf().blob_conf().shape());
attr_vec.emplace_back(
GetBuilder().getNamedAttr(OpTrait::TensorSource<void>::getShapeAttrName(), shape_attr));
}
Expand Down Expand Up @@ -446,9 +443,7 @@ LogicalResult JobImporter::ProcessOutputOp(const ::oneflow::OperatorConf& op_con
OpTrait::IsImportCompatible<void>::getOutputLBNsAttr(), output_lbns_attr));
// attr shape
if (op_conf.output_conf().blob_conf().has_shape()) {
auto shape_attr =
GetBuilder().getI64VectorAttr({op_conf.output_conf().blob_conf().shape().dim().begin(),
op_conf.output_conf().blob_conf().shape().dim().end()});
auto shape_attr = GetAttrFromShape(op_conf.output_conf().blob_conf().shape());
attr_vec.emplace_back(
GetBuilder().getNamedAttr(OpTrait::TensorSource<void>::getShapeAttrName(), shape_attr));
}
Expand Down
111 changes: 0 additions & 111 deletions python/oneflow/compatible/single_client/test/ops/test_multi_process.py

This file was deleted.

0 comments on commit 9430475

Please sign in to comment.