feat(rocprim): Implement Kernel Tuner for Various Algorithms #12008
<!-- therock-pr-bot-policy-check -->
✅ All Checks Passed — Ready for Review
| Check | Status | Details |
|---|:---:|---|
| 📝 PR Description | ✅ Pass | — |
| ⛔ Forbidden Files | ✅ Pass | — |
| 🧪 Unit Test | ⚠️ Warning | Error: Source/code files changed without an accompanying unit test.<br>Expected: add at least one test file named like test_<name>.py / test_<name>.cpp (or <name>_test.*).<br>Current: code file(s) changed: projects/rocprim/rocprim/include/rocprim/device/detail/config/device_find_first_of.hpp, projects/rocprim/rocprim/include/rocprim/device/detail/config/device_run_length_encode.hpp, projects/rocprim/rocprim/include/rocprim/device/detail/config/device_run_length_encode_non_trivial.hpp, projects/rocprim/rocprim/include/rocprim/device/detail/config/device_search_n.hpp, projects/rocprim/rocprim/include/rocprim/device/detail/config/device_topk_air.hpp (+10 more); no test file found |
| 🔎 pre-commit | ✅ Pass | — |
| 🚫 Draft PR | 🔜 To Be Enabled | — |
| 🚩 Feature Flag | 🔜 To Be Enabled | — |
| 📊 Code Coverage | 🔜 To Be Enabled | — |
| 🤖 therock-pr-bot | ✅ Pass | — |
🎉 All checks passed! This PR is ready for review.
📖 Need help? See the Policy FAQ for details on every check and how to fix failures.
<!-- therock-pr-bot-fix-policies -->
🎉 All checks passed! This PR is ready for review.
This is a duplicate
missing comma after
missing a comma here?
I found a few potential problems
I've been running Kernel Tuner on gfx950 and found a few things adjacent to this PR.
(1) device_adjacent_difference_inplace.cpp.jinja2 has a stray {% endblock %}. Not introduced here, but this PR is the natural place to fix it.
(2) Skipping already-completed algorithms only works partially. Should this be filed separately?
Could we add a guard so it can't silently happen again?
Maybe a better idea is to scrape the file names. I think I will do this to prevent this from happening again
@NB4444 , @amd-jmahovsky added auto scrape for file names in run_tuning. Not sure if this is the best way to do it, if there is a cleaner way let me know
@amd-mcieslak, it was actually not a stray endblock but a missing {% block benchmark_type % }. It must have got lost somewhere in all the changes. Thanks for catching that!
Should these be in a block?
Can this be {{ mk_is_fp_type_check(type.key_type) }} && {{ mk_type_sz_check(type.key_type) }} like in device_run_length_encode.h.jinja2?
do we need to import log2?
do we need this import?
Should it be written something like this, because the system is looking for a class named "Tuner" and right now we won't get the right one:
from tuning_device_topk_air import Tuner as TopkAirTuner
class Tuner(TopkAirTuner):
@classmethod
def _get_default_args(cls) -> TunerArgs:
return TunerArgs(algo_full_name='device_segmented_topk_air')
if __name__ == "__main__":
Tuner.cli()
Won't the glob also pick up things like "tuning_device_partition.py" and "tuning_device_select.py"? (I think these are helper modules.)
Also the regex has a few problems. The '.' means 'match any one character' not 'match a dot'. So the ".py" means any character followed by ".py" which will mess up on something like "tuning_device_copy.py" by matching the first py.
Claude suggests:r'^tuning_|\.py$'
\. is a literal dot, and ^/$ anchor the matches to the start and end of the name.
max_length is not a tuneable param and should be removed from params
the MAX_LENGTH constant can also go away, I think
I think we want to run both MAX_LENGTH=10 and MAX_LENGTH=1000 and then average the results. Claude suggests changing the template:
{% block benchmark_type %}
{% endblock %}
{% block benchmark_queue %}
executor.queue<device_run_length_encode_benchmark<key_type, 10, config>>();
executor.queue<device_run_length_encode_benchmark<key_type, 1000, config>>();
{% endblock %}
{% block get_time %}
double sum = 0;
double n = 0;
for(const double & x : executor.get_all_bytes_per_second()){
sum += (1000.0 * primbench::GiB) / x;
n++;
}
return sum / n;
{% endblock %}
The jinja template fix looks good.
Claude says this is a problem because of the rocprim:: prefix, where the rest of the tuner infrastructure is expecting just "empty_type" and things are silently failing. It proposes a solution that bypasses the issue:
for key_type in COMMON_KEY_TYPES:
self.tune_type(key_type) # keys-only
for value_type in COMMON_VALUE_TYPES:
self.tune_type(key_type, value_type)
I think this pattern is also used in tuning_device_merge.py.
The auto-scrape is better than the assert guard. Good call! But doesn't the glob pick up all tuning_ files, including tuning_device_paritition.py and tuning_device_select.py? If so, they will show up in --list as available algorithms. Should they be excluded? Also, should the regex r'tuning_|.py' use an escape charater \.py and the glob us tuning_.py? It's minor but keeps the tuner from picking up any stray files.
There are two transpose lines here. Other configs are transpose, direct.
There are two transpose lines here. Other configs are transpose, direct.
I found a few things.
I had no idea it did that. Thanks! Gonna have to make changes to search algos too then.
nope, this is dead code from copying a file over
nope, same as above
my inexperience with regex is shining brightly :)
This is addressed in #12186
The idea is to merge in that PR first and then this one
yes
yes
LGTM
I checked 39eda1a directly. Both run-length-encode tuners fail on their first type, before anything is compiled:
$ run_tuning.py --algo-regex run_length --max-fevals 1 --output-dir /tmp/out
File "tuner/base_tuner.py", line 407, in _get_base_tune_kernel_args
"restrictions": self._get_restrictions(types),
File "tuner/tuning_device_run_length_encode.py", line 58, in _get_restrictions
key_size = TYPE_CONFIGS[key_type].size
TypeError: unhashable type: 'dict'
Same at
tuning_device_run_length_encode_non_trivial.py line 63.Can you please check?
@amd-mcieslak thanks for pointing out that issue. It has now been fixed
LGTM
<!-- therock-pr-bot-precommit-failed -->
Pre-commit check failed
⛔ pre-commit failed
Please run locally:
python -m pip install pre-commitpre-commit installpre-commit run --all-files --show-diff-on-failureThis repo uses .pre-commit-config.yaml.
closing in favor of #13007
reopening cause hipccl might get nuked
temp close to resolve some tests
clsoing in favourof #13756
amd-jmahovsky
NguyenNhuDi
Motivation
Implement Kernel Tuner for Various Algorithms:
- device_find_first_of
- device_run_length_encode
- device_run_length_encode_non_trivial
- device_segmented_topk_air
- device_topk_air
JIRA ID: AIPRIMS-236 & EXSWSTRHPC-322
Technical Details
The rocPRIM config changes are due to running migrate.py (this updates the legacy config to be ready for Kernel Tuner)
This PR is built on top of #11678, do not merge until the mentioned PR has been merged
Recommended way to review this PR is to go to "Commit" and review the files per commit.
Test Plan
Local running of kernel tuner, making sure output matches legacy tuners and that there are no errors.
Test Result
Generated config files compiles, and all unit tests were passing locally
Submission Checklist