-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
[stdlib] Integrate hint_trivial_type
in List.__copyinit__
#3809
Open
rd4com
wants to merge
6
commits into
modular:nightly
Choose a base branch
from
rd4com:list_hint_trivial_type
base: nightly
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
dfee931
[stdlib] Integrate `hint_trivial_type` in `List.__copyinit__`
rd4com ade1281
Add tests
rd4com f6cf2c7
Fix: mojo format the changes
rd4com f08eea7
[stdlib] Add parametrized `benchmarks` for `List[Scalar[DT], is_trivi…
rd4com e16f07c
Fix: remove `seed()` and add a `FIXME` for the `BenchConfig` values
rd4com 6cb64b4
Fix: 🥧 mojo format the changes
rd4com 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
# ===----------------------------------------------------------------------=== # | ||
# Copyright (c) 2024, Modular Inc. All rights reserved. | ||
# | ||
# Licensed under the Apache License v2.0 with LLVM Exceptions: | ||
# https://llvm.org/LICENSE.txt | ||
# | ||
# 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. | ||
# ===----------------------------------------------------------------------=== # | ||
# RUN: %mojo-no-debug %s -t | ||
# NOTE: to test changes on the current branch using run-benchmarks.sh, remove | ||
# the -t flag. Remember to replace it again before pushing any code. | ||
|
||
from benchmark import Bench, BenchConfig, Bencher, BenchId, Unit, keep, run | ||
from random import seed | ||
from collections import List | ||
from random import * | ||
|
||
|
||
# ===-----------------------------------------------------------------------===# | ||
# Benchmark Data | ||
# ===-----------------------------------------------------------------------===# | ||
fn make_list[ | ||
size: Int, DT: DType, is_trivial: Bool | ||
]() -> List[Scalar[DT], is_trivial]: | ||
alias scalar_t = Scalar[DT] | ||
var d = List[Scalar[DT], is_trivial](capacity=size) | ||
rand[DT]( | ||
d.unsafe_ptr(), | ||
size, | ||
min=scalar_t.MIN.cast[DType.float64](), | ||
max=scalar_t.MAX.cast[DType.float64](), | ||
) | ||
d.size = size | ||
return d | ||
|
||
|
||
# ===-----------------------------------------------------------------------===# | ||
# Benchmark `List[DT, True].__copyinit__` | ||
# ===-----------------------------------------------------------------------===# | ||
|
||
|
||
@parameter | ||
fn bench_list_copyinit[ | ||
size: Int, DT: DType, is_trivial: Bool | ||
](mut b: Bencher) raises: | ||
var items = make_list[size, DT, is_trivial]() | ||
var result = List[Scalar[DT], is_trivial]() | ||
var res = 0 | ||
|
||
@always_inline | ||
@parameter | ||
fn call_fn() raises: | ||
result = items | ||
res += len(result) | ||
keep(result.data) | ||
keep(items.data) | ||
|
||
b.iter[call_fn]() | ||
print(res) | ||
keep(bool(items)) | ||
keep(bool(result)) | ||
keep(result.data) | ||
keep(items.data) | ||
|
||
|
||
def main(): | ||
var m = Bench( | ||
BenchConfig( | ||
num_repetitions=1, | ||
max_runtime_secs=0.5, | ||
min_runtime_secs=0.25, | ||
min_warmuptime_secs=0, # FIXME: adjust the values | ||
) | ||
) | ||
alias lengths = (1, 2, 4, 8, 16, 32, 128, 256, 512, 1024, 2048, 4096) | ||
|
||
@parameter | ||
for i in range(len(lengths)): | ||
alias length = lengths.get[i, Int]() | ||
m.bench_function[bench_list_copyinit[length, DType.uint8, True]]( | ||
BenchId("List[Scalar[DT], True].__copyinit__ [" + str(length) + "]") | ||
) | ||
m.bench_function[bench_list_copyinit[length, DType.uint8, False]]( | ||
BenchId( | ||
"List[Scalar[DT], False].__copyinit__ [" + str(length) + "]" | ||
) | ||
) | ||
|
||
m.dump_report() |
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
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
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.
Question Any harm in using the default
BenchConfig
values?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.
It takes too much time to benchmark all the
⚙️ parametrized
on my small laptop with defaults(please replace it with what makes sense)
Would you prefer a commit with defaults ?