Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace internal
{
template class OnlineContainer<DAAL_FPTYPE, fastCSR, DAAL_CPU>;

template class LowOrderMomentsOnlineKernel<DAAL_FPTYPE, fastCSR, DAAL_CPU>;
template class DAAL_EXPORT LowOrderMomentsOnlineKernel<DAAL_FPTYPE, fastCSR, DAAL_CPU>;
} // namespace internal
} // namespace low_order_moments
} // namespace algorithms
Expand Down

Copy link
Copy Markdown
Contributor Author

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_statistics for batch jobs).

Original file line number Diff line number Diff line change
Expand Up @@ -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>;
Expand All @@ -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>;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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,
Expand Down Expand Up @@ -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(),

@icfaust icfaust Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

required due to limitations in call_daal_kernel_finalize_compute to the default method (I didn't understand this at first, but have verified).

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());
Expand Down Expand Up @@ -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
Expand Up @@ -32,7 +32,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 = partial_compute_input<task_t>;
using result_t = partial_compute_result<task_t>;
Expand All @@ -41,8 +40,24 @@ using descriptor_t = detail::descriptor_base<task_t>;
namespace daal_lom = daal::algorithms::low_order_moments;
namespace interop = dal::backend::interop;

template <typename Float, daal::internal::CpuType Cpu>
template <daal_lom::Method Value>
using daal_method_constant = std::integral_constant<daal_lom::Method, Value>;

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, to_daal_method<Method>::value, Cpu>;

template <typename Float, daal::internal::CpuType Cpu>
using daal_lom_online_dense_kernel_t =
daal_lom::internal::LowOrderMomentsOnlineKernel<Float, daal_lom::defaultDense, Cpu>;

template <typename Float, typename Task>
Expand Down Expand Up @@ -146,11 +161,11 @@ result_t call_daal_kernel_with_weights(const context_cpu& ctx,
}
{
interop::status_to_exception(
interop::call_daal_kernel<Float, daal_lom_online_kernel_t>(ctx,
daal_data.get(),
&daal_partial,
&daal_parameter,
is_online));
interop::call_daal_kernel<Float, daal_lom_online_dense_kernel_t>(ctx,
daal_data.get(),
&daal_partial,
&daal_parameter,
is_online));
}
auto result = get_partial_result<Float, task_t>(daal_partial, desc);

Expand All @@ -159,18 +174,18 @@ result_t call_daal_kernel_with_weights(const context_cpu& ctx,
else {
{
interop::status_to_exception(
interop::call_daal_kernel<Float, daal_lom_online_kernel_t>(ctx,
daal_data.get(),
&daal_partial,
&daal_parameter,
is_online));
interop::call_daal_kernel<Float, daal_lom_online_dense_kernel_t>(ctx,
daal_data.get(),
&daal_partial,
&daal_parameter,
is_online));
}
auto result = get_partial_result<Float, task_t>(daal_partial, desc);
return result;
}
}

template <typename Float, typename Task>
template <typename Float, typename Method, typename Task>
result_t call_daal_kernel_without_weights(const context_cpu& ctx,
const descriptor_t& desc,
const partial_compute_input<Task>& input) {
Expand Down Expand Up @@ -223,52 +238,56 @@ result_t call_daal_kernel_without_weights(const context_cpu& ctx,
daal_partial.set(daal_lom::PartialResultId::partialSumSquares,
daal_partial_sum_squares);
}
interop::status_to_exception(
interop::call_daal_kernel<Float, daal_lom_online_kernel_t>(ctx,
daal_data.get(),
&daal_partial,
&daal_parameter,
is_online));
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>()
.compute(daal_data.get(), &daal_partial, &daal_parameter, is_online);
}));
auto result = get_partial_result<Float, task_t>(daal_partial, desc);
return result;
}
else {
{
interop::status_to_exception(
interop::call_daal_kernel<Float, daal_lom_online_kernel_t>(ctx,
daal_data.get(),
&daal_partial,
&daal_parameter,
is_online));
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>()
.compute(daal_data.get(), &daal_partial, &daal_parameter, is_online);
}));
}
auto result = get_partial_result<Float, task_t>(daal_partial, desc);
return result;
}
}

template <typename Float, typename Task>
template <typename Float, typename Method, typename Task>
static partial_compute_result<Task> partial_compute(const context_cpu& ctx,
const descriptor_t& desc,
const partial_compute_input<Task>& input) {
if (input.get_weights().has_data()) {
return call_daal_kernel_with_weights<Float>(ctx, desc, input);
return call_daal_kernel_with_weights<Float, Task>(ctx, desc, input);
}
else {
return call_daal_kernel_without_weights<Float, Task>(ctx, desc, input);
return call_daal_kernel_without_weights<Float, Method, Task>(ctx, desc, input);
}
}

template <typename Float>
struct partial_compute_kernel_cpu<Float, method_t, task_t> {
template <typename Float, typename Method>
struct partial_compute_kernel_cpu<Float, Method, task_t> {
partial_compute_result<task::compute> operator()(
const context_cpu& ctx,
const descriptor_t& desc,
const partial_compute_input<task::compute>& input) const {
return partial_compute<Float, task::compute>(ctx, desc, input);
return partial_compute<Float, Method, task::compute>(ctx, desc, input);
}
};

template struct partial_compute_kernel_cpu<float, method_t, task_t>;
template struct partial_compute_kernel_cpu<double, method_t, task_t>;
template struct partial_compute_kernel_cpu<float, method::dense, task_t>;
template struct partial_compute_kernel_cpu<double, method::dense, task_t>;
template struct partial_compute_kernel_cpu<float, method::sparse, task_t>;
template struct partial_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
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ struct finalize_compute_ops_dispatcher<Policy, Float, Method, Task> {

INSTANTIATE(float, method::dense, task::compute)
INSTANTIATE(double, method::dense, task::compute)
INSTANTIATE(float, method::sparse, task::compute)
INSTANTIATE(double, method::sparse, task::compute)

} // namespace v1
} // namespace oneapi::dal::basic_statistics::detail
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ struct finalize_compute_ops_dispatcher<Policy, Float, Method, Task> {

INSTANTIATE(float, method::dense, task::compute)
INSTANTIATE(double, method::dense, task::compute)
INSTANTIATE(float, method::sparse, task::compute)
INSTANTIATE(double, method::sparse, task::compute)

} // namespace v1
} // namespace oneapi::dal::basic_statistics::detail
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ struct partial_compute_ops_dispatcher<Policy, Float, Method, Task> {

INSTANTIATE(float, method::dense, task::compute)
INSTANTIATE(double, method::dense, task::compute)
INSTANTIATE(float, method::sparse, task::compute)
INSTANTIATE(double, method::sparse, task::compute)

} // namespace v1
} // namespace oneapi::dal::basic_statistics::detail
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ struct partial_compute_ops_dispatcher<Policy, Float, Method, Task> {

INSTANTIATE(float, method::dense, task::compute)
INSTANTIATE(double, method::dense, task::compute)
INSTANTIATE(float, method::sparse, task::compute)
INSTANTIATE(double, method::sparse, task::compute)

} // namespace v1
} // namespace oneapi::dal::basic_statistics::detail
Loading
Loading