Skip to content

ABS add MKL kernel #127

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

Merged
merged 1 commit into from
Oct 10, 2020
Merged
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
40 changes: 24 additions & 16 deletions dpnp/backend/custom_kernels_mathematical.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,33 @@ void custom_elemwise_absolute_c(void* array1_in, const std::vector<long>& input_
size_t* input_offset_shape = reinterpret_cast<size_t*>(dpnp_memory_alloc_c(input_shape_size * sizeof(long)));
size_t* result_offset_shape = reinterpret_cast<size_t*>(dpnp_memory_alloc_c(input_shape_size * sizeof(long)));

cl::sycl::range<1> gws(size);
auto kernel_parallel_for_func = [=](cl::sycl::id<1> global_id) {
const size_t idx = global_id[0];
if constexpr (std::is_same<_DataType, double>::value || std::is_same<_DataType, float>::value)
{
// https://docs.oneapi.com/versions/latest/onemkl/abs.html
event = oneapi::mkl::vm::abs(DPNP_QUEUE, size, array1, result);
}
else
{
cl::sycl::range<1> gws(size);
auto kernel_parallel_for_func = [=](cl::sycl::id<1> global_id) {
const size_t idx = global_id[0];

if (array1[idx] >= 0)
{
result[idx] = array1[idx];
}
else
{
result[idx] = -1 * array1[idx];
}
};
if (array1[idx] >= 0)
{
result[idx] = array1[idx];
}
else
{
result[idx] = -1 * array1[idx];
}
};

auto kernel_func = [&](cl::sycl::handler& cgh) {
cgh.parallel_for<class custom_elemwise_absolute_c_kernel<_DataType>>(gws, kernel_parallel_for_func);
};
auto kernel_func = [&](cl::sycl::handler& cgh) {
cgh.parallel_for<class custom_elemwise_absolute_c_kernel<_DataType>>(gws, kernel_parallel_for_func);
};

event = DPNP_QUEUE.submit(kernel_func);
event = DPNP_QUEUE.submit(kernel_func);
}

event.wait();

Expand Down