Skip to content

Commit

Permalink
[SYCL][XRT][Vitis] Fix some failing tests + improve device detection …
Browse files Browse the repository at this point in the history
…of xrt_pi
  • Loading branch information
Gauthier Harnisch committed Jun 2, 2022
1 parent 3fa9b01 commit dabc796
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
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
27 changes: 13 additions & 14 deletions sycl/plugins/xrt/pi_xrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,9 @@ struct _pi_device

private:
native_type xrtDevice_;
ref_counted_ref<_pi_platform> platform_;
/// _pi_platform hold 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 @@ -360,16 +362,23 @@ 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 +713,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 dabc796

Please sign in to comment.