-
Notifications
You must be signed in to change notification settings - Fork 226
[enhancement] adding csr online support to oneDAL basic_statistics
#3715
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,7 +31,6 @@ | |
| namespace oneapi::dal::basic_statistics::backend { | ||
|
|
||
| using dal::backend::context_cpu; | ||
| using method_t = method::dense; | ||
| using task_t = task::compute; | ||
| using input_t = compute_input<task_t>; | ||
| using result_t = compute_result<task_t>; | ||
|
|
@@ -41,11 +40,23 @@ namespace daal_lom = daal::algorithms::low_order_moments; | |
| namespace interop = dal::backend::interop; | ||
| namespace bk = dal::backend; | ||
|
|
||
| template <typename Float, daal::internal::CpuType Cpu> | ||
| template <daal_lom::Method Value> | ||
| using daal_method_constant = std::integral_constant<daal_lom::Method, Value>; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This follows on precedent in kmeans. |
||
|
|
||
| template <typename Method> | ||
| struct to_daal_method; | ||
|
|
||
| template <> | ||
| struct to_daal_method<method::dense> : daal_method_constant<daal_lom::defaultDense> {}; | ||
|
|
||
| template <> | ||
| struct to_daal_method<method::sparse> : daal_method_constant<daal_lom::fastCSR> {}; | ||
|
|
||
| template <typename Float, daal::internal::CpuType Cpu, typename Method> | ||
| using daal_lom_online_kernel_t = | ||
| daal_lom::internal::LowOrderMomentsOnlineKernel<Float, daal_lom::defaultDense, Cpu>; | ||
| daal_lom::internal::LowOrderMomentsOnlineKernel<Float, to_daal_method<Method>::value, Cpu>; | ||
|
|
||
| template <typename Float, typename Task> | ||
| template <typename Float, typename Method, typename Task> | ||
| static compute_result<Task> call_daal_kernel_finalize_compute( | ||
| const context_cpu& ctx, | ||
| const descriptor_t& desc, | ||
|
|
@@ -80,19 +91,22 @@ static compute_result<Task> call_daal_kernel_finalize_compute( | |
| auto daal_stdev = interop::allocate_daal_homogen_table<Float>(1, column_count); | ||
| auto daal_variation = interop::allocate_daal_homogen_table<Float>(1, column_count); | ||
| if (result_ids == daal_lom::estimatesMeanVariance || result_ids == daal_lom::estimatesAll) { | ||
| interop::status_to_exception( | ||
| interop::call_daal_kernel_finalize_compute<Float, daal_lom_online_kernel_t>( | ||
| ctx, | ||
| daal_partial_obs.get(), | ||
| daal_partial_sums.get(), | ||
| daal_partial_sum_squares.get(), | ||
| daal_partial_sum_squares_centered.get(), | ||
| daal_means.get(), | ||
| daal_rawt.get(), | ||
| daal_variance.get(), | ||
| daal_stdev.get(), | ||
| daal_variation.get(), | ||
| &daal_parameter)); | ||
| interop::status_to_exception(dal::backend::dispatch_by_cpu(ctx, [&](auto cpu) { | ||
| return daal_lom_online_kernel_t< | ||
| Float, | ||
| oneapi::dal::backend::interop::to_daal_cpu_type<decltype(cpu)>::value, | ||
| Method>() | ||
| .finalizeCompute(daal_partial_obs.get(), | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. required due to limitations in |
||
| daal_partial_sums.get(), | ||
| daal_partial_sum_squares.get(), | ||
| daal_partial_sum_squares_centered.get(), | ||
| daal_means.get(), | ||
| daal_rawt.get(), | ||
| daal_variance.get(), | ||
| daal_stdev.get(), | ||
| daal_variation.get(), | ||
| &daal_parameter); | ||
| })); | ||
| } | ||
| compute_result<Task> res; | ||
| res.set_result_options(desc.get_result_options()); | ||
|
|
@@ -132,24 +146,26 @@ static compute_result<Task> call_daal_kernel_finalize_compute( | |
| return res; | ||
| } | ||
|
|
||
| template <typename Float, typename Task> | ||
| template <typename Float, typename Method, typename Task> | ||
| static compute_result<Task> finalize_compute(const context_cpu& ctx, | ||
| const descriptor_t& desc, | ||
| const partial_compute_result<Task>& input) { | ||
| return call_daal_kernel_finalize_compute<Float, Task>(ctx, desc, input); | ||
| return call_daal_kernel_finalize_compute<Float, Method, Task>(ctx, desc, input); | ||
| } | ||
|
|
||
| template <typename Float> | ||
| struct finalize_compute_kernel_cpu<Float, method_t, task_t> { | ||
| template <typename Float, typename Method> | ||
| struct finalize_compute_kernel_cpu<Float, Method, task_t> { | ||
| compute_result<task::compute> operator()( | ||
| const context_cpu& ctx, | ||
| const descriptor_t& desc, | ||
| const partial_compute_result<task::compute>& input) const { | ||
| return finalize_compute<Float, task::compute>(ctx, desc, input); | ||
| return finalize_compute<Float, Method, task::compute>(ctx, desc, input); | ||
| } | ||
| }; | ||
|
|
||
| template struct finalize_compute_kernel_cpu<float, method_t, task_t>; | ||
| template struct finalize_compute_kernel_cpu<double, method_t, task_t>; | ||
| template struct finalize_compute_kernel_cpu<float, method::dense, task_t>; | ||
| template struct finalize_compute_kernel_cpu<double, method::dense, task_t>; | ||
| template struct finalize_compute_kernel_cpu<float, method::sparse, task_t>; | ||
| template struct finalize_compute_kernel_cpu<double, method::sparse, task_t>; | ||
|
|
||
| } // namespace oneapi::dal::basic_statistics::backend | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -104,6 +104,56 @@ class basic_statistics_test : public te::crtp_algo_fixture<TestType, Derived> { | |
| return (data.row_count_ > 100 || data.column_count_ > 100) && policy.is_cpu(); | ||
| } | ||
|
|
||
| std::vector<csr_table> split_csr_by_rows(const csr_table& table, std::int64_t split_count) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I need help here. I am not well versed in catch2 (only basic knowledge).
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What kind of help?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please move it to the common place: https://github.com/uxlfoundation/oneDAL/blob/main/cpp/oneapi/dal/test/engine/tables.hpp |
||
| ONEDAL_ASSERT(split_count > 0); | ||
| const std::int64_t row_count = table.get_row_count(); | ||
| const std::int64_t column_count = table.get_column_count(); | ||
| const std::int64_t block_size_regular = row_count / split_count; | ||
| const std::int64_t block_size_tail = row_count % split_count; | ||
| const auto indexing = table.get_indexing(); | ||
|
|
||
| csr_accessor<const float_t> accessor(table); | ||
| std::vector<csr_table> result(split_count); | ||
|
|
||
| std::int64_t row_offset = 0; | ||
| for (std::int64_t i = 0; i < split_count; ++i) { | ||
| const std::int64_t tail = std::int64_t(i + 1 == split_count) * block_size_tail; | ||
| const std::int64_t block_size = block_size_regular + tail; | ||
| if (block_size <= 0) { | ||
| result[i] = csr_table{}; | ||
| row_offset += block_size; | ||
| continue; | ||
| } | ||
| const auto [data_arr, col_arr, row_arr] = | ||
| accessor.pull({ row_offset, row_offset + block_size }, indexing); | ||
| result[i] = | ||
| csr_table::wrap(data_arr, col_arr, row_arr, column_count, indexing); | ||
| row_offset += block_size; | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| void csr_online_general_checks(const te::csr_table_builder<>& data, | ||
| bs::result_option_id compute_mode, | ||
| std::int64_t nBlocks) { | ||
| CAPTURE(compute_mode, nBlocks); | ||
| const auto bs_desc = | ||
| bs::descriptor<float_t, basic_statistics::method::sparse>{}.set_result_options( | ||
| compute_mode); | ||
| const auto csr_full = data.build_csr_table(this->get_policy()); | ||
| const auto dense_full = data.build_dense_table(this->get_policy()); | ||
|
|
||
| const auto blocks = split_csr_by_rows(csr_full, nBlocks); | ||
| dal::basic_statistics::partial_compute_result<> partial_result; | ||
| for (std::int64_t i = 0; i < nBlocks; ++i) { | ||
| partial_result = this->partial_compute(bs_desc, partial_result, blocks[i]); | ||
| } | ||
| auto compute_result = this->finalize_compute(bs_desc, partial_result); | ||
| table weights; | ||
| check_compute_result(compute_mode, dense_full, weights, compute_result); | ||
| check_for_exception_for_non_requested_results(compute_mode, compute_result); | ||
| } | ||
|
|
||
| void online_general_checks(const te::dataframe& data_fr, | ||
| std::shared_ptr<te::dataframe> weights_fr, | ||
| bs::result_option_id compute_mode, | ||
|
|
||
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.
Would need to rename this file based on its use for csr support as well (following the precedent of
basic_statisticsfor batch jobs).