Skip to content

Native row-major PCA#3036

Open
aamijar wants to merge 1 commit into
rapidsai:mainfrom
aamijar:pca-row-major
Open

Native row-major PCA#3036
aamijar wants to merge 1 commit into
rapidsai:mainfrom
aamijar:pca-row-major

Conversation

@aamijar
Copy link
Copy Markdown
Member

@aamijar aamijar commented May 26, 2026

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.

@aamijar aamijar requested a review from a team as a code owner May 26, 2026 00:52
@aamijar aamijar self-assigned this May 26, 2026
@aamijar aamijar added non-breaking Non-breaking change improvement Improvement / enhancement to an existing function labels May 26, 2026
@aamijar aamijar moved this to In Progress in Unstructured Data Processing May 26, 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);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

Comment thread cpp/tests/linalg/pca.cu
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);
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed? You're generating 1-dimensional random data. It can be interpreted as row or col major.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement Improvement / enhancement to an existing function non-breaking Non-breaking change

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

2 participants