Skip to content

Commit e3f7439

Browse files
Use capture initialization to avoid unnecessary copy of vector of shared_ptr
Since the vector is no longer used after it is captured by the lambda submitted via cgh.host_task, it should be moved rather than copied for efficiency.
1 parent 9f8f90b commit e3f7439

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

dpctl/tensor/libtensor/source/triul_ctor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,8 @@ usm_ndarray_triul(sycl::queue &exec_q,
206206
const auto &ctx = exec_q.get_context();
207207
using dpctl::tensor::alloc_utils::sycl_free_noexcept;
208208
cgh.host_task(
209-
[shp_host_shape_and_strides, dev_shape_and_strides, ctx]() {
209+
[shp_host_shape_and_strides = std::move(shp_host_shape_and_strides),
210+
dev_shape_and_strides, ctx]() {
210211
// capture of shp_host_shape_and_strides ensure the underlying
211212
// vector exists for the entire execution of copying kernel
212213
sycl_free_noexcept(dev_shape_and_strides, ctx);

0 commit comments

Comments
 (0)