-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from oneapi-src/main
Pull the changes from main branch
- Loading branch information
Showing
32 changed files
with
1,314 additions
and
140 deletions.
There are no files selected for viewing
This file contains 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
Validating CODEOWNERS rules …
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package(default_visibility = ["//visibility:public"]) | ||
load("@onedal//dev/bazel:dal.bzl", | ||
"dal_module", | ||
"dal_test_suite", | ||
) | ||
|
||
dal_module( | ||
name = "finiteness_checker", | ||
auto = True, | ||
dal_deps = [ | ||
"@onedal//cpp/oneapi/dal:core", | ||
"@onedal//cpp/oneapi/dal/backend/primitives:reduction", | ||
], | ||
extra_deps = [ | ||
"@onedal//cpp/daal:data_management", | ||
] | ||
) | ||
|
||
dal_test_suite( | ||
name = "cpu_tests", | ||
private = True, | ||
compile_as = [ "c++" ], | ||
srcs = glob([ | ||
"backend/cpu/test/*.cpp", | ||
]), | ||
dal_deps = [ | ||
":finiteness_checker", | ||
], | ||
) | ||
|
||
dal_test_suite( | ||
name = "gpu_tests", | ||
private = True, | ||
compile_as = [ "dpc++" ], | ||
srcs = glob([ | ||
"backend/gpu/test/*.cpp", | ||
]), | ||
dal_deps = [ | ||
":finiteness_checker", | ||
], | ||
) | ||
|
||
dal_test_suite( | ||
name = "interface_tests", | ||
framework = "catch2", | ||
srcs = glob([ | ||
"test/*.cpp", | ||
]), | ||
dal_deps = [ | ||
":finiteness_checker", | ||
], | ||
) | ||
|
||
dal_test_suite( | ||
name = "tests", | ||
tests = [ | ||
":cpu_tests", | ||
":gpu_tests", | ||
":interface_tests", | ||
], | ||
) |
39 changes: 39 additions & 0 deletions
39
cpp/oneapi/dal/algo/finiteness_checker/backend/cpu/compute_kernel.hpp
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/******************************************************************************* | ||
* 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. | ||
*******************************************************************************/ | ||
|
||
#pragma once | ||
|
||
#include "oneapi/dal/algo/finiteness_checker/compute_types.hpp" | ||
#include "oneapi/dal/backend/dispatcher.hpp" | ||
#include "oneapi/dal/table/homogen.hpp" | ||
|
||
namespace oneapi::dal::finiteness_checker::backend { | ||
|
||
template <typename Float, typename Method, typename Task> | ||
struct compute_kernel_cpu { | ||
compute_result<Task> operator()(const dal::backend::context_cpu& ctx, | ||
const detail::descriptor_base<Task>& params, | ||
const compute_input<Task>& input) const; | ||
|
||
#ifdef ONEDAL_DATA_PARALLEL | ||
void operator()(const dal::backend::context_cpu& ctx, | ||
const detail::descriptor_base<Task>& params, | ||
const table& data, | ||
bool& res) const; | ||
#endif | ||
}; | ||
|
||
} // namespace oneapi::dal::finiteness_checker::backend |
73 changes: 73 additions & 0 deletions
73
cpp/oneapi/dal/algo/finiteness_checker/backend/cpu/compute_kernel_dense.cpp
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/******************************************************************************* | ||
* 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 <daal/include/data_management/data/internal/finiteness_checker.h> | ||
|
||
#include "oneapi/dal/algo/finiteness_checker/backend/cpu/compute_kernel.hpp" | ||
#include "oneapi/dal/backend/interop/common.hpp" | ||
#include "oneapi/dal/backend/interop/error_converter.hpp" | ||
#include "oneapi/dal/backend/interop/table_conversion.hpp" | ||
#include "oneapi/dal/exceptions.hpp" | ||
|
||
#include "oneapi/dal/table/row_accessor.hpp" | ||
|
||
namespace oneapi::dal::finiteness_checker::backend { | ||
|
||
using dal::backend::context_cpu; | ||
using input_t = compute_input<task::compute>; | ||
using result_t = compute_result<task::compute>; | ||
using descriptor_t = detail::descriptor_base<task::compute>; | ||
|
||
namespace interop = dal::backend::interop; | ||
|
||
template <typename Float> | ||
static result_t call_daal_kernel(const context_cpu& ctx, | ||
const descriptor_t& desc, | ||
const table& data) { | ||
const auto daal_data = interop::convert_to_daal_table<Float>(data); | ||
|
||
return result_t().set_finite( | ||
daal::data_management::internal::allValuesAreFinite<Float>(*daal_data.get(), | ||
desc.get_allow_NaN())); | ||
} | ||
|
||
template <typename Float> | ||
static result_t compute(const context_cpu& ctx, const descriptor_t& desc, const input_t& input) { | ||
return call_daal_kernel<Float>(ctx, desc, input.get_data()); | ||
} | ||
|
||
template <typename Float> | ||
struct compute_kernel_cpu<Float, method::dense, task::compute> { | ||
result_t operator()(const context_cpu& ctx, | ||
const descriptor_t& desc, | ||
const input_t& input) const { | ||
return compute<Float>(ctx, desc, input); | ||
} | ||
|
||
#ifdef ONEDAL_DATA_PARALLEL | ||
void operator()(const context_cpu& ctx, | ||
const descriptor_t& desc, | ||
const table& data, | ||
bool& res) const { | ||
throw unimplemented(dal::detail::error_messages::method_not_implemented()); | ||
} | ||
#endif | ||
}; | ||
|
||
template struct compute_kernel_cpu<float, method::dense, task::compute>; | ||
template struct compute_kernel_cpu<double, method::dense, task::compute>; | ||
|
||
} // namespace oneapi::dal::finiteness_checker::backend |
39 changes: 39 additions & 0 deletions
39
cpp/oneapi/dal/algo/finiteness_checker/backend/gpu/compute_kernel.hpp
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/******************************************************************************* | ||
* 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. | ||
*******************************************************************************/ | ||
|
||
#pragma once | ||
|
||
#include "oneapi/dal/algo/finiteness_checker/compute_types.hpp" | ||
#include "oneapi/dal/backend/dispatcher.hpp" | ||
#include "oneapi/dal/table/homogen.hpp" | ||
|
||
namespace oneapi::dal::finiteness_checker::backend { | ||
|
||
template <typename Float, typename Method, typename Task> | ||
struct compute_kernel_gpu { | ||
compute_result<Task> operator()(const dal::backend::context_gpu& ctx, | ||
const detail::descriptor_base<Task>& params, | ||
const compute_input<Task>& input) const; | ||
|
||
#ifdef ONEDAL_DATA_PARALLEL | ||
void operator()(const dal::backend::context_gpu& ctx, | ||
const detail::descriptor_base<Task>& params, | ||
const table& data, | ||
bool& res); | ||
#endif | ||
}; | ||
|
||
} // namespace oneapi::dal::finiteness_checker::backend |
81 changes: 81 additions & 0 deletions
81
cpp/oneapi/dal/algo/finiteness_checker/backend/gpu/compute_kernel_dense_dpc.cpp
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/******************************************************************************* | ||
* 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/finiteness_checker/backend/gpu/compute_kernel.hpp" | ||
#include "oneapi/dal/backend/primitives/reduction.hpp" | ||
#include "oneapi/dal/backend/primitives/utils.hpp" | ||
#include "oneapi/dal/detail/profiler.hpp" | ||
|
||
namespace oneapi::dal::finiteness_checker::backend { | ||
|
||
using dal::backend::context_gpu; | ||
using input_t = compute_input<task::compute>; | ||
using result_t = compute_result<task::compute>; | ||
using descriptor_t = detail::descriptor_base<task::compute>; | ||
|
||
namespace pr = dal::backend::primitives; | ||
|
||
template <typename Float> | ||
bool compute_finiteness(sycl::queue& queue, | ||
const pr::ndview<Float, 1>& data_1d, | ||
bool allowNaN, | ||
const dal::backend::event_vector& deps = {}) { | ||
Float out; | ||
|
||
if (allowNaN) { | ||
ONEDAL_PROFILER_TASK(finiteness_checker.reduce, queue); | ||
out = pr::reduce_1d(queue, data_1d, pr::logical_or<Float>{}, pr::isinf<Float>{}, deps); | ||
} | ||
else { | ||
ONEDAL_PROFILER_TASK(finiteness_checker.reduce, queue); | ||
out = pr::reduce_1d(queue, data_1d, pr::logical_or<Float>{}, pr::isinfornan<Float>{}, deps); | ||
} | ||
// invert out to match daal implementation (assert result is finite) | ||
return !static_cast<bool>(out); | ||
} | ||
|
||
template <typename Float> | ||
static result_t compute(const context_gpu& ctx, const descriptor_t& desc, const input_t& input) { | ||
auto& queue = ctx.get_queue(); | ||
const auto data = input.get_data(); | ||
const auto data_1d = pr::table2ndarray_1d<Float>(queue, data, sycl::usm::alloc::device); | ||
return result_t{}.set_finite(compute_finiteness(queue, data_1d, desc.get_allow_NaN())); | ||
} | ||
|
||
template <typename Float> | ||
struct compute_kernel_gpu<Float, method::dense, task::compute> { | ||
result_t operator()(const context_gpu& ctx, | ||
const descriptor_t& desc, | ||
const input_t& input) const { | ||
return compute<Float>(ctx, desc, input); | ||
} | ||
|
||
#ifdef ONEDAL_DATA_PARALLEL | ||
void operator()(const context_gpu& ctx, | ||
const descriptor_t& desc, | ||
const table& data, | ||
bool& res) { | ||
auto& queue = ctx.get_queue(); | ||
const auto data_1d = pr::table2ndarray_1d<Float>(queue, data, sycl::usm::alloc::device); | ||
res = compute_finiteness(queue, data_1d, desc.get_allow_NaN()); | ||
} | ||
#endif | ||
}; | ||
|
||
template struct compute_kernel_gpu<float, method::dense, task::compute>; | ||
template struct compute_kernel_gpu<double, method::dense, task::compute>; | ||
|
||
} // namespace oneapi::dal::finiteness_checker::backend |
Oops, something went wrong.