From 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 20:24:20 +0200 Subject: Adding upstream version 14.2.21. Signed-off-by: Daniel Baumann --- src/boost/libs/compute/example/transform_sqrt.cpp | 58 +++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/boost/libs/compute/example/transform_sqrt.cpp (limited to 'src/boost/libs/compute/example/transform_sqrt.cpp') diff --git a/src/boost/libs/compute/example/transform_sqrt.cpp b/src/boost/libs/compute/example/transform_sqrt.cpp new file mode 100644 index 00000000..860063fc --- /dev/null +++ b/src/boost/libs/compute/example/transform_sqrt.cpp @@ -0,0 +1,58 @@ +//---------------------------------------------------------------------------// +// Copyright (c) 2013 Kyle Lutz +// +// Distributed under the Boost Software License, Version 1.0 +// See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt +// +// See http://boostorg.github.com/compute for more information. +//---------------------------------------------------------------------------// + +//[transform_sqrt_example + +#include +#include + +#include +#include +#include + +namespace compute = boost::compute; + +int main() +{ + // get default device and setup context + compute::device device = compute::system::default_device(); + compute::context context(device); + compute::command_queue queue(context, device); + + // generate random data on the host + std::vector host_vector(10000); + std::generate(host_vector.begin(), host_vector.end(), rand); + + // create a vector on the device + compute::vector device_vector(host_vector.size(), context); + + // transfer data from the host to the device + compute::copy( + host_vector.begin(), host_vector.end(), device_vector.begin(), queue + ); + + // calculate the square-root of each element in-place + compute::transform( + device_vector.begin(), + device_vector.end(), + device_vector.begin(), + compute::sqrt(), + queue + ); + + // copy values back to the host + compute::copy( + device_vector.begin(), device_vector.end(), host_vector.begin(), queue + ); + + return 0; +} + +//] -- cgit v1.2.3