From 6eb9a5234659380c136d18d97f353eea5a14106e Mon Sep 17 00:00:00 2001 From: "Chen, Cheng2" Date: Mon, 6 Nov 2023 11:17:47 +0800 Subject: [PATCH] using vector instead of vector --- tests/usm/usm_api.h | 95 +++++++-------------------------------------- 1 file changed, 15 insertions(+), 80 deletions(-) diff --git a/tests/usm/usm_api.h b/tests/usm/usm_api.h index e3b55b8cb..229d639b1 100644 --- a/tests/usm/usm_api.h +++ b/tests/usm/usm_api.h @@ -511,30 +511,34 @@ struct gen_buf_size_selector<0> { */ template class event_generator { + // Change vector to vector , since vector is + // stored bit-wise, and does not have data() member function. + using ContainType = typename std::conditional, + unsigned char, T>::type; sycl::range<1> rng{buf_size}; - std::vector arr_src; - std::vector arr_dst; - sycl::buffer buf_src; - sycl::buffer buf_dst; + std::vector arr_src; + std::vector arr_dst; + sycl::buffer buf_src; + sycl::buffer buf_dst; public: event_generator() : rng{buf_size}, - arr_src(buf_size, T{0}), - arr_dst(buf_size, T{0}), + arr_src(buf_size, ContainType{0}), + arr_dst(buf_size, ContainType{0}), buf_src{arr_src.data(), rng}, buf_dst{arr_dst.data(), rng} {} /** @brief Initialize arr_src with init_value and return sycl::event of * queue::submit() - * @param value Some non-zero (non-default) value of type T + * @param value Some non-zero (non-default) value of type ContainType */ - sycl::event init(sycl::queue &queue, T value) { + sycl::event init(sycl::queue& queue, ContainType value) { return queue.submit([&](sycl::handler &cgh) { auto acc_src = buf_src.template get_access(cgh); // single_task is used to make process long enough for testing purpose // The function being tested must wait for this task to complete. - cgh.single_task>([=] { + cgh.single_task>([=] { for (size_t i = 0; i < buf_size; ++i) { acc_src[i] = value; } @@ -545,77 +549,8 @@ class event_generator { /** @brief Copy data from arr_src to arr_dst for future check */ void copy_arrays(sycl::queue &queue) { - queue.submit([&](sycl::handler &cgh) { - using kernel_name = copy_arrays_kernel_name; - auto acc_src = buf_src.template get_access(cgh); - auto acc_dst = buf_dst.template get_access(cgh); - // Copy should be much faster then algorithm in 'init()' member function - // to detect situation when tested function doesn't wait for events - // provided as arguments - cgh.parallel_for(rng, [=](sycl::id<1> idx) { - const size_t i = idx[0]; - acc_dst[i] = acc_src[i]; - }); - }); - } - - /** @brief Check that elements of arrays are equal to each other and to - * value - * @param value The same value as value passed to init() member function - */ - bool check(T value) { - bool result = true; - auto acc_src = buf_src.template get_access(rng); - auto acc_dst = buf_dst.template get_access(rng); - for (size_t i = buf_size - 1; i + 1 > 0; --i) { - result = result && (acc_src[i] == acc_dst[i]); - result = result && (acc_dst[i] == value); - } - return result; - } -}; - -// Since the std::vector type does not have a data() member function, -// std::array is used instead. -template -class event_generator { - sycl::range<1> rng{buf_size}; - std::array arr_src; - std::array arr_dst; - sycl::buffer buf_src; - sycl::buffer buf_dst; - - public: - event_generator() - : rng{buf_size}, - buf_src{arr_src.data(), rng}, - buf_dst{arr_dst.data(), rng} { - arr_src.fill(bool{0}); - arr_dst.fill(bool{0}); - } - - /** @brief Initialize arr_src with init_value and return sycl::event of - * queue::submit() - * @param value Some non-zero (non-default) value of type bool - */ - sycl::event init(sycl::queue& queue, bool value) { - return queue.submit([&](sycl::handler& cgh) { - auto acc_src = buf_src.template get_access(cgh); - // single_task is used to make process long enough for testing purpose - // The function being tested must wait for this task to complete. - cgh.single_task>([=] { - for (size_t i = 0; i < buf_size; ++i) { - acc_src[i] = value; - } - }); - }); - } - - /** @brief Copy data from arr_src to arr_dst for future check - */ - void copy_arrays(sycl::queue& queue) { queue.submit([&](sycl::handler& cgh) { - using kernel_name = copy_arrays_kernel_name; + using kernel_name = copy_arrays_kernel_name; auto acc_src = buf_src.template get_access(cgh); auto acc_dst = buf_dst.template get_access(cgh); // Copy should be much faster then algorithm in 'init()' member function @@ -632,7 +567,7 @@ class event_generator { * value * @param value The same value as value passed to init() member function */ - bool check(bool value) { + bool check(ContainType value) { bool result = true; auto acc_src = buf_src.template get_access(rng); auto acc_dst = buf_dst.template get_access(rng);