Skip to content
Merged
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
75 changes: 61 additions & 14 deletions sycl/include/sycl/detail/compile_time_kernel_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,85 @@
namespace sycl {
inline namespace _V1 {
namespace detail {
inline namespace compile_time_kernel_info_v1 {

template <typename KernelNameType>
constexpr kernel_param_desc_t getKernelParamDesc(int Idx) {
#ifndef __INTEL_SYCL_USE_INTEGRATION_HEADERS
kernel_param_desc_t ParamDesc;
ParamDesc.kind =
__builtin_sycl_kernel_param_kind(KernelIdentity<KernelNameType>(), Idx);
ParamDesc.info = ParamDesc.kind == kernel_param_kind_t::kind_accessor
? __builtin_sycl_kernel_param_access_target(
KernelIdentity<KernelNameType>(), Idx)
: __builtin_sycl_kernel_param_size(
KernelIdentity<KernelNameType>(), Idx);
ParamDesc.offset =
__builtin_sycl_kernel_param_offset(KernelIdentity<KernelNameType>(), Idx);
return ParamDesc;
#else
return KernelInfo<KernelNameType>::getParamDesc(Idx);
#endif
}

inline namespace compile_time_kernel_info_v1 {
// This is being passed across ABI boundary, so we don't use std::string_view,
// at least for as long as we support user apps built with GNU libstdc++'s
// pre-C++11 ABI.
struct CompileTimeKernelInfoTy {
detail::string_view Name;
detail::string_view Name{};
unsigned NumParams = 0;
bool IsESIMD = false;
// TODO: Can we just have code_location here?
detail::string_view FileName{};
detail::string_view FunctionName{};
unsigned LineNumber = 0;
unsigned ColumnNumber = 0;
int64_t KernelSize = 0;
using ParamDescGetterT = kernel_param_desc_t (*)(int);
ParamDescGetterT ParamDescGetter = nullptr;
bool HasSpecialCaptures = true;

bool HasSpecialCaptures = [this]() constexpr {
// No-compile time info for the kernel (i.e., kernel_bundle/interop/etc.),
// be conservative:
if (NumParams == 0)
return true;
Comment on lines +54 to +57
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I don't understand why are we returning true if there's no parameters...

Copy link
Contributor

Choose a reason for hiding this comment

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

Basically, we had the following before

template <typename KernelNameType> constexpr bool hasSpecialCaptures() {
  bool FoundSpecialCapture = false;
  for (unsigned I = 0; I < getKernelNumParams<KernelNameType>(); ++I) {
    auto ParamDesc = getKernelParamDesc<KernelNameType>(I);
    bool IsSpecialCapture =
        (ParamDesc.kind != kernel_param_kind_t::kind_std_layout &&
         ParamDesc.kind != kernel_param_kind_t::kind_pointer);
    FoundSpecialCapture |= IsSpecialCapture;
  }
  return FoundSpecialCapture;
}

Which returns false for hasSpecialCaptures when there are no parameters.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This corresponds to the bool HasSpecialCaptures = true; on the left (which we chose in #19117 (comment)).

NumParams isn't really 0 unless we leave that data "uninitialized", like in the interop kernel code path where we only know its Name.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see.


for (unsigned I = 0; I < NumParams; ++I) {
auto ParamDesc = ParamDescGetter(I);
if (ParamDesc.kind != kernel_param_kind_t::kind_std_layout &&
ParamDesc.kind != kernel_param_kind_t::kind_pointer)
return true;
}

return false;
}();
};

template <class Kernel>
inline constexpr CompileTimeKernelInfoTy CompileTimeKernelInfo{
std::string_view(getKernelName<Kernel>()),
getKernelNumParams<Kernel>(),
isKernelESIMD<Kernel>(),
std::string_view(getKernelFileName<Kernel>()),
std::string_view(getKernelFunctionName<Kernel>()),
getKernelLineNumber<Kernel>(),
getKernelColumnNumber<Kernel>(),
getKernelSize<Kernel>(),
&getKernelParamDesc<Kernel>,
hasSpecialCaptures<Kernel>()};

#ifndef __INTEL_SYCL_USE_INTEGRATION_HEADERS
__builtin_sycl_kernel_name(KernelIdentity<Kernel>()),
__builtin_sycl_kernel_param_count(KernelIdentity<Kernel>()),
false /*IsESIMD*/, // TODO needs a builtin counterpart
__builtin_sycl_kernel_file_name(KernelIdentity<Kernel>()),
__builtin_sycl_kernel_function_name(KernelIdentity<Kernel>()),
__builtin_sycl_kernel_line_number(KernelIdentity<Kernel>()),
__builtin_sycl_kernel_column_number(KernelIdentity<Kernel>()),
// TODO needs a builtin counterpart, but is currently only used for checking
// cases with external host compiler, which use integration headers.
0 /* KernelSize */, &getKernelParamDesc<Kernel>
#else
detail::string_view{KernelInfo<Kernel>::getName()},
KernelInfo<Kernel>::getNumParams(), KernelInfo<Kernel>::isESIMD(),
detail::string_view{KernelInfo<Kernel>::getFileName()},
detail::string_view{KernelInfo<Kernel>::getFunctionName()},
KernelInfo<Kernel>::getLineNumber(), KernelInfo<Kernel>::getColumnNumber(),
KernelInfo<Kernel>::getKernelSize(),
// Can't use KernelInfo::getParamDesc due to different return type (const
// ref vs. by val):
&getKernelParamDesc<Kernel>
#endif
};
} // namespace compile_time_kernel_info_v1
} // namespace detail
} // namespace _V1
Expand Down
90 changes: 0 additions & 90 deletions sycl/include/sycl/detail/kernel_desc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,96 +187,6 @@ template <typename KNT> struct KernelIdentity {
using type = KNT;
};

template <typename KernelNameType> constexpr unsigned getKernelNumParams() {
#ifndef __INTEL_SYCL_USE_INTEGRATION_HEADERS
return __builtin_sycl_kernel_param_count(KernelIdentity<KernelNameType>());
#else
return KernelInfo<KernelNameType>::getNumParams();
#endif
}

template <typename KernelNameType>
constexpr kernel_param_desc_t getKernelParamDesc(int Idx) {
#ifndef __INTEL_SYCL_USE_INTEGRATION_HEADERS
kernel_param_desc_t ParamDesc;
ParamDesc.kind =
__builtin_sycl_kernel_param_kind(KernelIdentity<KernelNameType>(), Idx);
ParamDesc.info = ParamDesc.kind == kernel_param_kind_t::kind_accessor
? __builtin_sycl_kernel_param_access_target(
KernelIdentity<KernelNameType>(), Idx)
: __builtin_sycl_kernel_param_size(
KernelIdentity<KernelNameType>(), Idx);
ParamDesc.offset =
__builtin_sycl_kernel_param_offset(KernelIdentity<KernelNameType>(), Idx);
return ParamDesc;
#else
return KernelInfo<KernelNameType>::getParamDesc(Idx);
#endif
}

template <typename KernelNameType> constexpr const char *getKernelName() {
#ifndef __INTEL_SYCL_USE_INTEGRATION_HEADERS
return __builtin_sycl_kernel_name(KernelIdentity<KernelNameType>());
#else
return KernelInfo<KernelNameType>::getName();
#endif
}

template <typename KernelNameType> constexpr bool isKernelESIMD() {
// TODO Needs a builtin counterpart
return KernelInfo<KernelNameType>::isESIMD();
}

template <typename KernelNameType> constexpr const char *getKernelFileName() {
#ifndef __INTEL_SYCL_USE_INTEGRATION_HEADERS
return __builtin_sycl_kernel_file_name(KernelIdentity<KernelNameType>());
#else
return KernelInfo<KernelNameType>::getFileName();
#endif
}

template <typename KernelNameType>
constexpr const char *getKernelFunctionName() {
#ifndef __INTEL_SYCL_USE_INTEGRATION_HEADERS
return __builtin_sycl_kernel_function_name(KernelIdentity<KernelNameType>());
#else
return KernelInfo<KernelNameType>::getFunctionName();
#endif
}

template <typename KernelNameType> constexpr unsigned getKernelLineNumber() {
#ifndef __INTEL_SYCL_USE_INTEGRATION_HEADERS
return __builtin_sycl_kernel_line_number(KernelIdentity<KernelNameType>());
#else
return KernelInfo<KernelNameType>::getLineNumber();
#endif
}

template <typename KernelNameType> constexpr unsigned getKernelColumnNumber() {
#ifndef __INTEL_SYCL_USE_INTEGRATION_HEADERS
return __builtin_sycl_kernel_column_number(KernelIdentity<KernelNameType>());
#else
return KernelInfo<KernelNameType>::getColumnNumber();
#endif
}

template <typename KernelNameType> constexpr int64_t getKernelSize() {
// TODO needs a builtin counterpart, but is currently only used for checking
// cases with external host compiler, which use integration headers.
return KernelInfo<KernelNameType>::getKernelSize();
}

template <typename KernelNameType> constexpr bool hasSpecialCaptures() {
bool FoundSpecialCapture = false;
for (unsigned I = 0; I < getKernelNumParams<KernelNameType>(); ++I) {
auto ParamDesc = getKernelParamDesc<KernelNameType>(I);
bool IsSpecialCapture =
(ParamDesc.kind != kernel_param_kind_t::kind_std_layout &&
ParamDesc.kind != kernel_param_kind_t::kind_pointer);
FoundSpecialCapture |= IsSpecialCapture;
}
return FoundSpecialCapture;
}
} // namespace detail
} // namespace _V1
} // namespace sycl
4 changes: 3 additions & 1 deletion sycl/include/sycl/detail/kernel_launch_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#pragma once

#include <sycl/detail/cg_types.hpp>
#include <sycl/detail/compile_time_kernel_info.hpp>
#include <sycl/detail/helpers.hpp>
#include <sycl/ext/intel/experimental/fp_control_kernel_properties.hpp>
#include <sycl/ext/intel/experimental/kernel_execution_properties.hpp>
Expand Down Expand Up @@ -261,7 +262,8 @@ struct KernelLaunchPropertyWrapper {
if constexpr (ext::oneapi::experimental::detail::
HasKernelPropertiesGetMethod<const KernelType &>::value) {

h->template processProperties<detail::isKernelESIMD<KernelName>()>(
h->template processProperties<
detail::CompileTimeKernelInfo<KernelName>.IsESIMD>(
KernelFunc.get(ext::oneapi::experimental::properties_tag{}));
}
#endif
Expand Down
Loading