Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support static graph code-gen for scalar and int_array #48792

Merged
merged 6 commits into from
Dec 9, 2022
Merged
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
320 changes: 0 additions & 320 deletions paddle/fluid/operators/crop_tensor_op.cc

This file was deleted.

17 changes: 11 additions & 6 deletions paddle/fluid/operators/generator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,23 @@ execute_process(
--op_compat_yaml_path ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/op_compat.yaml
--output_op_path "${generated_op_path}.tmp" --output_arg_map_path
"${generated_argument_mapping_path}.tmp"
RESULT_VARIABLE _result)
if(${_result})
message(FATAL_ERROR "operator codegen failed, exiting.")
endif()

execute_process(
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/paddle/fluid/operators/generator
COMMAND
${PYTHON_EXECUTABLE} generate_sparse_op.py --ops_yaml_path
./parsed_ops/sparse_ops.parsed.yaml --backward_ops_yaml_path
./parsed_ops/sparse_backward.parsed.yaml --output_op_path
"${generated_sparse_ops_path}.tmp" --output_arg_map_path
"${generated_sparse_argument_mapping_path}.tmp"
RESULT_VARIABLE _results)
foreach(_result in ${_results})
if(${_result})
message(FATAL_ERROR "operator codegen failed, exiting.")
endif()
endforeach()
RESULT_VARIABLE _result)
if(${_result})
message(FATAL_ERROR "sparse operator codegen failed, exiting.")
endif()

if(EXISTS "${generated_op_path}.tmp" AND EXISTS "${generated_op_path}")
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different
Expand Down
35 changes: 31 additions & 4 deletions paddle/fluid/operators/generator/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,44 @@ def to_input_name(s):
return match.group(2)


def to_scalar_tensor_name(attr):
if 'tensor_name' in attr:
return attr['tensor_name']
return to_pascal_case(attr['name']) + 'Tensor'


def to_int_array_tensor_name(attr):
if 'tensor_name' in attr:
return attr['tensor_name']
return to_pascal_case(attr['name']) + 'Tensor'


def to_int_array_tensors_name(attr):
if 'tensors_name' in attr:
return attr['tensors_name']
return to_pascal_case(attr['name']) + 'TensorList'


def cartesian_prod_attrs(attrs):
items = []
for attr in attrs:
type_name = attr["typename"]
name = attr["name"]
if type_name == "Scalar":
items.append((name, "{}Tensor".format(name)))
items.append((name, to_scalar_tensor_name(attr)))
elif type_name == "IntArray":
items.append(
(name, "{}Tensor".format(name), "{}TensorList".format(name))
)
if 'tensor_name' not in attr and 'manual_flag' in attr:
items.append((name, to_int_array_tensors_name(attr)))
elif 'tensors_name' not in attr and 'manual_flag' in attr:
items.append((name, to_int_array_tensor_name(attr)))
else:
items.append(
(
name,
to_int_array_tensor_name(attr),
to_int_array_tensors_name(attr),
)
)
else:
items.append((name,))

Expand Down
Loading