Skip to content

Commit

Permalink
[SYCL] Use public interfaces in function_pointer.hpp (#1097)
Browse files Browse the repository at this point in the history
This patch is a part of effort to decouple SYCL Runtime library
interface from its actual implementation. The goal is to improve
SYCL ABI/API compatibility between different versions of library.

Two helper functions were introduced to eliminate calls to _impl
classes. This caused 3 tests fail. 2 tests were found to use
internal APIs. Missing include clauses were added to workaround
those fails. A more robust solution will be provided in separate
patches.

Signed-off-by: Alexander Batashev <alexander.batashev@intel.com>
  • Loading branch information
Alexander Batashev committed Feb 6, 2020
1 parent c5641a7 commit e026a0d
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 12 deletions.
1 change: 0 additions & 1 deletion sycl/include/CL/sycl/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class device_selector;
namespace detail {
class device_impl;
}

class device {
public:
/// Constructs a SYCL device instance as a host device.
Expand Down
17 changes: 6 additions & 11 deletions sycl/include/CL/sycl/intel/function_pointer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#pragma once

#include <CL/sycl/detail/program_impl.hpp>
#include <CL/sycl/device.hpp>
#include <CL/sycl/program.hpp>
#include <CL/sycl/stl.hpp>
Expand All @@ -17,6 +16,10 @@

__SYCL_INLINE namespace cl {
namespace sycl {
namespace detail {
cl_ulong getDeviceFunctionPointerImpl(device &D, program &P,
const char *FuncName);
}
namespace intel {

// This is a preview extension implementation, intended to provide early access
Expand All @@ -27,7 +30,7 @@ namespace intel {
// products. If you are interested in using this feature in your software
// product, please let us know!

using device_func_ptr_holder_t = cl::sycl::cl_ulong;
using device_func_ptr_holder_t = cl_ulong;

/// \brief this function performs a cast from device_func_ptr_holder_t type
/// to the provided function pointer type.
Expand Down Expand Up @@ -78,15 +81,7 @@ device_func_ptr_holder_t get_device_func_ptr(FuncType F, const char *FuncName,
"Program must be built before passing to get_device_func_ptr");
}

device_func_ptr_holder_t FPtr = 0;
// FIXME: return value must be checked here, but since we cannot yet check
// if corresponding extension is supported, let's silently ignore it here.
PI_CALL(piextGetDeviceFunctionPointer)(
detail::pi::cast<pi_device>(detail::getSyclObjImpl(D)->getHandleRef()),
detail::pi::cast<pi_program>(detail::getSyclObjImpl(P)->getHandleRef()),
FuncName, &FPtr);

return FPtr;
return detail::getDeviceFunctionPointerImpl(D, P, FuncName);
}

} // namespace intel
Expand Down
1 change: 1 addition & 0 deletions sycl/source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ set(SYCL_SOURCES
"event.cpp"
"exception.cpp"
"exception_list.cpp"
"function_pointer.cpp"
"half_type.cpp"
"handler.cpp"
"kernel.cpp"
Expand Down
30 changes: 30 additions & 0 deletions sycl/source/function_pointer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//==----------- function_pointer.cpp --- SYCL Function pointers ------------==//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include <CL/sycl/intel/function_pointer.hpp>
#include <CL/sycl/detail/device_impl.hpp>
#include <CL/sycl/detail/program_impl.hpp>

__SYCL_INLINE namespace cl {
namespace sycl {
namespace detail {
intel::device_func_ptr_holder_t
getDeviceFunctionPointerImpl(device &D, program &P, const char *FuncName) {
intel::device_func_ptr_holder_t FPtr = 0;
// FIXME: return value must be checked here, but since we cannot yet check
// if corresponding extension is supported, let's silently ignore it here.
PI_CALL(piextGetDeviceFunctionPointer)(
detail::pi::cast<pi_device>(detail::getSyclObjImpl(D)->getHandleRef()),
detail::pi::cast<pi_program>(detail::getSyclObjImpl(P)->getHandleRef()),
FuncName, &FPtr);
return FPtr;
}

} // namespace detail
} // namespace sycl
} // namespace cl
3 changes: 3 additions & 0 deletions sycl/test/basic_tests/image_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
// RUN: %ACC_RUN_PLACEHOLDER %t1.out

#include <CL/sycl.hpp>
// FIXME do not use internal methods in tests.
#include <CL/sycl/detail/cg.hpp>
#include <CL/sycl/detail/kernel_impl.hpp>

#include <algorithm>
#include <array>
Expand Down
2 changes: 2 additions & 0 deletions sycl/test/kernel-and-program/cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
//===----------------------------------------------------------------------===//

#include <CL/sycl.hpp>
// FIXME do not use internal methods in tests.
#include <CL/sycl/detail/program_impl.hpp>

namespace RT = cl::sycl::RT;
namespace detail = cl::sycl::detail;
Expand Down
2 changes: 2 additions & 0 deletions sycl/test/sub_group/common_ocl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
#include "helper.hpp"
#include <CL/sycl.hpp>
#include <cstring>
#include <fstream>
#include <iostream>

using namespace cl::sycl;
struct Data {
unsigned int local_id;
Expand Down

0 comments on commit e026a0d

Please sign in to comment.