Native row-major PCA#3036
Open
aamijar wants to merge 1 commit into
Open
Conversation
divyegala
reviewed
May 28, 2026
Comment on lines
+161
to
+166
| auto components_col_storage = raft::make_device_matrix<math_t, idx_t, raft::col_major>( | ||
| handle, input_row_major ? n_components : idx_t(0), input_row_major ? n_cols : idx_t(0)); | ||
| math_t* components_col_data = | ||
| input_row_major ? components_col_storage.data_handle() : components.data_handle(); | ||
| auto components_col_view = raft::make_device_matrix_view<math_t, idx_t, raft::col_major>( | ||
| components_col_data, n_components, n_cols); |
Member
There was a problem hiding this comment.
I found this confusing to read:
Suggested change
| auto components_col_storage = raft::make_device_matrix<math_t, idx_t, raft::col_major>( | |
| handle, input_row_major ? n_components : idx_t(0), input_row_major ? n_cols : idx_t(0)); | |
| math_t* components_col_data = | |
| input_row_major ? components_col_storage.data_handle() : components.data_handle(); | |
| auto components_col_view = raft::make_device_matrix_view<math_t, idx_t, raft::col_major>( | |
| components_col_data, n_components, n_cols); | |
| std::optional<raft::device_matrix<math_t, idx_t, raft::col_major>> components_col_storage; | |
| if constexpr (input_row_major) { | |
| components_col_storage = raft::make_device_matrix_view<...)(...); | |
| } | |
| math_t* components_col_data = | |
| input_row_major ? components_col_storage->data_handle() : components.data_handle(); | |
| auto components_col_view = raft::make_device_matrix_view<math_t, idx_t, raft::col_major>( | |
| components_col_data, n_components, n_cols); |
Comment on lines
+247
to
+248
| auto components_copy_view = raft::make_device_matrix_view<math_t, idx_t, LayoutPolicy>( | ||
| components_copy.data(), n_components, n_cols); |
Member
There was a problem hiding this comment.
Why explicitly here instead of inline in the diff before this PR?
Comment on lines
+324
to
+325
| auto components_copy_view = raft::make_device_matrix_view<math_t, idx_t, LayoutPolicy>( | ||
| components_copy.data(), n_components, n_cols); |
Comment on lines
+351
to
+363
| void to_row_major(const T* col_major_src, T* row_major_dst, int n_rows, int n_cols) | ||
| { | ||
| std::vector<T> host_col(n_rows * n_cols); | ||
| std::vector<T> host_row(n_rows * n_cols); | ||
| raft::update_host(host_col.data(), col_major_src, n_rows * n_cols, stream); | ||
| RAFT_CUDA_TRY(cudaStreamSynchronize(stream)); | ||
| for (int i = 0; i < n_rows; ++i) { | ||
| for (int j = 0; j < n_cols; ++j) { | ||
| host_row[i * n_cols + j] = host_col[j * n_rows + i]; | ||
| } | ||
| } | ||
| raft::update_device(row_major_dst, host_row.data(), n_rows * n_cols, stream); | ||
| } |
Member
There was a problem hiding this comment.
Why is this needed? You're generating 1-dimensional random data. It can be interpreted as row or col major.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Currently PCA only supports col-major which is not ideal for consumers passing in row-major datasets.
This PR exposes row-major APIs for PCA and calls the corresponding row-major raft primitives based on templated row or col layout.
This PR is backward compatible with cuml and cuvs.