-
Notifications
You must be signed in to change notification settings - Fork 182
Refactor instantiation matrices to generate at build time #1984
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
Merged
rapids-bot
merged 15 commits into
rapidsai:main
from
KyleFromNVIDIA:refactor-file-matrices
Apr 7, 2026
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
867dde7
Refactor instantiation matrices to generate at build time
KyleFromNVIDIA f35432c
DELETE DELETE DELETE
KyleFromNVIDIA 818e7b8
Refactor interleaved scan
KyleFromNVIDIA e619f31
Oops
KyleFromNVIDIA 187f978
More
KyleFromNVIDIA 1ead914
Moar
KyleFromNVIDIA efbb7e6
MOAR
KyleFromNVIDIA 122c620
Merge branch 'main' into refactor-file-matrices
KyleFromNVIDIA ba34834
Comment everything out for debugging
KyleFromNVIDIA daf5977
Uncomment one header
KyleFromNVIDIA 5267856
Uncomment everything
KyleFromNVIDIA 655f3b2
Refactor generate_inst_matrix() to allow other file types
KyleFromNVIDIA 6a8344c
Oops
KyleFromNVIDIA afa38bc
Merge branch 'main' into refactor-file-matrices
KyleFromNVIDIA 3c7ecd8
Review feedback
KyleFromNVIDIA File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,53 @@ | ||
| # ============================================================================= | ||
| # cmake-format: off | ||
| # SPDX-FileCopyrightText: Copyright (c) 2025-2026, NVIDIA CORPORATION. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # cmake-format: on | ||
| # ============================================================================= | ||
|
|
||
| include_guard(GLOBAL) | ||
|
|
||
| function(compute_matrix_product output_var) | ||
| set(options) | ||
| set(one_value MATRIX_JSON_FILE MATRIX_JSON_STRING) | ||
| set(multi_value) | ||
|
|
||
| cmake_parse_arguments(_JIT_LTO "${options}" "${one_value}" "${multi_value}" ${ARGN}) | ||
|
|
||
| find_package(Python3 REQUIRED COMPONENTS Interpreter) | ||
|
|
||
| if(_JIT_LTO_MATRIX_JSON_FILE) | ||
| execute_process( | ||
| COMMAND "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/compute_matrix_product.py" | ||
| "${_JIT_LTO_MATRIX_JSON_FILE}" # | ||
| OUTPUT_VARIABLE output COMMAND_ERROR_IS_FATAL ANY | ||
| ) | ||
| else() | ||
| execute_process( | ||
| COMMAND "${CMAKE_COMMAND}" -E echo "${_JIT_LTO_MATRIX_JSON_STRING}" | ||
| COMMAND "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/compute_matrix_product.py" | ||
| - | ||
| OUTPUT_VARIABLE output COMMAND_ERROR_IS_FATAL ANY | ||
| ) | ||
| endif() | ||
|
|
||
| set(${output_var} | ||
| "${output}" | ||
| PARENT_SCOPE | ||
| ) | ||
| endfunction() | ||
|
|
||
| function(populate_matrix_variables matrix_json_entry) | ||
| string(JSON len LENGTH "${matrix_json_entry}") | ||
| math(EXPR last "${len} - 1") | ||
|
|
||
| # cmake-lint: disable=C0103,E1120 | ||
| foreach(i RANGE "${last}") | ||
| string(JSON key MEMBER "${matrix_json_entry}" "${i}") | ||
| string(JSON value GET "${matrix_json_entry}" "${key}") | ||
| set(${key} | ||
| "${value}" | ||
| PARENT_SCOPE | ||
| ) | ||
| endforeach() | ||
| endfunction() |
This file contains hidden or 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,67 @@ | ||
| # ============================================================================= | ||
| # cmake-format: off | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # cmake-format: on | ||
| # ============================================================================= | ||
|
|
||
| include_guard(GLOBAL) | ||
|
|
||
| include(${CMAKE_CURRENT_LIST_DIR}/compute_matrix_product.cmake) | ||
|
|
||
| function(process_inst_matrix_entry source_list_var) | ||
| set(options) | ||
| set(one_value INPUT_FILE OUTPUT_FILE_FORMAT MATRIX_JSON_ENTRY) | ||
| set(multi_value) | ||
|
|
||
| cmake_parse_arguments(_GIM "${options}" "${one_value}" "${multi_value}" ${ARGN}) | ||
|
|
||
| populate_matrix_variables("${_GIM_MATRIX_JSON_ENTRY}") | ||
| string(CONFIGURE "${_GIM_OUTPUT_FILE_FORMAT}" output_file @ONLY) | ||
|
|
||
| configure_file("${_GIM_INPUT_FILE}" "${output_file}" @ONLY) | ||
|
|
||
| list(APPEND ${source_list_var} "${output_file}") | ||
| set(${source_list_var} | ||
| "${${source_list_var}}" | ||
| PARENT_SCOPE | ||
| ) | ||
| endfunction() | ||
|
|
||
| function(generate_inst_matrix source_list_var) | ||
| set(options) | ||
| set(one_value MATRIX_JSON_FILE MATRIX_JSON_STRING INPUT_FILE OUTPUT_FILE_FORMAT) | ||
| set(multi_value) | ||
|
|
||
| cmake_parse_arguments(_GIM "${options}" "${one_value}" "${multi_value}" ${ARGN}) | ||
|
|
||
| if(_GIM_MATRIX_JSON_FILE) | ||
| set_property( | ||
| DIRECTORY | ||
| PROPERTY CMAKE_CONFIGURE_DEPENDS "${_GIM_MATRIX_JSON_FILE}" | ||
| APPEND | ||
| ) | ||
| compute_matrix_product(matrix_product MATRIX_JSON_FILE "${_GIM_MATRIX_JSON_FILE}") | ||
| else() | ||
| compute_matrix_product(matrix_product MATRIX_JSON_STRING "${_GIM_MATRIX_JSON_STRING}") | ||
| endif() | ||
|
|
||
| string(JSON len LENGTH "${matrix_product}") | ||
| math(EXPR last "${len} - 1") | ||
|
|
||
| # cmake-lint: disable=C0103,E1120 | ||
| foreach(i RANGE "${last}") | ||
| string(JSON matrix_json_entry GET "${matrix_product}" "${i}") | ||
| process_inst_matrix_entry( | ||
| "${source_list_var}" | ||
| INPUT_FILE "${_GIM_INPUT_FILE}" | ||
| OUTPUT_FILE_FORMAT "${_GIM_OUTPUT_FILE_FORMAT}" | ||
| MATRIX_JSON_ENTRY "${matrix_json_entry}" | ||
| ) | ||
| endforeach() | ||
|
|
||
| set(${source_list_var} | ||
| "${${source_list_var}}" | ||
| PARENT_SCOPE | ||
| ) | ||
| endfunction() |
This file contains hidden or 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 hidden or 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,68 @@ | ||
| # ============================================================================= | ||
| # cmake-format: off | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # cmake-format: on | ||
| # ============================================================================= | ||
|
|
||
| include_guard(GLOBAL) | ||
|
|
||
| include(${CMAKE_CURRENT_LIST_DIR}/compute_matrix_product.cmake) | ||
|
|
||
| function(process_string_matrix_entry string_var) | ||
| set(options) | ||
| set(one_value ITEM_FORMAT GLUE MATRIX_JSON_ENTRY) | ||
| set(multi_value) | ||
|
|
||
| cmake_parse_arguments(_GSM "${options}" "${one_value}" "${multi_value}" ${ARGN}) | ||
|
|
||
| populate_matrix_variables("${_GSM_MATRIX_JSON_ENTRY}") | ||
| # It's impossible to pass a semicolon inside `ITEM_FORMAT` due to how CMake divides up arguments, | ||
| # so provide a constant placeholder to insert it into code | ||
| set(semicolon ";") | ||
| string(CONFIGURE "${_GSM_ITEM_FORMAT}" item @ONLY) | ||
|
|
||
| string(APPEND ${string_var} "${_GSM_GLUE}${item}") | ||
| set(${string_var} | ||
| "${${string_var}}" | ||
| PARENT_SCOPE | ||
| ) | ||
| endfunction() | ||
|
|
||
| function(generate_string_matrix string_var) | ||
| set(options) | ||
| set(one_value ITEM_FORMAT GLUE MATRIX_JSON_FILE MATRIX_JSON_STRING) | ||
| set(multi_value) | ||
|
|
||
| cmake_parse_arguments(_GSM "${options}" "${one_value}" "${multi_value}" ${ARGN}) | ||
|
|
||
| if(_GSM_MATRIX_JSON_FILE) | ||
| set_property( | ||
| DIRECTORY | ||
| PROPERTY CMAKE_CONFIGURE_DEPENDS "${_GSM_MATRIX_JSON_FILE}" | ||
| APPEND | ||
| ) | ||
| compute_matrix_product(matrix_product MATRIX_JSON_FILE "${_GSM_MATRIX_JSON_FILE}") | ||
| else() | ||
| compute_matrix_product(matrix_product MATRIX_JSON_STRING "${_GSM_MATRIX_JSON_STRING}") | ||
| endif() | ||
|
|
||
| string(JSON len LENGTH "${matrix_product}") | ||
| math(EXPR last "${len} - 1") | ||
|
|
||
| # cmake-lint: disable=C0103,E1120 | ||
| set(glue) | ||
| foreach(i RANGE "${last}") | ||
| string(JSON matrix_json_entry GET "${matrix_product}" "${i}") | ||
| process_string_matrix_entry( | ||
| "${string_var}" ITEM_FORMAT "${_GSM_ITEM_FORMAT}" GLUE "${glue}" MATRIX_JSON_ENTRY | ||
| "${matrix_json_entry}" | ||
| ) | ||
| set(glue "${_GSM_GLUE}") | ||
| endforeach() | ||
|
|
||
| set(${string_var} | ||
| "${${string_var}}" | ||
| PARENT_SCOPE | ||
| ) | ||
| endfunction() | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.