Skip to content

Commit 5f3b001

Browse files
Merge pull request #1791 from IntelPython/run-os-llvm-dpctl-tests-without-stdout-stderr-capture
Try/catch wrap a call to deallocate in silent usm_host_allocator class to be used by std::vector for array metadata transfers
2 parents a077f42 + a49bd76 commit 5f3b001

File tree

5 files changed

+37
-14
lines changed

5 files changed

+37
-14
lines changed

.github/workflows/os-llvm-sycl-build.yml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ jobs:
1313

1414
env:
1515
DOWNLOAD_URL_PREFIX: https://github.com/intel/llvm/releases/download
16-
DRIVER_PATH: 2023-WW27
17-
OCLCPUEXP_FN: oclcpuexp-2023.16.6.0.28_rel.tar.gz
18-
TBB_URL: https://github.com/oneapi-src/oneTBB/releases/download/v2021.9.0/
19-
TBB_INSTALL_DIR: oneapi-tbb-2021.9.0
20-
TBB_FN: oneapi-tbb-2021.9.0-lin.tgz
16+
DRIVER_PATH: 2024-WW25
17+
OCLCPUEXP_FN: oclcpuexp-2024.18.6.0.02_rel.tar.gz
18+
TBB_URL: https://github.com/oneapi-src/oneTBB/releases/download/v2021.12.0/
19+
TBB_INSTALL_DIR: oneapi-tbb-2021.12.0
20+
TBB_FN: oneapi-tbb-2021.12.0-lin.tgz
2121

2222
steps:
2323
- name: Cancel Previous Runs
@@ -159,6 +159,4 @@ jobs:
159159
SYCL_CACHE_PERSISTENT: 1
160160
run: |
161161
source set_allvars.sh
162-
# Skip the test that checks if there is only one hard
163-
# copy of DPCTLSyclInterface library
164-
python -m pytest -v dpctl/tests --no-sycl-interface-test
162+
python -m pytest -sv dpctl/tests

dpctl/tensor/libtensor/include/utils/offset_utils.hpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#pragma once
2828

2929
#include <algorithm>
30+
#include <exception>
3031
#include <sycl/sycl.hpp>
3132
#include <tuple>
3233
#include <vector>
@@ -81,6 +82,30 @@ std::vector<T, A> concat(std::vector<T, A> lhs, Vs &&...vs)
8182

8283
} // namespace detail
8384

85+
template <typename T>
86+
class usm_host_allocator : public sycl::usm_allocator<T, sycl::usm::alloc::host>
87+
{
88+
public:
89+
using baseT = sycl::usm_allocator<T, sycl::usm::alloc::host>;
90+
using baseT::baseT;
91+
92+
template <typename U> struct rebind
93+
{
94+
typedef usm_host_allocator<U> other;
95+
};
96+
97+
void deallocate(T *ptr, size_t n)
98+
{
99+
try {
100+
baseT::deallocate(ptr, n);
101+
} catch (const std::exception &e) {
102+
std::cerr
103+
<< "Exception caught in `usm_host_allocator::deallocate`: "
104+
<< e.what() << std::endl;
105+
}
106+
}
107+
};
108+
84109
template <typename indT, typename... Vs>
85110
std::tuple<indT *, size_t, sycl::event>
86111
device_allocate_and_pack(sycl::queue &q,
@@ -90,8 +115,7 @@ device_allocate_and_pack(sycl::queue &q,
90115

91116
// memory transfer optimization, use USM-host for temporary speeds up
92117
// transfer to device, especially on dGPUs
93-
using usm_host_allocatorT =
94-
sycl::usm_allocator<indT, sycl::usm::alloc::host>;
118+
using usm_host_allocatorT = usm_host_allocator<indT>;
95119
using shT = std::vector<indT, usm_host_allocatorT>;
96120

97121
usm_host_allocatorT usm_host_allocator(q);

dpctl/tensor/libtensor/source/integer_advanced_indexing.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "dpctl4pybind11.hpp"
3636
#include "kernels/integer_advanced_indexing.hpp"
3737
#include "utils/memory_overlap.hpp"
38+
#include "utils/offset_utils.hpp"
3839
#include "utils/output_validation.hpp"
3940
#include "utils/type_dispatch.hpp"
4041
#include "utils/type_utils.hpp"
@@ -91,15 +92,15 @@ _populate_kernel_params(sycl::queue &exec_q,
9192
{
9293

9394
using usm_host_allocator_T =
94-
sycl::usm_allocator<char *, sycl::usm::alloc::host>;
95+
dpctl::tensor::offset_utils::usm_host_allocator<char *>;
9596
using ptrT = std::vector<char *, usm_host_allocator_T>;
9697

9798
usm_host_allocator_T ptr_allocator(exec_q);
9899
std::shared_ptr<ptrT> host_ind_ptrs_shp =
99100
std::make_shared<ptrT>(k, ptr_allocator);
100101

101102
using usm_host_allocatorT =
102-
sycl::usm_allocator<py::ssize_t, sycl::usm::alloc::host>;
103+
dpctl::tensor::offset_utils::usm_host_allocator<py::ssize_t>;
103104
using shT = std::vector<py::ssize_t, usm_host_allocatorT>;
104105

105106
usm_host_allocatorT sz_allocator(exec_q);

dpctl/tensor/libtensor/source/triul_ctor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "kernels/constructors.hpp"
3333
#include "simplify_iteration_space.hpp"
3434
#include "utils/memory_overlap.hpp"
35+
#include "utils/offset_utils.hpp"
3536
#include "utils/output_validation.hpp"
3637
#include "utils/type_dispatch.hpp"
3738

@@ -150,7 +151,7 @@ usm_ndarray_triul(sycl::queue &exec_q,
150151
nd += 2;
151152

152153
using usm_host_allocatorT =
153-
sycl::usm_allocator<py::ssize_t, sycl::usm::alloc::host>;
154+
dpctl::tensor::offset_utils::usm_host_allocator<py::ssize_t>;
154155
using usmshT = std::vector<py::ssize_t, usm_host_allocatorT>;
155156

156157
usm_host_allocatorT allocator(exec_q);

dpctl/tests/test_usm_ndarray_print.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,6 @@ def test_print_repr(self):
283283
x = dpt.arange(4, dtype="i4", sycl_queue=q)
284284
x.sycl_queue.wait()
285285
r = repr(x)
286-
print(r)
287286
assert r == "usm_ndarray([0, 1, 2, 3], dtype=int32)"
288287

289288
dpt.set_print_options(linewidth=1)

0 commit comments

Comments
 (0)