-
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 all commits
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 |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /******************************************************************************* | ||
| * Copyright contributors to the oneDAL project | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| *******************************************************************************/ | ||
|
|
||
| #include "oneapi/dal/algo/basic_statistics/backend/gpu/finalize_compute_kernel.hpp" | ||
| #include "oneapi/dal/exceptions.hpp" | ||
|
|
||
| namespace oneapi::dal::basic_statistics::backend { | ||
|
|
||
| using dal::backend::context_gpu; | ||
| using method_t = method::sparse; | ||
| using task_t = task::compute; | ||
| using input_t = partial_compute_result<task_t>; | ||
| using result_t = compute_result<task_t>; | ||
| using descriptor_t = detail::descriptor_base<task_t>; | ||
|
|
||
| template <typename Float> | ||
| struct finalize_compute_kernel_gpu<Float, method_t, task_t> { | ||
| result_t operator()(const context_gpu& ctx, | ||
| const descriptor_t& desc, | ||
| const input_t& input) const { | ||
| throw unimplemented(dal::detail::error_messages::method_not_implemented()); | ||
| } | ||
| }; | ||
|
|
||
| template struct finalize_compute_kernel_gpu<float, method_t, task_t>; | ||
| template struct finalize_compute_kernel_gpu<double, method_t, task_t>; | ||
|
|
||
| } // namespace oneapi::dal::basic_statistics::backend |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /******************************************************************************* | ||
| * Copyright contributors to the oneDAL project | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| *******************************************************************************/ | ||
|
|
||
| #include "oneapi/dal/algo/basic_statistics/backend/gpu/partial_compute_kernel.hpp" | ||
| #include "oneapi/dal/exceptions.hpp" | ||
|
|
||
| namespace oneapi::dal::basic_statistics::backend { | ||
|
|
||
| using dal::backend::context_gpu; | ||
| using method_t = method::sparse; | ||
| using task_t = task::compute; | ||
| using input_t = partial_compute_input<task_t>; | ||
| using result_t = partial_compute_result<task_t>; | ||
| using descriptor_t = detail::descriptor_base<task_t>; | ||
|
|
||
| template <typename Float> | ||
| struct partial_compute_kernel_gpu<Float, method_t, task_t> { | ||
| result_t operator()(const context_gpu& ctx, | ||
| const descriptor_t& desc, | ||
| const input_t& input) const { | ||
| throw unimplemented(dal::detail::error_messages::method_not_implemented()); | ||
| } | ||
| }; | ||
|
|
||
| template struct partial_compute_kernel_gpu<float, method_t, task_t>; | ||
| template struct partial_compute_kernel_gpu<double, method_t, task_t>; | ||
|
|
||
| } // namespace oneapi::dal::basic_statistics::backend |
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).