Skip to content

Commit

Permalink
Merge branch 'sycl/unified/next' into MergeIntel
Browse files Browse the repository at this point in the history
  • Loading branch information
Gauthier Harnisch committed Jun 6, 2022
2 parents 3fa9b01 + 4de2a59 commit 5a97a7d
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 35 deletions.
19 changes: 9 additions & 10 deletions clang/lib/Driver/ToolChains/VXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,18 +248,17 @@ void SYCL::SYCLPostLinkVXX::constructSYCLVXXPLCommand(
//// V++ Toolchain
///////////////////////////////////////////////////////////////////////////////

static llvm::Triple getLinuxTriple(const llvm::Triple &Triple) {
if (Triple.getArch() == llvm::Triple::vitis_ip)
return llvm::Triple(llvm::sys::getProcessTriple());
return Triple;
}

VXXToolChain::VXXToolChain(const Driver &D, const llvm::Triple &Triple,
const ArgList &Args)
: Generic_GCC(D, Triple, Args) {
if (Triple.getArch() == llvm::Triple::vitis_ip) {
/// If we are targeting vitis_ip we cannot rely on sycl setting up the
/// standard library. So we do it ourselves by configuring gcc to find
/// native system libraries.
GCCInstallation.init(llvm::Triple(llvm::sys::getProcessTriple()), Args);
} else {
/// Otherwise we initialize gcc with our triple and gcc will find nothing.
GCCInstallation.init(Triple, Args);
}
: ToolChain(D, Triple, Args) {
InnerTC =
std::make_unique<toolchains::Linux>(D, getLinuxTriple(Triple), Args);
// Lookup binaries into the driver directory, this is used to
// discover the clang-offload-bundler executable.
getProgramPaths().push_back(getDriver().Dir);
Expand Down
20 changes: 16 additions & 4 deletions clang/lib/Driver/ToolChains/VXX.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_VXX_H
#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_VXX_H

#include "ToolChains/Gnu.h"
#include "ToolChains/Linux.h"
#include "clang/Driver/ToolChain.h"
#include "clang/Driver/Tool.h"
#include "llvm/ADT/Triple.h"
Expand Down Expand Up @@ -76,9 +76,10 @@ class LLVM_LIBRARY_VISIBILITY SYCLPostLinkVXX : public Tool {

namespace toolchains {

/// The VXXToolChain inherits from Generic_GCC because the logic for detecting
/// and using libstdc++ are inside Generic_GCC
class LLVM_LIBRARY_VISIBILITY VXXToolChain : public Generic_GCC {
/// The VXXToolChain inherits from Linux because the logic for detecting
/// and using libstdc++ are inside Linux
class LLVM_LIBRARY_VISIBILITY VXXToolChain : public ToolChain {
std::unique_ptr<ToolChain> InnerTC;
public:
VXXToolChain(const Driver &D, const llvm::Triple &Triple,
const llvm::opt::ArgList &Args);
Expand Down Expand Up @@ -107,6 +108,17 @@ class LLVM_LIBRARY_VISIBILITY VXXToolChain : public Generic_GCC {

const ToolChain* HostTC;

virtual void
AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const override {
InnerTC->AddClangSystemIncludeArgs(DriverArgs, CC1Args);
}
virtual void AddClangCXXStdlibIncludeArgs(
const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const override {
InnerTC->AddClangCXXStdlibIncludeArgs(DriverArgs, CC1Args);
}

protected:
Tool *buildLinker() const override;
virtual Tool *getTool(Action::ActionClass AC) const override;
Expand Down
6 changes: 4 additions & 2 deletions llvm/lib/SYCL/LowerSYCLMetaData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,10 @@ struct LSMDState {

HasChanged = true;
Function *SideEffect = Intrinsic::getDeclaration(&M, Intrinsic::sideeffect);
OperandBundleDef OpBundle(
XclId.str(), std::vector<Value *>{F->arg_begin(), F->arg_end()});
std::vector<Value *> Args;
for (auto &A : F->args())
Args.push_back(&A);
OperandBundleDef OpBundle(XclId.str(), Args);

Instruction *I = CallInst::Create(SideEffect, {}, {OpBundle});
I->insertBefore(F->getEntryBlock().getTerminator());
Expand Down
31 changes: 14 additions & 17 deletions sycl/plugins/xrt/pi_xrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ to_native_handle(From &&from) {

struct _pi_device
/// TODO: _pi_device should be ref-counted , but the SYCL runtime
/// seems to be expected piDevicesGet to return objects with a ref-count
/// seems to expect piDevicesGet to return objects with a ref-count
/// of 0 so we do not destroy _pi_device for now.
/// (https://github.com/intel/llvm/issues/6034)
/// : ref_counted_base<_pi_device>
Expand All @@ -339,7 +339,9 @@ struct _pi_device

private:
native_type xrtDevice_;
ref_counted_ref<_pi_platform> platform_;
/// _pi_platform holds a counting reference onto all its _pi_device so we do
/// not keep counting reference on devices to prevent circular dependency.
_pi_platform *platform_;

public:
_pi_device(native_type dev, _pi_platform *platform)
Expand All @@ -358,18 +360,23 @@ struct _pi_device
///
struct _pi_platform : ref_counted_base<_pi_platform>, unique<_pi_platform> {
private:
/// _pi_device hold a counting reference onto _pi_platform so we do not keep
/// counting reference on devices to prevent circular dependency.
std::vector<_pi_device*> devices_;
std::vector<ref_counted_ref<_pi_device>> devices_;

public:
_pi_platform() {
int device_count = xrt::system::enumerate_devices();
devices_.reserve(device_count);
for (int idx = 0; idx < device_count; idx++)
devices_.emplace_back(
make_ref_counted<_pi_device>(REPRODUCE_CALL(xrt::device, idx), this));
}
unsigned get_num_device() { return devices_.size(); }
ref_counted_ref<_pi_device> get_device(unsigned idx) { return devices_[idx]; }
/// Add a device if it inst't already in the list
template <typename... Ts> ref_counted_ref<_pi_device> make_device(Ts &&...ts) {
auto new_dev = REPRODUCE_CALL(xrt::device, std::forward<Ts>(ts)...);
auto bdf = new_dev.template get_info<xrt::info::device::bdf>();
for (auto *dev : devices_)
for (ref_counted_ref<_pi_device> dev : devices_)
if (bdf == dev->get_native().get_info<xrt::info::device::bdf>())
return dev;
auto dev_ref = make_ref_counted<_pi_device>(std::move(new_dev), this);
Expand Down Expand Up @@ -704,21 +711,11 @@ pi_result xrt_piDevicesGet(pi_platform platform, pi_device_type device_type,
uint32_t *num_devices) {
assert_valid_obj(platform);

unsigned device_count = std::max<unsigned>(1, platform->get_num_device());

if (num_devices) {
*num_devices = device_count;
*num_devices = platform->get_num_device();
}

if (devices) {
/// We keep the reference to the device to insure it doesn't get destroyed
/// before re call give_externally
ref_counted_ref<_pi_device> new_device;

// If the platform is empty add a device
if (platform->get_num_device() == 0)
new_device = platform->make_device(0);

for (size_t i = 0; i < platform->get_num_device(); ++i)
devices[i] = platform->get_device(i).give_externally();
}
Expand Down
2 changes: 1 addition & 1 deletion sycl/test/vitis/simple_tests/vitis_ip_export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// RUN: %clangxx -std=c++20 --target=vitis_ip-xilinx %s -o %t.zip --vitis-ip-part=xc7vx330t-ffg1157-1 -### 2>&1 | FileCheck %s
// RUN: %clangxx -std=c++20 --target=vitis_ip-xilinx %s -o %t.zip --vitis-ip-part=xc7vx330t-ffg1157-1

// CHECK: clang-{{.*}}"-cc1" "-triple" "vitis_ip-xilinx" "-O3" "-disable-llvm-passes" {{.*}} "-emit-llvm"
// CHECK: clang-{{.*}}"-cc1" "-triple" "vitis_ip-xilinx" "-O3" "-disable-llvm-passes" {{.*}}
// CHECK-NEXT: sycl_vxx.py" "ipexport" "--clang_path" {{.*}} "--target" "xc7vx330t-ffg1157-1"
// CHECK-NOT: clang

Expand Down
2 changes: 1 addition & 1 deletion sycl/tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ if(SYCL_BUILD_PI_HIP)
${SYCL_BUILD_PI_HIP_INCLUDE_DIR})
endif()

if(SYCL_BUILD_PI_HIP)
if(SYCL_BUILD_PI_XRT)
target_include_directories(get_device_count_by_type
PRIVATE
${XILINX_RT_INCLUDE})
Expand Down

0 comments on commit 5a97a7d

Please sign in to comment.