This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
[OpPerf] Consolidate array manipulation related operators #17487
Merged
Merged
Changes from 15 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
eb59775
add shape manipulation, array expanding ops
ChaiBapchya 3a438ce
split as alias of SliceChannel
ChaiBapchya feb57e8
add rounding ops
ChaiBapchya 8ea9bee
add profiler param to function description
ChaiBapchya abcfa09
add params, improve readability of prepare op input logic, improve op…
ChaiBapchya 435d2ac
Merge branch 'master' into rearrange_ops
ChaiBapchya 6724b23
Merge branch 'master' into rearrange_ops
ChaiBapchya 98910e2
Merge branch 'master' into rearrange_ops
ChaiBapchya cb0861e
Merge branch 'master' into rearrange_ops
ChaiBapchya f1a88f7
Merge branch 'master' into rearrange_ops
ChaiBapchya 342b4a4
fix index merge issue
ChaiBapchya 1a8f211
Merge branch 'master' into rearrange_ops
ChaiBapchya 893d8bf
Merge branch 'master' into rearrange_ops
ChaiBapchya a376b50
add join,split ops
ChaiBapchya 23cb1bc
minor fixes in join,split
ChaiBapchya a602b79
Merge branch 'master' into rearrange_ops
ChaiBapchya 0ced040
fix if else logic issue, lint
ChaiBapchya 315feb8
Merge branch 'master' into rearrange_ops
ChaiBapchya a6b2ef2
add comment on profiler, remove all completed ops, add res of 2 ops i…
ChaiBapchya 9b0824d
remove unreachable if statements
ChaiBapchya ef14bef
resolved merge conflict
ChaiBapchya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
254 changes: 254 additions & 0 deletions
254
benchmark/opperf/nd_operations/array_manipulation_operators.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,254 @@ | ||
# 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. | ||
|
||
import mxnet as mx | ||
|
||
from mxnet import nd | ||
from benchmark.opperf.utils.benchmark_utils import run_performance_test | ||
from benchmark.opperf.utils.common_utils import merge_map_list | ||
from benchmark.opperf.rules.default_params import MX_OP_MODULE | ||
|
||
from benchmark.opperf.utils.benchmark_utils import run_op_benchmarks | ||
from benchmark.opperf.utils.op_registry_utils import get_all_rearrange_operators, \ | ||
get_all_shape_operators, get_all_expanding_operators, get_all_rounding_operators | ||
|
||
"""Performance benchmark tests for MXNet Array Manipulation Operators. | ||
|
||
Array Rearrange Operators | ||
1. transpose | ||
2. swapaxes (alias SwapAxis) | ||
3. flip (alias reverse) | ||
4. depth_to_space | ||
5. space_to_depth | ||
|
||
Array Shape Manipulation Operators | ||
1. split (alias SliceChannel) | ||
2. diag | ||
3. reshape | ||
4. reshape_like | ||
5. size_array | ||
6. shape_array | ||
|
||
Array Expanding Operators | ||
1. broadcast_axes (alias broadcast_axis) | ||
2. broadcast_to | ||
3. broadcast_like | ||
4. repeat | ||
5. tile | ||
6. pad | ||
7. expand_dims | ||
|
||
|
||
Array Rounding Operators | ||
1. round | ||
2. rint | ||
3. fix | ||
4. floor | ||
5. ceil | ||
6. trunc | ||
|
||
Array Join & Split Operators | ||
1. concat | ||
2. split | ||
3. stack | ||
|
||
""" | ||
|
||
|
||
def run_rearrange_operators_benchmarks(ctx=mx.cpu(), dtype='float32', profiler='native', warmup=25, runs=100): | ||
"""Runs benchmarks with the given context and precision (dtype) for all the | ||
rearrange operators in MXNet. | ||
|
||
Parameters | ||
---------- | ||
ctx: mx.ctx | ||
Context to run benchmarks | ||
dtype: str, default 'float32' | ||
Precision to use for benchmarks | ||
profiler: str, default 'native' | ||
Type of Profiler to use (native/python) | ||
warmup: int, default 25 | ||
Number of times to run for warmup | ||
runs: int, default 100 | ||
Number of runs to capture benchmark results | ||
|
||
Returns | ||
------- | ||
Dictionary of results. Key -> Name of the operator, Value -> Benchmark results. | ||
|
||
""" | ||
# Fetch all array rearrange operators | ||
mx_rearrange_ops = get_all_rearrange_operators() | ||
|
||
# Run benchmarks | ||
mx_rearrange_op_results = run_op_benchmarks(mx_rearrange_ops, dtype, ctx, profiler, warmup, runs) | ||
return mx_rearrange_op_results | ||
|
||
|
||
def run_shape_operators_benchmarks(ctx=mx.cpu(), dtype='float32', profiler='native', warmup=25, runs=100): | ||
"""Runs benchmarks with the given context and precision (dtype) for all the | ||
array shape operators in MXNet. | ||
|
||
Parameters | ||
---------- | ||
ctx: mx.ctx | ||
Context to run benchmarks | ||
dtype: str, default 'float32' | ||
Precision to use for benchmarks | ||
profiler: str, default 'native' | ||
Type of Profiler to use (native/python) | ||
warmup: int, default 25 | ||
Number of times to run for warmup | ||
runs: int, default 100 | ||
Number of runs to capture benchmark results | ||
|
||
Returns | ||
------- | ||
Dictionary of results. Key -> Name of the operator, Value -> Benchmark results. | ||
|
||
""" | ||
# Fetch all array shape operators | ||
mx_shape_ops = get_all_shape_operators() | ||
|
||
# Run benchmarks | ||
mx_shape_op_results = run_op_benchmarks(mx_shape_ops, dtype, ctx, profiler, warmup, runs) | ||
return mx_shape_op_results | ||
|
||
|
||
def run_expanding_operators_benchmarks(ctx=mx.cpu(), dtype='float32', profiler='native', warmup=25, runs=100): | ||
"""Runs benchmarks with the given context and precision (dtype) for all the | ||
array expanding operators in MXNet. | ||
|
||
Parameters | ||
---------- | ||
ctx: mx.ctx | ||
Context to run benchmarks | ||
dtype: str, default 'float32' | ||
Precision to use for benchmarks | ||
profiler: str, default 'native' | ||
Type of Profiler to use (native/python) | ||
warmup: int, default 25 | ||
Number of times to run for warmup | ||
runs: int, default 100 | ||
Number of runs to capture benchmark results | ||
|
||
Returns | ||
------- | ||
Dictionary of results. Key -> Name of the operator, Value -> Benchmark results. | ||
|
||
""" | ||
# Fetch all array expanding operators | ||
mx_expanding_ops = get_all_expanding_operators() | ||
|
||
# Run benchmarks | ||
mx_expanding_op_results = run_op_benchmarks(mx_expanding_ops, dtype, ctx, profiler, warmup, runs) | ||
return mx_expanding_op_results | ||
|
||
|
||
def run_rounding_operators_benchmarks(ctx=mx.cpu(), dtype='float32', profiler='native', warmup=25, runs=100): | ||
"""Runs benchmarks with the given context and precision (dtype) for all the | ||
array rounding operators in MXNet. | ||
|
||
Parameters | ||
---------- | ||
ctx: mx.ctx | ||
Context to run benchmarks | ||
dtype: str, default 'float32' | ||
Precision to use for benchmarks | ||
profiler: str, default 'native' | ||
Type of Profiler to use (native/python) | ||
warmup: int, default 25 | ||
Number of times to run for warmup | ||
runs: int, default 100 | ||
Number of runs to capture benchmark results | ||
|
||
Returns | ||
------- | ||
Dictionary of results. Key -> Name of the operator, Value -> Benchmark results. | ||
|
||
""" | ||
# Fetch all array rounding operators | ||
mx_rounding_ops = get_all_rounding_operators() | ||
|
||
# Run benchmarks | ||
mx_rounding_op_results = run_op_benchmarks(mx_rounding_ops, dtype, ctx, profiler, warmup, runs) | ||
return mx_rounding_op_results | ||
|
||
|
||
def run_join_split_operators_benchmarks(ctx=mx.cpu(), dtype='float32', profiler='native', warmup=25, runs=100): | ||
"""Runs benchmarks with the given context and precision (dtype) for all the | ||
join & split operators in MXNet. | ||
|
||
Parameters | ||
---------- | ||
ctx: mx.ctx | ||
Context to run benchmarks | ||
dtype: str, default 'float32' | ||
Precision to use for benchmarks | ||
profiler: str, default 'native' | ||
Type of Profiler to use (native/python) | ||
warmup: int, default 25 | ||
Number of times to run for warmup | ||
runs: int, default 100 | ||
Number of runs to capture benchmark results | ||
|
||
Returns | ||
------- | ||
Dictionary of results. Key -> Name of the operator, Value -> Benchmark results. | ||
|
||
""" | ||
# backward not supported for all 3 ops - concat, stack, split | ||
# concat | ||
concat_benchmark_res = run_performance_test([getattr(MX_OP_MODULE, "concat")], | ||
run_backward=False, | ||
dtype=dtype, | ||
ctx=ctx, | ||
profiler=profiler, | ||
inputs=[{"args0":nd.random_normal(shape=(100,100)), | ||
"args1":nd.random_normal(shape=(100,100)), | ||
"args2":nd.random_normal(shape=(100,100))} | ||
], | ||
warmup=warmup, | ||
runs=runs) | ||
|
||
# split | ||
split_benchmark_res = run_performance_test([getattr(MX_OP_MODULE, "split")], | ||
run_backward=False, | ||
dtype=dtype, | ||
ctx=ctx, | ||
profiler=profiler, | ||
inputs=[{"data": (1024, 1024), "num_outputs": 2}, | ||
{"data": (10000, 1), "num_outputs": 1}, | ||
{"data": (10000, 100), "num_outputs": 10} | ||
], | ||
warmup=warmup, | ||
runs=runs) | ||
|
||
# stack | ||
stack_benchmark_res = run_performance_test([getattr(MX_OP_MODULE, "stack")], | ||
run_backward=False, | ||
dtype=dtype, | ||
ctx=ctx, | ||
profiler=profiler, | ||
inputs=[{"args0":nd.random_normal(shape=(100,100)), | ||
"args1":nd.random_normal(shape=(100,100)), | ||
"args2":nd.random_normal(shape=(100,100))} | ||
], | ||
warmup=warmup, | ||
runs=runs) | ||
mx_join_split_op_results = merge_map_list(concat_benchmark_res + split_benchmark_res + stack_benchmark_res) | ||
return mx_join_split_op_results |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does
native
mean? Could you be more specificThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Native profiler uses the MXNet's default profiler function
Python uses python's time-it function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know what it means. Could you provide more information to first time users?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a line. @apeforest