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
6 changes: 6 additions & 0 deletions libdevice/crt_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ void _wassert(const wchar_t *wexpr, const wchar_t *wfile, unsigned line) {
}
#else
DEVICE_EXTERN_C
void *malloc(size_t size) {
return reinterpret_cast<void *>(0xEFEFEFEFEFEFEFEF);
}
DEVICE_EXTERN_C
void free(void *ptr) { return ; }
DEVICE_EXTERN_C
void __assert_fail(const char *expr, const char *file, unsigned int line,
const char *func) {
__devicelib_assert_fail(
Expand Down
1 change: 1 addition & 0 deletions llvm/include/llvm/Support/PropertySetIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ class PropertySetRegistry {
static constexpr char SYCL_PROGRAM_METADATA[] = "SYCL/program metadata";
static constexpr char SYCL_MISC_PROP[] = "SYCL/misc properties";
static constexpr char SYCL_ASSERT_USED[] = "SYCL/assert used";
static constexpr char SYCL_MALLOC_USED[] = "SYCL/malloc used";
static constexpr char SYCL_KERNEL_NAMES[] = "SYCL/kernel names";
static constexpr char SYCL_EXPORTED_SYMBOLS[] = "SYCL/exported symbols";
static constexpr char SYCL_IMPORTED_SYMBOLS[] = "SYCL/imported symbols";
Expand Down
7 changes: 7 additions & 0 deletions llvm/lib/SYCLPostLink/ComputeModuleRuntimeInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,13 @@ PropSetRegTy computeModuleProperties(const Module &M,
for (const StringRef &FName : FuncNames)
PropSet.add(PropSetRegTy::SYCL_ASSERT_USED, FName, true);
}
{
std::vector<StringRef> MallocFuncNames{"malloc", "free"};
std::vector<StringRef> FuncNames =
getKernelNamesUsingSpecialFunctions(M, MallocFuncNames);
for (const StringRef &FName : FuncNames)
PropSet.add(PropSetRegTy::SYCL_MALLOC_USED, FName, true);
}
{
std::vector<std::pair<StringRef, int>> ArgPos =
getKernelNamesUsingImplicitLocalMem(M);
Expand Down
2 changes: 2 additions & 0 deletions sycl/include/sycl/builtins.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,8 @@ __glibcxx_assert_fail(const char *file, int line, const char *func,
const char *cond) noexcept;
} // namespace std
extern "C" {
extern __DPCPP_SYCL_EXTERNAL_LIBC void *malloc(size_t size);
extern __DPCPP_SYCL_EXTERNAL_LIBC void free(void *ptr);
extern __DPCPP_SYCL_EXTERNAL_LIBC void __assert_fail(const char *expr,
const char *file,
unsigned int line,
Expand Down
2 changes: 2 additions & 0 deletions sycl/source/detail/compiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
#define __SYCL_PROPERTY_SET_SYCL_MISC_PROP "SYCL/misc properties"
/// PropertySetRegistry::SYCL_ASSERT_USED defined in PropertySetIO.h
#define __SYCL_PROPERTY_SET_SYCL_ASSERT_USED "SYCL/assert used"
/// PropertySetRegistry::SYCL_MALLOC_USED defined in PropertySetIO.h
#define __SYCL_PROPERTY_SET_SYCL_MALLOC_USED "SYCL/malloc used"
/// PropertySetRegistry::SYCL_KERNEL_NAMES defined in PropertySetIO.h
#define __SYCL_PROPERTY_SET_SYCL_KERNEL_NAMES "SYCL/kernel names"
/// PropertySetRegistry::SYCL_EXPORTED_SYMBOLS defined in PropertySetIO.h
Expand Down
1 change: 1 addition & 0 deletions sycl/source/detail/device_binary_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ RTDeviceBinaryImage::RTDeviceBinaryImage(sycl_device_binary Bin) {
DeviceLibMetadata.init(Bin, __SYCL_PROPERTY_SET_DEVICELIB_METADATA);
KernelParamOptInfo.init(Bin, __SYCL_PROPERTY_SET_KERNEL_PARAM_OPT_INFO);
AssertUsed.init(Bin, __SYCL_PROPERTY_SET_SYCL_ASSERT_USED);
MallocUsed.init(Bin, __SYCL_PROPERTY_SET_SYCL_MALLOC_USED);
ImplicitLocalArg.init(Bin, __SYCL_PROPERTY_SET_SYCL_IMPLICIT_LOCAL_ARG);
ProgramMetadata.init(Bin, __SYCL_PROPERTY_SET_PROGRAM_METADATA);
// Convert ProgramMetadata into the UR format
Expand Down
2 changes: 2 additions & 0 deletions sycl/source/detail/device_binary_image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ class RTDeviceBinaryImage {
return KernelParamOptInfo;
}
const PropertyRange &getAssertUsed() const { return AssertUsed; }
const PropertyRange &getMallocUsed() const { return MallocUsed; }
const PropertyRange &getProgramMetadata() const { return ProgramMetadata; }
const std::vector<ur_program_metadata_t> &getProgramMetadataUR() const {
return ProgramMetadataUR;
Expand Down Expand Up @@ -260,6 +261,7 @@ class RTDeviceBinaryImage {
RTDeviceBinaryImage::PropertyRange DeviceLibMetadata;
RTDeviceBinaryImage::PropertyRange KernelParamOptInfo;
RTDeviceBinaryImage::PropertyRange AssertUsed;
RTDeviceBinaryImage::PropertyRange MallocUsed;
RTDeviceBinaryImage::PropertyRange ProgramMetadata;
RTDeviceBinaryImage::PropertyRange KernelNames;
RTDeviceBinaryImage::PropertyRange ExportedSymbols;
Expand Down
8 changes: 8 additions & 0 deletions sycl/source/detail/device_kernel_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ DeviceKernelInfo::DeviceKernelInfo(const CompileTimeKernelInfoTy &Info)
void DeviceKernelInfo::init(KernelNameStrRefT KernelName) {
auto &PM = detail::ProgramManager::getInstance();
MUsesAssert = PM.kernelUsesAssert(KernelName);
MUsesMalloc = PM.kernelUsesMalloc(KernelName);
MImplicitLocalArgPos = PM.kernelImplicitLocalArgPos(KernelName);
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
MInitialized.store(true);
Expand Down Expand Up @@ -78,10 +79,17 @@ FastKernelSubcacheT &DeviceKernelInfo::getKernelSubcache() {
assertInitialized();
return MFastKernelSubcache;
}

bool DeviceKernelInfo::usesAssert() {
assertInitialized();
return MUsesAssert;
}

bool DeviceKernelInfo::usesMalloc() {
assertInitialized();
return MUsesMalloc;
}

const std::optional<int> &DeviceKernelInfo::getImplicitLocalArgPos() {
assertInitialized();
return MImplicitLocalArgPos;
Expand Down
2 changes: 2 additions & 0 deletions sycl/source/detail/device_kernel_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class DeviceKernelInfo : public CompileTimeKernelInfoTy {

FastKernelSubcacheT &getKernelSubcache();
bool usesAssert();
bool usesMalloc();
const std::optional<int> &getImplicitLocalArgPos();

private:
Expand All @@ -121,6 +122,7 @@ class DeviceKernelInfo : public CompileTimeKernelInfoTy {
FastKernelSubcacheT MFastKernelSubcache;
bool MUsesAssert;
std::optional<int> MImplicitLocalArgPos;
bool MUsesMalloc;
};

} // namespace detail
Expand Down
9 changes: 9 additions & 0 deletions sycl/source/detail/program_manager/program_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1802,6 +1802,14 @@ void ProgramManager::cacheKernelUsesAssertInfo(const RTDeviceBinaryImage &Img) {
m_KernelUsesAssert.insert(Prop->Name);
}

void ProgramManager::cacheKernelUsesMallocInfo(const RTDeviceBinaryImage &Img) {
const RTDeviceBinaryImage::PropertyRange &MallocUsedRange =
Img.getMallocUsed();
if (MallocUsedRange.isAvailable())
for (const auto &Prop : MallocUsedRange)
m_KernelUsesMalloc.insert(Prop->Name);
}

void ProgramManager::cacheKernelImplicitLocalArg(
const RTDeviceBinaryImage &Img) {
const RTDeviceBinaryImage::PropertyRange &ImplicitLocalArgRange =
Expand Down Expand Up @@ -2045,6 +2053,7 @@ void ProgramManager::addImage(sycl_device_binary RawImg,
}

cacheKernelUsesAssertInfo(*Img);
cacheKernelUsesMallocInfo(*Img);

// check if kernel uses sanitizer
{
Expand Down
13 changes: 11 additions & 2 deletions sycl/source/detail/program_manager/program_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,11 @@ class ProgramManager {
return m_KernelUsesAssert.find(KernelName) != m_KernelUsesAssert.end();
}

template <typename NameT>
bool kernelUsesMalloc(const NameT &KernelName) const {
return m_KernelUsesMalloc.find(KernelName) != m_KernelUsesMalloc.end();
}

SanitizerType kernelUsesSanitizer() const { return m_SanitizerFoundInImage; }

std::optional<int>
Expand Down Expand Up @@ -409,6 +414,9 @@ class ProgramManager {
/// Add info on kernels using assert into cache
void cacheKernelUsesAssertInfo(const RTDeviceBinaryImage &Img);

/// Add info on kernels using assert into cache
void cacheKernelUsesMallocInfo(const RTDeviceBinaryImage &Img);

/// Add info on kernels using local arg into cache
void cacheKernelImplicitLocalArg(const RTDeviceBinaryImage &Img);

Expand Down Expand Up @@ -522,8 +530,9 @@ class ProgramManager {
// different types without temporary key_type object creation. This includes
// standard overloads, such as comparison between std::string and
// std::string_view or just char*.
using KernelUsesAssertSet = std::set<KernelNameStrT, std::less<>>;
KernelUsesAssertSet m_KernelUsesAssert;
using KernelUsesFnSet = std::set<KernelNameStrT, std::less<>>;
KernelUsesFnSet m_KernelUsesAssert;
KernelUsesFnSet m_KernelUsesMalloc;
std::unordered_map<KernelNameStrT, int> m_KernelImplicitLocalArgPos;

// Map for storing device kernel information. Runtime lookup should be avoided
Expand Down
6 changes: 6 additions & 0 deletions sycl/source/detail/scheduler/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <sycl/sampler.hpp>

#include <cassert>
#include <iostream>
#include <optional>
#include <string>
#include <vector>
Expand Down Expand Up @@ -2534,6 +2535,11 @@ static ur_result_t SetKernelParamsAndLaunch(
property_list.push_back({UR_KERNEL_LAUNCH_PROPERTY_ID_WORK_GROUP_MEMORY,
{{WorkGroupMemorySize}}});
}

if (DeviceKernelInfo.usesMalloc())
std::cout << "enqueue Kernel with Malloc launch for " << DeviceKernelInfo.Name.data() << std::endl;
else
std::cout << "enqueue Kernel without Malloc launch for " << DeviceKernelInfo.Name.data() << std::endl;
ur_event_handle_t UREvent = nullptr;
ur_result_t Error =
Adapter.call_nocheck<UrApiKind::urEnqueueKernelLaunchWithArgsExp>(
Expand Down
Loading