├── .coveralls.yml ├── test ├── data │ ├── program.spirv32 │ ├── program.spirv64 │ ├── invalid_program.cl │ └── program.cl ├── check │ └── has_opencl.cpp ├── extra │ ├── test_multiple_objects2.cpp │ ├── test_multiple_objects1.cpp │ └── test_interop_opengl.cpp ├── opencl_version_check.hpp ├── test_unsupported_extension.cpp ├── test_sha1.cpp ├── test_pinned_allocator.cpp ├── test_buffer_allocator.cpp ├── test_no_device_found.cpp ├── test_context_error.cpp ├── context_setup.hpp ├── test_user_event.cpp ├── test_pipe.cpp ├── test_image3d.cpp ├── test_unique_copy.cpp ├── test_opencl_error.cpp ├── test_tabulate.cpp ├── test_functional_identity.cpp ├── test_malloc.cpp ├── test_result_of.cpp ├── test_functional_hash.cpp ├── test_partition_point.cpp ├── test_clamp_range.cpp ├── test_stable_partition.cpp ├── test_partial_sum.cpp ├── test_attach_user_queue_error.cpp ├── test_transform_if.cpp ├── test_bernoulli_distribution.cpp ├── test_functional_convert.cpp ├── test_stack.cpp ├── test_for_each.cpp ├── test_inplace_merge.cpp ├── test_functional_popcount.cpp ├── test_function_input_iterator.cpp ├── test_async_wait_guard.cpp └── test_platform.cpp ├── .gitignore ├── cmake └── BoostComputeConfig.cmake.in ├── meta └── libraries.json ├── index.html ├── include └── boost │ └── compute │ ├── image2d.hpp │ ├── image3d.hpp │ ├── source.hpp │ ├── wait_list.hpp │ ├── image_format.hpp │ ├── types │ └── builtin.hpp │ ├── image_sampler.hpp │ ├── interop │ ├── eigen.hpp │ ├── qt │ │ ├── qtgui.hpp │ │ ├── qpoint.hpp │ │ ├── qpointf.hpp │ │ ├── qtcore.hpp │ │ └── qvector.hpp │ ├── qt.hpp │ ├── opencv.hpp │ ├── opengl │ │ ├── gl.hpp │ │ ├── cl_gl.hpp │ │ └── cl_gl_ext.hpp │ ├── vtk.hpp │ ├── opengl.hpp │ ├── opencv │ │ ├── highgui.hpp │ │ └── ocl.hpp │ └── vtk │ │ └── matrix4x4.hpp │ ├── version.hpp │ ├── cl_ext.hpp │ ├── async.hpp │ ├── memory.hpp │ ├── allocator.hpp │ ├── utility.hpp │ ├── container │ └── string.hpp │ ├── lambda │ └── placeholder.hpp │ ├── random │ └── default_random_engine.hpp │ ├── lambda.hpp │ ├── exception.hpp │ ├── detail │ ├── assert_cl_success.hpp │ ├── getenv.hpp │ ├── is_buffer_iterator.hpp │ ├── iterator_traits.hpp │ ├── work_size.hpp │ ├── global_static.hpp │ ├── iterator_range_size.hpp │ └── literal.hpp │ ├── types.hpp │ ├── image.hpp │ ├── type_traits │ ├── detail │ │ └── capture_traits.hpp │ ├── is_vector_type.hpp │ ├── type_definition.hpp │ ├── result_of.hpp │ └── is_device_iterator.hpp │ ├── container.hpp │ ├── type_traits.hpp │ ├── functional │ ├── common.hpp │ ├── integer.hpp │ ├── detail │ │ ├── macros.hpp │ │ ├── nvidia_popcount.hpp │ │ └── nvidia_ballot.hpp │ ├── as.hpp │ ├── convert.hpp │ └── geometry.hpp │ ├── iterator.hpp │ ├── random.hpp │ ├── core.hpp │ ├── algorithm │ ├── generate_n.hpp │ ├── fill_n.hpp │ ├── for_each_n.hpp │ ├── all_of.hpp │ ├── none_of.hpp │ ├── binary_search.hpp │ └── find_if.hpp │ ├── functional.hpp │ ├── utility │ └── source.hpp │ ├── experimental │ ├── tabulate.hpp │ └── malloc.hpp │ ├── exception │ ├── no_device_found.hpp │ └── set_default_queue_error.hpp │ └── allocator │ └── pinned_allocator.hpp ├── doc ├── introduction.qbk ├── compute.qbk └── platforms_and_compilers.qbk ├── example ├── hello_world.cpp ├── memory_limits.cpp ├── copy_data.cpp ├── print_vector.cpp ├── mapped_view.cpp └── list_devices.cpp ├── perf ├── perf_stl_sort.cpp ├── perf_tbb_sort.cpp ├── perf_stl_merge.cpp ├── perf_stl_reverse.cpp ├── perf_stl_unique.cpp ├── perf_stl_search_n.cpp ├── perf_stl_rotate.cpp ├── perf_stl_max_element.cpp ├── perf_stl_includes.cpp ├── perf_stl_accumulate.cpp ├── perf_stl_search.cpp ├── perf_stl_find_end.cpp ├── perf_stl_partition.cpp ├── perf_bolt_fill.cpp ├── perf_stl_unique_copy.cpp ├── perf_stl_rotate_copy.cpp ├── perf_stl_count.cpp ├── perf_stl_inner_product.cpp ├── perf_stl_prev_permutation.cpp ├── perf_stl_stable_partition.cpp ├── perf_thrust_accumulate.cu ├── perf_stl_reverse_copy.cpp ├── perf_stl_next_permutation.cpp ├── perf_stl_partial_sum.cpp ├── perf_stl_is_permutation.cpp ├── perf_thrust_sort.cu ├── perf_thrust_unique.cu ├── perf_thrust_exclusive_scan.cu ├── perf_thrust_reverse.cu ├── perf_stl_partition_point.cpp ├── perf_thrust_reverse_copy.cu ├── perf_thrust_partial_sum.cu ├── perf_bernoulli_distribution.cpp ├── perf_stl_saxpy.cpp ├── perf_fill.cpp ├── perf_thrust_count.cu ├── perf_uniform_int_distribution.cpp └── perf_discrete_distribution.cpp └── LICENSE_1_0.txt /.coveralls.yml: -------------------------------------------------------------------------------- 1 | service_name: travis-ci 2 | -------------------------------------------------------------------------------- /test/data/program.spirv32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/compute/HEAD/test/data/program.spirv32 -------------------------------------------------------------------------------- /test/data/program.spirv64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/compute/HEAD/test/data/program.spirv64 -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # build directory 2 | build/ 3 | 4 | # python compiled files 5 | *.pyc 6 | 7 | # vim temp files 8 | .*.sw* 9 | 10 | # generated documentation 11 | bin/ 12 | doc/bin/ 13 | doc/html/ 14 | doc/autodoc.xml 15 | -------------------------------------------------------------------------------- /cmake/BoostComputeConfig.cmake.in: -------------------------------------------------------------------------------- 1 | # Config file for Boost.Compute (https://github.com/boostorg/compute) 2 | # 3 | # Sets the following variables: 4 | # BoostCompute_INCLUDE_DIRS - include directories for Boost.Compute 5 | 6 | set(BoostCompute_INCLUDE_DIRS "@CMAKE_INSTALL_PREFIX@/include/compute") 7 | -------------------------------------------------------------------------------- /meta/libraries.json: -------------------------------------------------------------------------------- 1 | { 2 | "key": "compute", 3 | "name": "Compute", 4 | "authors": [ 5 | "Kyle Lutz" 6 | ], 7 | "description": "Parallel/GPU-computing library", 8 | "category": [ 9 | "Concurrent" 10 | ], 11 | "maintainers": [ 12 | "Kyle Lutz " 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /test/check/has_opencl.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2017 Kohei Takahashi 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #include 12 | -------------------------------------------------------------------------------- /test/data/invalid_program.cl: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2017 Kristian Popov 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | __kernel void foo(__global int *input) { !@#$%^&*() } 11 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Automatic redirection failed, please go to 7 | doc/html/index.html 8 |
9 | 10 | Boost.Compute
11 |
12 | Copyright (C) 2013-2015 Kyle Lutz
13 |
14 | Distributed under the Boost Software License, Version 1.0. (See 15 | accompanying file LICENSE_1_0.txt or copy at 16 | http://www.boost.org/LICENSE_1_0.txt)
17 |
18 |
19 | 20 | 21 | -------------------------------------------------------------------------------- /test/extra/test_multiple_objects2.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #include 12 | 13 | bool dummy_function() { 14 | return true; 15 | } 16 | -------------------------------------------------------------------------------- /test/data/program.cl: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2017 Jakub Szuppe 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | __kernel void foobar(__global int* x) 12 | { 13 | const int gid = get_global_id(0); 14 | x[gid] = gid; 15 | } 16 | -------------------------------------------------------------------------------- /include/boost/compute/image2d.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2015 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | // deprecated, use instead 12 | #include 13 | -------------------------------------------------------------------------------- /include/boost/compute/image3d.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2015 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | // deprecated, use instead 12 | #include 13 | -------------------------------------------------------------------------------- /include/boost/compute/source.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | // deprecated, use instead 12 | #include 13 | -------------------------------------------------------------------------------- /include/boost/compute/wait_list.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | // deprecated, use instead 12 | #include 13 | -------------------------------------------------------------------------------- /include/boost/compute/image_format.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2015 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | // deprecated, use instead 12 | #include 13 | -------------------------------------------------------------------------------- /include/boost/compute/types/builtin.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | // deprecated, use instead 12 | #include 13 | -------------------------------------------------------------------------------- /include/boost/compute/image_sampler.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2015 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | // deprecated, use instead 12 | #include 13 | -------------------------------------------------------------------------------- /include/boost/compute/interop/eigen.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_INTEROP_EIGEN_HPP 12 | #define BOOST_COMPUTE_INTEROP_EIGEN_HPP 13 | 14 | #include 15 | 16 | #endif // BOOST_COMPUTE_INTEROP_EIGEN_HPP 17 | -------------------------------------------------------------------------------- /include/boost/compute/interop/qt/qtgui.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_INTEROP_QT_QTGUI_HPP 12 | #define BOOST_COMPUTE_INTEROP_QT_QTGUI_HPP 13 | 14 | #include 15 | 16 | #endif // BOOST_COMPUTE_INTEROP_QT_QTGUI_HPP 17 | -------------------------------------------------------------------------------- /include/boost/compute/interop/qt.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_INTEROP_QT_HPP 12 | #define BOOST_COMPUTE_INTEROP_QT_HPP 13 | 14 | #include 15 | #include 16 | 17 | #endif // BOOST_COMPUTE_INTEROP_QT_HPP 18 | -------------------------------------------------------------------------------- /include/boost/compute/version.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2015 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_VERSION_HPP 12 | #define BOOST_COMPUTE_VERSION_HPP 13 | 14 | #define BOOST_COMPUTE_VERSION_MAJOR 0 15 | #define BOOST_COMPUTE_VERSION_MINOR 5 16 | #define BOOST_COMPUTE_VERSION_PATCH 0 17 | 18 | #endif // BOOST_COMPUTE_VERSION_HPP 19 | -------------------------------------------------------------------------------- /include/boost/compute/interop/opencv.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_INTEROP_OPENCV_HPP 12 | #define BOOST_COMPUTE_INTEROP_OPENCV_HPP 13 | 14 | #include 15 | #include 16 | 17 | #endif // BOOST_COMPUTE_INTEROP_OPENCV_HPP 18 | -------------------------------------------------------------------------------- /include/boost/compute/interop/opengl/gl.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_INTEROP_OPENGL_GL_HPP 12 | #define BOOST_COMPUTE_INTEROP_OPENGL_GL_HPP 13 | 14 | #if defined(__APPLE__) 15 | #include 16 | #else 17 | #include 18 | #endif 19 | 20 | #endif // BOOST_COMPUTE_INTEROP_OPENGL_GL_HPP 21 | -------------------------------------------------------------------------------- /include/boost/compute/cl_ext.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_CL_EXT_HPP 12 | #define BOOST_COMPUTE_CL_EXT_HPP 13 | 14 | #include "detail/cl_versions.hpp" 15 | 16 | #if defined(__APPLE__) 17 | #include 18 | #else 19 | #include 20 | #endif 21 | 22 | #endif // BOOST_COMPUTE_CL_EXT_HPP 23 | -------------------------------------------------------------------------------- /include/boost/compute/interop/qt/qpoint.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_INTEROP_QT_QPOINT_HPP 12 | #define BOOST_COMPUTE_INTEROP_QT_QPOINT_HPP 13 | 14 | #include 15 | 16 | #include 17 | 18 | BOOST_COMPUTE_TYPE_NAME(QPoint, "int2") 19 | 20 | #endif // BOOST_COMPUTE_INTEROP_QT_QPOINT_HPP 21 | -------------------------------------------------------------------------------- /include/boost/compute/async.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_ASYNC_HPP 12 | #define BOOST_COMPUTE_ASYNC_HPP 13 | 14 | /// \file 15 | /// 16 | /// Meta-header to include all Boost.Compute async headers. 17 | 18 | #include 19 | #include 20 | 21 | #endif // BOOST_COMPUTE_ASYNC_HPP 22 | -------------------------------------------------------------------------------- /test/extra/test_multiple_objects1.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #define BOOST_TEST_MODULE TestMultipleObjects 12 | #include 13 | #include 14 | 15 | bool dummy_function(); 16 | 17 | BOOST_AUTO_TEST_CASE(multiple_objects) 18 | { 19 | // It is enough if the test compiles. 20 | BOOST_CHECK( dummy_function() ); 21 | } 22 | -------------------------------------------------------------------------------- /include/boost/compute/interop/qt/qpointf.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_INTEROP_QT_QPOINTF_HPP 12 | #define BOOST_COMPUTE_INTEROP_QT_QPOINTF_HPP 13 | 14 | #include 15 | 16 | #include 17 | 18 | BOOST_COMPUTE_TYPE_NAME(QPointF, "float2") 19 | 20 | #endif // BOOST_COMPUTE_INTEROP_QT_QPOINTF_HPP 21 | -------------------------------------------------------------------------------- /doc/introduction.qbk: -------------------------------------------------------------------------------- 1 | [/=========================================================================== 2 | Copyright (c) 2013-2015 Kyle Lutz 3 | 4 | Distributed under the Boost Software License, Version 1.0 5 | See accompanying file LICENSE_1_0.txt or copy at 6 | http://www.boost.org/LICENSE_1_0.txt 7 | =============================================================================/] 8 | 9 | [section:introduction Introduction] 10 | 11 | The Boost Compute library provides a C++ interface to multi-core CPU and GPGPU 12 | computing platforms based on [@http://en.wikipedia.org/wiki/OpenCL OpenCL]. 13 | 14 | The project is hosted on GitHub at [@https://github.com/boostorg/compute]. Click 15 | the arrow below to see the guide on [link boost_compute.getting_started Getting 16 | Started]. 17 | 18 | [endsect] 19 | -------------------------------------------------------------------------------- /include/boost/compute/interop/qt/qtcore.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_INTEROP_QT_QTCORE_HPP 12 | #define BOOST_COMPUTE_INTEROP_QT_QTCORE_HPP 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | #endif // BOOST_COMPUTE_INTEROP_QT_QTCORE_HPP 19 | -------------------------------------------------------------------------------- /include/boost/compute/memory.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_MEMORY_HPP 12 | #define BOOST_COMPUTE_MEMORY_HPP 13 | 14 | /// \file 15 | /// 16 | /// Meta-header to include all Boost.Compute memory headers. 17 | 18 | #include 19 | #include 20 | 21 | #endif // BOOST_COMPUTE_MEMORY_HPP 22 | -------------------------------------------------------------------------------- /include/boost/compute/interop/opengl/cl_gl.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_INTEROP_OPENGL_CL_GL_HPP 12 | #define BOOST_COMPUTE_INTEROP_OPENGL_CL_GL_HPP 13 | 14 | #include 15 | 16 | #if defined(__APPLE__) 17 | #include 18 | #else 19 | #include 20 | #endif 21 | 22 | #endif // BOOST_COMPUTE_INTEROP_OPENGL_CL_GL_HPP 23 | -------------------------------------------------------------------------------- /test/opencl_version_check.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2014 Denis Demidov 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_TEST_OPENCL_VERSION_CHECK_HPP 12 | #define BOOST_COMPUTE_TEST_OPENCL_VERSION_CHECK_HPP 13 | 14 | #define REQUIRES_OPENCL_VERSION(major, minor) \ 15 | if (!device.check_version(major, minor)) return 16 | 17 | #define REQUIRES_OPENCL_PLATFORM_VERSION(major, minor) \ 18 | if (!device.platform().check_version(major, minor)) return 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /include/boost/compute/allocator.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_ALLOCATOR_HPP 12 | #define BOOST_COMPUTE_ALLOCATOR_HPP 13 | 14 | /// \file 15 | /// 16 | /// Meta-header to include all Boost.Compute allocator headers. 17 | 18 | #include 19 | #include 20 | 21 | #endif // BOOST_COMPUTE_ALLOCATOR_HPP 22 | -------------------------------------------------------------------------------- /include/boost/compute/interop/vtk.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_INTEROP_VTK_HPP 12 | #define BOOST_COMPUTE_INTEROP_VTK_HPP 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #endif // BOOST_COMPUTE_INTEROP_VTK_HPP 20 | -------------------------------------------------------------------------------- /include/boost/compute/interop/opengl/cl_gl_ext.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_INTEROP_OPENGL_CL_GL_EXT_HPP 12 | #define BOOST_COMPUTE_INTEROP_OPENGL_CL_GL_EXT_HPP 13 | 14 | #include 15 | 16 | #if defined(__APPLE__) 17 | #include 18 | #else 19 | #include 20 | #endif 21 | 22 | #endif // BOOST_COMPUTE_INTEROP_OPENGL_CL_GL_EXT_HPP 23 | -------------------------------------------------------------------------------- /include/boost/compute/utility.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_UTILITY_HPP 12 | #define BOOST_COMPUTE_UTILITY_HPP 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #endif // BOOST_COMPUTE_UTILITY_HPP 22 | -------------------------------------------------------------------------------- /include/boost/compute/container/string.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_CONTAINER_STRING_HPP 12 | #define BOOST_COMPUTE_CONTAINER_STRING_HPP 13 | 14 | #include 15 | #include 16 | 17 | namespace boost { 18 | namespace compute { 19 | 20 | typedef basic_string string; 21 | 22 | } // end compute namespace 23 | } // end boost namespace 24 | 25 | #endif // BOOST_COMPUTE_CONTAINER_STRING_HPP 26 | -------------------------------------------------------------------------------- /include/boost/compute/lambda/placeholder.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_LAMBDA_PLACEHOLDER_HPP 12 | #define BOOST_COMPUTE_LAMBDA_PLACEHOLDER_HPP 13 | 14 | namespace boost { 15 | namespace compute { 16 | namespace lambda { 17 | 18 | // lambda placeholder type 19 | template 20 | struct placeholder 21 | { 22 | }; 23 | 24 | } // end lambda namespace 25 | } // end compute namespace 26 | } // end boost namespace 27 | 28 | #endif // BOOST_COMPUTE_LAMBDA_PLACEHOLDER_HPP 29 | -------------------------------------------------------------------------------- /include/boost/compute/random/default_random_engine.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_RANDOM_DEFAULT_RANDOM_ENGINE_HPP 12 | #define BOOST_COMPUTE_RANDOM_DEFAULT_RANDOM_ENGINE_HPP 13 | 14 | #include 15 | 16 | namespace boost { 17 | namespace compute { 18 | 19 | typedef mt19937 default_random_engine; 20 | 21 | } // end compute namespace 22 | } // end boost namespace 23 | 24 | #endif // BOOST_COMPUTE_RANDOM_DEFAULT_RANDOM_ENGINE_HPP 25 | -------------------------------------------------------------------------------- /test/test_unsupported_extension.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2014 Fabian Köhler 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | #define BOOST_TEST_MODULE TestUnsupportedExtension 11 | #include 12 | #include 13 | 14 | BOOST_AUTO_TEST_CASE(unsupported_extension_error_what) 15 | { 16 | boost::compute::unsupported_extension_error error("CL_DUMMY_EXTENSION"); 17 | BOOST_CHECK_EQUAL(std::string(error.what()), std::string("OpenCL extension CL_DUMMY_EXTENSION not supported")); 18 | } 19 | -------------------------------------------------------------------------------- /include/boost/compute/lambda.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_LAMBDA_HPP 12 | #define BOOST_COMPUTE_LAMBDA_HPP 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #endif // BOOST_COMPUTE_LAMBDA_HPP 23 | -------------------------------------------------------------------------------- /include/boost/compute/exception.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_EXCEPTION_HPP 12 | #define BOOST_COMPUTE_EXCEPTION_HPP 13 | 14 | /// \file 15 | /// 16 | /// Meta-header to include all Boost.Compute exception headers. 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #endif // BOOST_COMPUTE_EXCEPTION_HPP 24 | -------------------------------------------------------------------------------- /include/boost/compute/detail/assert_cl_success.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_DETAIL_ASSERT_CL_SUCCESS_HPP 12 | #define BOOST_COMPUTE_DETAIL_ASSERT_CL_SUCCESS_HPP 13 | 14 | #include 15 | 16 | #if defined(BOOST_DISABLE_ASSERTS) || defined(NDEBUG) 17 | #define BOOST_COMPUTE_ASSERT_CL_SUCCESS(function) \ 18 | function 19 | #else 20 | #define BOOST_COMPUTE_ASSERT_CL_SUCCESS(function) \ 21 | BOOST_ASSERT(function == CL_SUCCESS) 22 | #endif 23 | 24 | #endif // BOOST_COMPUTE_DETAIL_ASSERT_CL_SUCCESS_HPP 25 | -------------------------------------------------------------------------------- /include/boost/compute/types.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_TYPES_HPP 12 | #define BOOST_COMPUTE_TYPES_HPP 13 | 14 | /// \file 15 | /// 16 | /// Meta-header to include all Boost.Compute types headers. 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #endif // BOOST_COMPUTE_TYPES_HPP 26 | -------------------------------------------------------------------------------- /example/hello_world.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | //[hello_world_example 12 | 13 | #include 14 | 15 | #include 16 | 17 | namespace compute = boost::compute; 18 | 19 | int main() 20 | { 21 | // get the default device 22 | compute::device device = compute::system::default_device(); 23 | 24 | // print the device's name and platform 25 | std::cout << "hello from " << device.name(); 26 | std::cout << " (platform: " << device.platform().name() << ")" << std::endl; 27 | 28 | return 0; 29 | } 30 | //] 31 | -------------------------------------------------------------------------------- /test/test_sha1.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Peter Dimov 2 | // Distributed under the Boost Software License, Version 1.0 3 | // https://www.boost.org/LICENSE_1_0.txt 4 | 5 | #include 6 | #include 7 | 8 | std::string digest( std::string const& s ) 9 | { 10 | boost::compute::detail::sha1 h; 11 | h.process( s ); 12 | return h; 13 | } 14 | 15 | int main() 16 | { 17 | // https://en.wikipedia.org/wiki/SHA-1#Example_hashes 18 | 19 | BOOST_TEST_EQ( 20 | digest( "The quick brown fox jumps over the lazy dog" ), 21 | std::string( "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12" ) ); 22 | 23 | BOOST_TEST_EQ( 24 | digest( "The quick brown fox jumps over the lazy cog" ), 25 | std::string( "de9f2c7fd25e1b3afad3e85a0bd17d9b100db4b3" ) ); 26 | 27 | BOOST_TEST_EQ( 28 | digest( "" ), 29 | std::string( "da39a3ee5e6b4b0d3255bfef95601890afd80709" ) ); 30 | 31 | return boost::report_errors(); 32 | } 33 | -------------------------------------------------------------------------------- /include/boost/compute/image.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2015 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_IMAGE_HPP 12 | #define BOOST_COMPUTE_IMAGE_HPP 13 | 14 | /// \file 15 | /// 16 | /// Meta-header to include all Boost.Compute image headers. 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #endif // BOOST_COMPUTE_IMAGE_HPP 26 | -------------------------------------------------------------------------------- /test/extra/test_interop_opengl.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #define BOOST_TEST_MODULE TestInteropOpenGL 12 | #include 13 | 14 | #include 15 | 16 | BOOST_AUTO_TEST_CASE(opengl_buffer) 17 | { 18 | } 19 | 20 | BOOST_AUTO_TEST_CASE(type_name) 21 | { 22 | BOOST_CHECK_EQUAL( 23 | boost::compute::type_name(), "image2d_t" 24 | ); 25 | BOOST_CHECK_EQUAL( 26 | boost::compute::type_name(), "image2d_t" 27 | ); 28 | } 29 | -------------------------------------------------------------------------------- /test/test_pinned_allocator.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #define BOOST_TEST_MODULE TestPinnedAllocator 12 | #include 13 | 14 | #include 15 | #include 16 | 17 | #include "context_setup.hpp" 18 | 19 | namespace compute = boost::compute; 20 | 21 | BOOST_AUTO_TEST_CASE(vector_with_pinned_allocator) 22 | { 23 | compute::vector > vector(context); 24 | vector.push_back(12, queue); 25 | } 26 | 27 | BOOST_AUTO_TEST_SUITE_END() 28 | -------------------------------------------------------------------------------- /test/test_buffer_allocator.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #define BOOST_TEST_MODULE TestBufferAllocator 12 | #include 13 | 14 | #include 15 | 16 | #include "context_setup.hpp" 17 | 18 | namespace compute = boost::compute; 19 | 20 | BOOST_AUTO_TEST_CASE(allocate) 21 | { 22 | compute::buffer_allocator allocator(context); 23 | 24 | typedef compute::buffer_allocator::pointer pointer; 25 | pointer x = allocator.allocate(10); 26 | allocator.deallocate(x, 10); 27 | } 28 | 29 | BOOST_AUTO_TEST_SUITE_END() 30 | -------------------------------------------------------------------------------- /include/boost/compute/interop/opengl.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_INTEROP_OPENGL_HPP 12 | #define BOOST_COMPUTE_INTEROP_OPENGL_HPP 13 | 14 | /// \file 15 | /// 16 | /// Meta-header to include all Boost.Compute OpenGL interop headers. 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #endif // BOOST_COMPUTE_INTEROP_OPENGL_HPP 25 | -------------------------------------------------------------------------------- /test/test_no_device_found.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2015 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #define BOOST_TEST_MODULE TestNoDeviceFound 12 | #include 13 | 14 | #include 15 | 16 | void throw_no_device_found() 17 | { 18 | throw boost::compute::no_device_found(); 19 | } 20 | 21 | BOOST_AUTO_TEST_CASE(what) 22 | { 23 | try { 24 | throw_no_device_found(); 25 | 26 | BOOST_REQUIRE(false); // should not get here 27 | } 28 | catch(boost::compute::no_device_found& e){ 29 | BOOST_CHECK_EQUAL(std::string(e.what()), "No OpenCL device found"); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /perf/perf_stl_sort.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #include 12 | #include 13 | 14 | #include "perf.hpp" 15 | 16 | int main(int argc, char *argv[]) 17 | { 18 | perf_parse_args(argc, argv); 19 | 20 | std::cout << "size: " << PERF_N << std::endl; 21 | 22 | std::vector v; 23 | perf_timer t; 24 | for(size_t trial = 0; trial < PERF_TRIALS; trial++){ 25 | v = generate_random_vector(PERF_N); 26 | t.start(); 27 | std::sort(v.begin(), v.end()); 28 | t.stop(); 29 | } 30 | std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl; 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /include/boost/compute/detail/getenv.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_DETAIL_GETENV_HPP 12 | #define BOOST_COMPUTE_DETAIL_GETENV_HPP 13 | 14 | #include 15 | 16 | namespace boost { 17 | namespace compute { 18 | namespace detail { 19 | 20 | inline const char* getenv(const char *env_var) 21 | { 22 | #ifdef _MSC_VER 23 | # pragma warning(push) 24 | # pragma warning(disable: 4996) 25 | #endif 26 | return std::getenv(env_var); 27 | #ifdef _MSC_VER 28 | # pragma warning(pop) 29 | #endif 30 | } 31 | 32 | } // end detail namespace 33 | } // end compute namespace 34 | } // end boost namespace 35 | 36 | #endif // BOOST_COMPUTE_DETAIL_GETENV_HPP 37 | -------------------------------------------------------------------------------- /include/boost/compute/detail/is_buffer_iterator.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_DETAIL_IS_BUFFER_ITERATOR_HPP 12 | #define BOOST_COMPUTE_DETAIL_IS_BUFFER_ITERATOR_HPP 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | namespace boost { 19 | namespace compute { 20 | namespace detail { 21 | 22 | // default = false 23 | template 24 | struct is_buffer_iterator : public boost::false_type {}; 25 | 26 | } // end detail namespace 27 | } // end compute namespace 28 | } // end boost namespace 29 | 30 | #endif // BOOST_COMPUTE_DETAIL_IS_BUFFER_ITERATOR_HPP 31 | -------------------------------------------------------------------------------- /test/test_context_error.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2014 Fabian Köhler 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #define BOOST_TEST_MODULE TestContextError 12 | #include 13 | 14 | #include 15 | #include 16 | 17 | BOOST_AUTO_TEST_CASE(what) 18 | { 19 | boost::compute::context context = boost::compute::system::default_context(); 20 | boost::compute::context_error error(&context, "Test", 0, 0); 21 | BOOST_CHECK_EQUAL(std::string(error.what()), std::string("Test")); 22 | BOOST_CHECK(*error.get_context_ptr() == context); 23 | BOOST_CHECK(error.get_private_info_ptr() == 0); 24 | BOOST_CHECK(error.get_private_info_size() == 0); 25 | } 26 | -------------------------------------------------------------------------------- /include/boost/compute/type_traits/detail/capture_traits.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_TYPE_TRAITS_DETAIL_CAPTURE_TRAITS_HPP 12 | #define BOOST_COMPUTE_TYPE_TRAITS_DETAIL_CAPTURE_TRAITS_HPP 13 | 14 | #include 15 | 16 | namespace boost { 17 | namespace compute { 18 | namespace detail { 19 | 20 | template 21 | struct capture_traits 22 | { 23 | static std::string type_name() 24 | { 25 | return ::boost::compute::type_name(); 26 | } 27 | }; 28 | 29 | } // end detail namespace 30 | } // end compute namespace 31 | } // end boost namespace 32 | 33 | #endif // BOOST_COMPUTE_TYPE_TRAITS_DETAIL_CAPTURE_TRAITS_HPP 34 | -------------------------------------------------------------------------------- /include/boost/compute/container.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_CONTAINER_HPP 12 | #define BOOST_COMPUTE_CONTAINER_HPP 13 | 14 | /// \file 15 | /// 16 | /// Meta-header to include all Boost.Compute container headers. 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #endif // BOOST_COMPUTE_CONTAINER_HPP 28 | -------------------------------------------------------------------------------- /perf/perf_tbb_sort.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | #include "perf.hpp" 17 | 18 | int main(int argc, char *argv[]) 19 | { 20 | perf_parse_args(argc, argv); 21 | 22 | std::cout << "size: " << PERF_N << std::endl; 23 | std::vector v(PERF_N); 24 | 25 | perf_timer t; 26 | for(size_t trial = 0; trial < PERF_TRIALS; trial++){ 27 | v = generate_random_vector(PERF_N); 28 | t.start(); 29 | tbb::parallel_sort(v.begin(), v.end()); 30 | t.stop(); 31 | } 32 | std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl; 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /test/context_setup.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Denis Demidov 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_TEST_CONTEXT_SETUP_HPP 12 | #define BOOST_COMPUTE_TEST_CONTEXT_SETUP_HPP 13 | 14 | #include 15 | #include 16 | 17 | #include "opencl_version_check.hpp" 18 | 19 | struct Context { 20 | boost::compute::device device; 21 | boost::compute::context context; 22 | boost::compute::command_queue queue; 23 | 24 | Context() : 25 | device ( boost::compute::system::default_device() ), 26 | context( boost::compute::system::default_context() ), 27 | queue ( boost::compute::system::default_queue() ) 28 | {} 29 | }; 30 | 31 | BOOST_FIXTURE_TEST_SUITE(compute_test, Context) 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /test/test_user_event.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #define BOOST_TEST_MODULE TestUserEvent 12 | #include 13 | 14 | #include 15 | 16 | #include "context_setup.hpp" 17 | 18 | BOOST_AUTO_TEST_CASE(empty){} 19 | 20 | #ifdef BOOST_COMPUTE_CL_VERSION_1_1 21 | BOOST_AUTO_TEST_CASE(user_event) 22 | { 23 | REQUIRES_OPENCL_VERSION(1, 1); 24 | 25 | boost::compute::user_event event(context); 26 | BOOST_CHECK(event.get() != cl_event()); 27 | BOOST_CHECK(event.status() != CL_COMPLETE); 28 | 29 | event.set_status(CL_COMPLETE); 30 | event.wait(); 31 | BOOST_CHECK(event.status() == CL_COMPLETE); 32 | } 33 | #endif // BOOST_COMPUTE_CL_VERSION_1_1 34 | 35 | BOOST_AUTO_TEST_SUITE_END() 36 | -------------------------------------------------------------------------------- /test/test_pipe.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #define BOOST_TEST_MODULE TestPipe 12 | #include 13 | 14 | #include 15 | #include 16 | 17 | #include "context_setup.hpp" 18 | 19 | namespace compute = boost::compute; 20 | 21 | BOOST_AUTO_TEST_CASE(empty) 22 | { 23 | } 24 | 25 | #ifdef BOOST_COMPUTE_CL_VERSION_2_0 26 | BOOST_AUTO_TEST_CASE(create_pipe) 27 | { 28 | REQUIRES_OPENCL_VERSION(2, 0); 29 | 30 | compute::pipe pipe(context, 16 * sizeof(float), 128); 31 | BOOST_CHECK_EQUAL(pipe.get_info(), 64); 32 | BOOST_CHECK_EQUAL(pipe.get_info(), 128); 33 | } 34 | #endif // BOOST_COMPUTE_CL_VERSION_2_0 35 | 36 | BOOST_AUTO_TEST_SUITE_END() 37 | -------------------------------------------------------------------------------- /doc/compute.qbk: -------------------------------------------------------------------------------- 1 | [/=========================================================================== 2 | Copyright (c) 2013-2015 Kyle Lutz 3 | 4 | Distributed under the Boost Software License, Version 1.0 5 | See accompanying file LICENSE_1_0.txt or copy at 6 | http://www.boost.org/LICENSE_1_0.txt 7 | =============================================================================/] 8 | 9 | [library Boost.Compute 10 | [quickbook 1.5] 11 | [authors [Lutz, Kyle]] 12 | [copyright 2013-2014 Kyle Lutz] 13 | [purpose A multi-core/GPGPU computing library] 14 | [category concurrent] 15 | [id compute] 16 | [dirname compute] 17 | [license 18 | Distributed under the Boost Software License, Version 1.0. 19 | (See accompanying file LICENSE_1_0.txt or copy at 20 | [@http://www.boost.org/LICENSE_1_0.txt]) 21 | ] 22 | ] 23 | 24 | [include introduction.qbk] 25 | [include getting_started.qbk] 26 | [include design.qbk] 27 | [include tutorial.qbk] 28 | [include advanced_topics.qbk] 29 | [include interop.qbk] 30 | [include porting_guide.qbk] 31 | [include platforms_and_compilers.qbk] 32 | [include reference.qbk] 33 | [include performance.qbk] 34 | [include faq.qbk] 35 | -------------------------------------------------------------------------------- /include/boost/compute/interop/opencv/highgui.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_INTEROP_OPENCV_HIGHGUI_HPP 12 | #define BOOST_COMPUTE_INTEROP_OPENCV_HIGHGUI_HPP 13 | 14 | #include 15 | 16 | #include 17 | 18 | namespace boost { 19 | namespace compute { 20 | 21 | inline void opencv_imshow(const std::string &winname, 22 | const image2d &image, 23 | command_queue &queue = system::default_queue()) 24 | { 25 | const cv::Mat mat = opencv_create_mat_with_image2d(image, queue); 26 | 27 | cv::imshow(winname, mat); 28 | } 29 | 30 | } // end compute namespace 31 | } // end boost namespace 32 | 33 | #endif // BOOST_COMPUTE_INTEROP_OPENCV_HIGHGUI_HPP 34 | -------------------------------------------------------------------------------- /include/boost/compute/type_traits.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_TYPE_TRAITS_HPP 12 | #define BOOST_COMPUTE_TYPE_TRAITS_HPP 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #endif // BOOST_COMPUTE_TYPE_TRAITS_HPP 26 | -------------------------------------------------------------------------------- /test/test_image3d.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2015 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #define BOOST_TEST_MODULE TestImage3D 12 | #include 13 | 14 | #include 15 | #include 16 | 17 | #include "context_setup.hpp" 18 | 19 | namespace compute = boost::compute; 20 | 21 | BOOST_AUTO_TEST_CASE(image3d_get_supported_formats) 22 | { 23 | const std::vector formats = 24 | compute::image3d::get_supported_formats(context); 25 | } 26 | 27 | // check type_name() for image3d 28 | BOOST_AUTO_TEST_CASE(image3d_type_name) 29 | { 30 | BOOST_CHECK( 31 | std::strcmp( 32 | boost::compute::type_name(), "image3d_t" 33 | ) == 0 34 | ); 35 | } 36 | 37 | BOOST_AUTO_TEST_SUITE_END() 38 | -------------------------------------------------------------------------------- /include/boost/compute/functional/common.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_FUNCTIONAL_COMMON_HPP 12 | #define BOOST_COMPUTE_FUNCTIONAL_COMMON_HPP 13 | 14 | #include 15 | 16 | namespace boost { 17 | namespace compute { 18 | 19 | BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(clamp, T (T, T, T), class T) 20 | BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(degrees, T (T), class T) 21 | BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(radians, T (T), class T) 22 | BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(sign, T (T), class T) 23 | BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(smoothstep, T (T, T, T), class T) 24 | BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(step, T (T, T), class T) 25 | 26 | } // end compute namespace 27 | } // end boost namespace 28 | 29 | #endif // BOOST_COMPUTE_FUNCTIONAL_COMMON_HPP 30 | -------------------------------------------------------------------------------- /include/boost/compute/iterator.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_ITERATOR_HPP 12 | #define BOOST_COMPUTE_ITERATOR_HPP 13 | 14 | /// \file 15 | /// 16 | /// Meta-header to include all Boost.Compute iterator headers. 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #endif // BOOST_COMPUTE_ITERATOR_HPP 29 | -------------------------------------------------------------------------------- /include/boost/compute/random.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_RANDOM_HPP 12 | #define BOOST_COMPUTE_RANDOM_HPP 13 | 14 | /// \file 15 | /// 16 | /// Meta-header to include all Boost.Compute random headers. 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #endif // BOOST_COMPUTE_RANDOM_HPP 29 | -------------------------------------------------------------------------------- /include/boost/compute/core.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_CORE_HPP 12 | #define BOOST_COMPUTE_CORE_HPP 13 | 14 | /// \file 15 | /// 16 | /// Meta-header to include all Boost.Compute core headers. 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #endif // BOOST_COMPUTE_CORE_HPP 34 | -------------------------------------------------------------------------------- /include/boost/compute/type_traits/is_vector_type.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_TYPE_TRAITS_IS_VECTOR_TYPE_HPP 12 | #define BOOST_COMPUTE_TYPE_TRAITS_IS_VECTOR_TYPE_HPP 13 | 14 | #include 15 | 16 | #include 17 | 18 | namespace boost { 19 | namespace compute { 20 | 21 | /// Meta-function returning \c true if \p T is a vector type. 22 | /// 23 | /// For example, 24 | /// \code 25 | /// is_vector_type::value == false 26 | /// is_vector_type::value == true 27 | /// \endcode 28 | /// 29 | /// \see make_vector_type, vector_size 30 | template 31 | struct is_vector_type : boost::mpl::bool_::value != 1> 32 | { 33 | }; 34 | 35 | } // end compute namespace 36 | } // end boost namespace 37 | 38 | #endif // BOOST_COMPUTE_TYPE_TRAITS_IS_VECTOR_TYPE_HPP 39 | -------------------------------------------------------------------------------- /include/boost/compute/functional/integer.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_FUNCTIONAL_INTEGER_HPP 12 | #define BOOST_COMPUTE_FUNCTIONAL_INTEGER_HPP 13 | 14 | #include 15 | 16 | namespace boost { 17 | namespace compute { 18 | 19 | BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(abs, T (T), class T) 20 | BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(abs_diff, T (T, T), class T) 21 | BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(add_sat, T (T, T), class T) 22 | BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(hadd, T (T, T), class T) 23 | BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(rhadd, T (T, T), class T) 24 | BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(max, T (T, T), class T) 25 | BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(min, T (T, T), class T) 26 | 27 | } // end compute namespace 28 | } // end boost namespace 29 | 30 | #endif // BOOST_COMPUTE_FUNCTIONAL_INTEGER_HPP 31 | -------------------------------------------------------------------------------- /include/boost/compute/detail/iterator_traits.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_DETAIL_ITERATOR_TRAITS_HPP 12 | #define BOOST_COMPUTE_DETAIL_ITERATOR_TRAITS_HPP 13 | 14 | #include 15 | 16 | #include 17 | #include 18 | 19 | namespace boost { 20 | namespace compute { 21 | namespace detail { 22 | 23 | template 24 | struct iterator_traits : public std::iterator_traits 25 | { 26 | static const bool is_contiguous = is_contiguous_iterator::value; 27 | static const bool is_on_device = is_device_iterator::value; 28 | static const bool is_on_host = !is_on_device; 29 | }; 30 | 31 | } // end detail namespace 32 | } // end compute namespace 33 | } // end boost namespace 34 | 35 | #endif // BOOST_COMPUTE_ITERATOR_TRAITS_HPP 36 | -------------------------------------------------------------------------------- /test/test_unique_copy.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2014 Roshan 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #define BOOST_TEST_MODULE TestUniqueCopy 12 | #include 13 | 14 | #include 15 | #include 16 | 17 | #include "check_macros.hpp" 18 | #include "context_setup.hpp" 19 | 20 | namespace bc = boost::compute; 21 | namespace compute = boost::compute; 22 | 23 | BOOST_AUTO_TEST_CASE(unique_copy_int) 24 | { 25 | int data[] = {1, 6, 6, 4, 2, 2, 4}; 26 | 27 | bc::vector input(data, data + 7, queue); 28 | bc::vector result(5, context); 29 | 30 | bc::vector::iterator iter = 31 | bc::unique_copy(input.begin(), input.end(), result.begin(), queue); 32 | 33 | BOOST_VERIFY(iter == result.begin() + 5); 34 | CHECK_RANGE_EQUAL(int, 5, result, (1, 6, 4, 2, 4)); 35 | } 36 | 37 | BOOST_AUTO_TEST_SUITE_END() 38 | -------------------------------------------------------------------------------- /include/boost/compute/type_traits/type_definition.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_TYPE_TRAITS_TYPE_DEFINITION_HPP 12 | #define BOOST_COMPUTE_TYPE_TRAITS_TYPE_DEFINITION_HPP 13 | 14 | #include 15 | 16 | namespace boost { 17 | namespace compute { 18 | namespace detail { 19 | 20 | template 21 | struct type_definition_trait 22 | { 23 | static std::string value() { return std::string(); } 24 | }; 25 | 26 | } // end detail namespace 27 | 28 | /// Returns the OpenCL type definition for \c T. 29 | /// 30 | /// \return a string containing the type definition for \c T 31 | /// 32 | /// \see type_name() 33 | template 34 | inline std::string type_definition() 35 | { 36 | return detail::type_definition_trait::value(); 37 | } 38 | 39 | } // end compute namespace 40 | } // end boost namespace 41 | 42 | #endif // BOOST_COMPUTE_TYPE_TRAITS_TYPE_DEFINITION_HPP 43 | -------------------------------------------------------------------------------- /test/test_opencl_error.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #define BOOST_TEST_MODULE TestOpenCLError 12 | #include 13 | 14 | #include 15 | 16 | #include "check_macros.hpp" 17 | #include "context_setup.hpp" 18 | 19 | BOOST_AUTO_TEST_CASE(error_to_string) 20 | { 21 | using boost::compute::opencl_error; 22 | 23 | BOOST_CHECK_EQUAL(opencl_error::to_string(CL_SUCCESS), "Success"); 24 | BOOST_CHECK_EQUAL(opencl_error::to_string(CL_INVALID_VALUE), "Invalid Value"); 25 | BOOST_CHECK_EQUAL(opencl_error::to_string(-123456), "Unknown OpenCL Error (-123456)"); 26 | } 27 | 28 | BOOST_AUTO_TEST_CASE(error_code) 29 | { 30 | boost::compute::opencl_error e(CL_INVALID_DEVICE); 31 | BOOST_CHECK_EQUAL(e.error_code(), CL_INVALID_DEVICE); 32 | BOOST_CHECK_EQUAL(e.error_string(), "Invalid Device"); 33 | } 34 | 35 | BOOST_AUTO_TEST_SUITE_END() 36 | -------------------------------------------------------------------------------- /test/test_tabulate.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #define BOOST_TEST_MODULE TestTabulate 12 | #include 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #include "check_macros.hpp" 21 | #include "context_setup.hpp" 22 | 23 | namespace compute = boost::compute; 24 | 25 | BOOST_AUTO_TEST_CASE(tabulate_negative_int) 26 | { 27 | BOOST_COMPUTE_FUNCTION(int, negate, (int x), 28 | { 29 | return -x; 30 | }); 31 | 32 | compute::vector vector(10, context); 33 | compute::experimental::tabulate(vector.begin(), vector.end(), negate, queue); 34 | CHECK_RANGE_EQUAL(int, 10, vector, (0, -1, -2, -3, -4, -5, -6, -7, -8, -9)); 35 | } 36 | 37 | BOOST_AUTO_TEST_SUITE_END() 38 | -------------------------------------------------------------------------------- /perf/perf_stl_merge.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "perf.hpp" 16 | 17 | int main(int argc, char *argv[]) 18 | { 19 | perf_parse_args(argc, argv); 20 | 21 | std::cout << "size: " << PERF_N << std::endl; 22 | std::vector v1 = generate_random_vector(std::floor(PERF_N / 2.0)); 23 | std::vector v2 = generate_random_vector(std::ceil(PERF_N / 2.0)); 24 | std::vector v3(PERF_N); 25 | 26 | std::sort(v1.begin(), v1.end()); 27 | std::sort(v2.begin(), v2.end()); 28 | 29 | perf_timer t; 30 | for(size_t trial = 0; trial < PERF_TRIALS; trial++){ 31 | t.start(); 32 | std::merge(v1.begin(), v1.end(), v2.begin(), v2.end(), v3.begin()); 33 | t.stop(); 34 | } 35 | std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl; 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /perf/perf_stl_reverse.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2014 Roshan 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include "perf.hpp" 17 | 18 | int rand_int() 19 | { 20 | return static_cast((rand() / double(RAND_MAX)) * 25.0); 21 | } 22 | 23 | int main(int argc, char *argv[]) 24 | { 25 | perf_parse_args(argc, argv); 26 | std::cout << "size: " << PERF_N << std::endl; 27 | 28 | // create vector of random numbers on the host 29 | std::vector host_vector(PERF_N); 30 | std::generate(host_vector.begin(), host_vector.end(), rand_int); 31 | 32 | perf_timer t; 33 | for(size_t trial = 0; trial < PERF_TRIALS; trial++){ 34 | t.start(); 35 | std::reverse(host_vector.begin(), host_vector.end()); 36 | t.stop(); 37 | } 38 | std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl; 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /perf/perf_stl_unique.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2014 Roshan 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include "perf.hpp" 17 | 18 | int rand_int() 19 | { 20 | return static_cast((rand() / double(RAND_MAX)) * 25.0); 21 | } 22 | 23 | int main(int argc, char *argv[]) 24 | { 25 | perf_parse_args(argc, argv); 26 | std::cout << "size: " << PERF_N << std::endl; 27 | 28 | // create vector of random numbers on the host 29 | std::vector host_vector(PERF_N); 30 | 31 | perf_timer t; 32 | for(size_t trial = 0; trial < PERF_TRIALS; trial++){ 33 | std::generate(host_vector.begin(), host_vector.end(), rand_int); 34 | t.start(); 35 | std::unique(host_vector.begin(), host_vector.end()); 36 | t.stop(); 37 | } 38 | std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl; 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /perf/perf_stl_search_n.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2014 Roshan 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include "perf.hpp" 17 | 18 | int rand_int() 19 | { 20 | return static_cast((rand() / double(RAND_MAX)) * 25.0); 21 | } 22 | 23 | int main(int argc, char *argv[]) 24 | { 25 | perf_parse_args(argc, argv); 26 | std::cout << "size: " << PERF_N << std::endl; 27 | 28 | // create vector of random numbers on the host 29 | std::vector host_vector(PERF_N); 30 | std::generate(host_vector.begin(), host_vector.end(), rand_int); 31 | 32 | perf_timer t; 33 | for(size_t trial = 0; trial < PERF_TRIALS; trial++){ 34 | t.start(); 35 | std::search_n(host_vector.begin(), host_vector.end(), 5, 2); 36 | t.stop(); 37 | } 38 | std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl; 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /perf/perf_stl_rotate.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2014 Roshan 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include "perf.hpp" 17 | 18 | int rand_int() 19 | { 20 | return static_cast((rand() / double(RAND_MAX)) * 25.0); 21 | } 22 | 23 | int main(int argc, char *argv[]) 24 | { 25 | perf_parse_args(argc, argv); 26 | std::cout << "size: " << PERF_N << std::endl; 27 | 28 | // create vector of random numbers on the host 29 | std::vector host_vector(PERF_N); 30 | std::generate(host_vector.begin(), host_vector.end(), rand_int); 31 | 32 | perf_timer t; 33 | for(size_t trial = 0; trial < PERF_TRIALS; trial++){ 34 | t.start(); 35 | std::rotate(host_vector.begin(), host_vector.begin()+(PERF_N/2), host_vector.end()); 36 | t.stop(); 37 | } 38 | std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl; 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /example/memory_limits.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #include 12 | 13 | #include 14 | 15 | namespace compute = boost::compute; 16 | 17 | int main() 18 | { 19 | // get the default device 20 | compute::device device = compute::system::default_device(); 21 | 22 | std::cout << "device: " << device.name() << std::endl; 23 | std::cout << " global memory size: " 24 | << device.get_info(CL_DEVICE_GLOBAL_MEM_SIZE) / 1024 / 1024 25 | << " MB" 26 | << std::endl; 27 | std::cout << " local memory size: " 28 | << device.get_info(CL_DEVICE_LOCAL_MEM_SIZE) / 1024 29 | << " KB" 30 | << std::endl; 31 | std::cout << " constant memory size: " 32 | << device.get_info(CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE) / 1024 33 | << " KB" 34 | << std::endl; 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /test/test_functional_identity.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #define BOOST_TEST_MODULE TestFunctionalIdentity 12 | #include 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #include "check_macros.hpp" 20 | #include "context_setup.hpp" 21 | 22 | namespace compute = boost::compute; 23 | 24 | BOOST_AUTO_TEST_CASE(copy_with_identity_transform) 25 | { 26 | int data[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; 27 | compute::vector input(data, data + 8, queue); 28 | compute::vector output(8, context); 29 | 30 | compute::transform( 31 | input.begin(), input.end(), output.begin(), compute::identity(), queue 32 | ); 33 | 34 | CHECK_RANGE_EQUAL( 35 | int, 8, output, (1, 2, 3, 4, 5, 6, 7, 8) 36 | ); 37 | } 38 | 39 | BOOST_AUTO_TEST_SUITE_END() 40 | -------------------------------------------------------------------------------- /test/test_malloc.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #define BOOST_TEST_MODULE TestMalloc 12 | #include 13 | 14 | #include 15 | #include 16 | 17 | #include "context_setup.hpp" 18 | 19 | namespace bc = boost::compute; 20 | 21 | BOOST_AUTO_TEST_CASE(malloc_int) 22 | { 23 | bc::experimental::device_ptr ptr = bc::experimental::malloc(5, context); 24 | 25 | int input_data[] = { 2, 5, 8, 3, 6 }; 26 | bc::copy(input_data, input_data + 5, ptr, queue); 27 | 28 | int output_data[5]; 29 | bc::copy(ptr, ptr + 5, output_data, queue); 30 | 31 | BOOST_CHECK_EQUAL(output_data[0], 2); 32 | BOOST_CHECK_EQUAL(output_data[1], 5); 33 | BOOST_CHECK_EQUAL(output_data[2], 8); 34 | BOOST_CHECK_EQUAL(output_data[3], 3); 35 | BOOST_CHECK_EQUAL(output_data[4], 6); 36 | 37 | bc::experimental::free(ptr); 38 | } 39 | 40 | BOOST_AUTO_TEST_SUITE_END() 41 | -------------------------------------------------------------------------------- /LICENSE_1_0.txt: -------------------------------------------------------------------------------- 1 | Boost Software License - Version 1.0 - August 17th, 2003 2 | 3 | Permission is hereby granted, free of charge, to any person or organization 4 | obtaining a copy of the software and accompanying documentation covered by 5 | this license (the "Software") to use, reproduce, display, distribute, 6 | execute, and transmit the Software, and to prepare derivative works of the 7 | Software, and to permit third-parties to whom the Software is furnished to 8 | do so, all subject to the following: 9 | 10 | The copyright notices in the Software and this entire statement, including 11 | the above license grant, this restriction and the following disclaimer, 12 | must be included in all copies of the Software, in whole or in part, and 13 | all derivative works of the Software, unless such copies or derivative 14 | works are solely in the form of machine-executable object code generated by 15 | a source language processor. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 20 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 21 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | DEALINGS IN THE SOFTWARE. 24 | -------------------------------------------------------------------------------- /include/boost/compute/detail/work_size.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_DETAIL_WORK_SIZE_HPP 12 | #define BOOST_COMPUTE_DETAIL_WORK_SIZE_HPP 13 | 14 | #include 15 | 16 | namespace boost { 17 | namespace compute { 18 | namespace detail { 19 | 20 | // Given a total number of values (count), a number of values to 21 | // process per thread (vtp), and a number of threads to execute per 22 | // block (tpb), this function returns the global work size to be 23 | // passed to clEnqueueNDRangeKernel() for a 1D algorithm. 24 | inline size_t calculate_work_size(size_t count, size_t vpt, size_t tpb) 25 | { 26 | size_t work_size = static_cast(std::ceil(float(count) / vpt)); 27 | if(work_size % tpb != 0){ 28 | work_size += tpb - work_size % tpb; 29 | } 30 | return work_size; 31 | } 32 | 33 | } // end detail namespace 34 | } // end compute namespace 35 | } // end boost namespace 36 | 37 | #endif // BOOST_COMPUTE_DETAIL_WORK_SIZE_HPP 38 | -------------------------------------------------------------------------------- /perf/perf_stl_max_element.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Rastko Anicic 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "perf.hpp" 16 | 17 | int rand_int() 18 | { 19 | return static_cast(rand() % 10000000); 20 | } 21 | 22 | int main(int argc, char *argv[]) 23 | { 24 | perf_parse_args(argc, argv); 25 | std::cout << "size: " << PERF_N << std::endl; 26 | 27 | // create vector of random numbers on the host 28 | std::vector host_vector(PERF_N); 29 | std::generate(host_vector.begin(), host_vector.end(), rand_int); 30 | 31 | int max = 0; 32 | 33 | perf_timer t; 34 | for(size_t trial = 0; trial < PERF_TRIALS; trial++){ 35 | t.start(); 36 | max = *(std::max_element(host_vector.begin(), host_vector.end())); 37 | t.stop(); 38 | } 39 | std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl; 40 | std::cout << "max: " << max << std::endl; 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /test/test_result_of.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #define BOOST_TEST_MODULE TestResultOf 12 | #include 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | BOOST_AUTO_TEST_CASE(result_of_function) 19 | { 20 | using boost::compute::function; 21 | using boost::compute::result_of; 22 | 23 | BOOST_STATIC_ASSERT(( 24 | boost::is_same()>::type, int>::value 25 | )); 26 | } 27 | 28 | BOOST_AUTO_TEST_CASE(result_of_operators) 29 | { 30 | using boost::compute::plus; 31 | using boost::compute::minus; 32 | using boost::compute::result_of; 33 | 34 | BOOST_STATIC_ASSERT(( 35 | boost::is_same(int, int)>::type, int>::value 36 | )); 37 | BOOST_STATIC_ASSERT(( 38 | boost::is_same(int, int)>::type, int>::value 39 | )); 40 | } 41 | -------------------------------------------------------------------------------- /include/boost/compute/functional/detail/macros.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_FUNCTIONAL_MACROS_HPP 12 | #define BOOST_COMPUTE_FUNCTIONAL_MACROS_HPP 13 | 14 | #include 15 | #include 16 | 17 | #include 18 | 19 | #define BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(name, signature, template_args) \ 20 | template \ 21 | class name : public function \ 22 | { \ 23 | public: \ 24 | (name)() : function(BOOST_PP_STRINGIZE(name)) { } \ 25 | }; 26 | 27 | #define BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION_UNDERSCORE(name, signature, template_args) \ 28 | template \ 29 | class BOOST_PP_CAT(name, _) : public function \ 30 | { \ 31 | public: \ 32 | BOOST_PP_CAT(name, _)() : function(BOOST_PP_STRINGIZE(name)) { } \ 33 | }; 34 | 35 | #endif // BOOST_COMPUTE_FUNCTIONAL_MACROS_HPP 36 | -------------------------------------------------------------------------------- /test/test_functional_hash.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #define BOOST_TEST_MODULE TestFunctionalHash 12 | #include 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #include "check_macros.hpp" 21 | #include "context_setup.hpp" 22 | 23 | namespace compute = boost::compute; 24 | 25 | BOOST_AUTO_TEST_CASE(hash_int) 26 | { 27 | using compute::ulong_; 28 | 29 | int data[] = { 1, 2, 3, 4 }; 30 | compute::vector input_values(data, data + 4, queue); 31 | compute::vector hash_values(4, context); 32 | 33 | compute::transform( 34 | input_values.begin(), 35 | input_values.end(), 36 | hash_values.begin(), 37 | compute::hash(), 38 | queue 39 | ); 40 | } 41 | 42 | BOOST_AUTO_TEST_SUITE_END() 43 | -------------------------------------------------------------------------------- /test/test_partition_point.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2014 Roshan 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #define BOOST_TEST_MODULE TestPartitionPoint 12 | #include 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #include "check_macros.hpp" 22 | #include "context_setup.hpp" 23 | 24 | namespace bc = boost::compute; 25 | 26 | BOOST_AUTO_TEST_CASE(partition_point_int) 27 | { 28 | int dataset[] = {1, 1, 5, 2, 4, -2, 0, -1, 0, -1}; 29 | bc::vector vector(dataset, dataset + 10, queue); 30 | 31 | bc::vector::iterator iter = 32 | bc::partition_point(vector.begin(), vector.begin() + 10, 33 | bc::_1 > 0, queue); 34 | 35 | BOOST_VERIFY(iter == vector.begin()+5); 36 | } 37 | 38 | BOOST_AUTO_TEST_SUITE_END() 39 | -------------------------------------------------------------------------------- /perf/perf_stl_includes.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2014 Roshan 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "perf.hpp" 16 | 17 | int rand_int() 18 | { 19 | return static_cast((rand() / double(RAND_MAX)) * 25.0); 20 | } 21 | 22 | int main(int argc, char *argv[]) 23 | { 24 | perf_parse_args(argc, argv); 25 | 26 | std::cout << "size: " << PERF_N << std::endl; 27 | 28 | std::vector v1(PERF_N); 29 | std::generate(v1.begin(), v1.end(), rand_int); 30 | 31 | std::vector v2(v1); 32 | 33 | std::sort(v1.begin(), v1.end()); 34 | std::sort(v2.begin(), v2.end()); 35 | 36 | perf_timer t; 37 | for(size_t trial = 0; trial < PERF_TRIALS; trial++){ 38 | t.start(); 39 | std::includes( 40 | v1.begin(), v1.end(), 41 | v2.begin(), v2.end() 42 | ); 43 | t.stop(); 44 | } 45 | std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl; 46 | 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /include/boost/compute/functional/as.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_FUNCTIONAL_AS_HPP 12 | #define BOOST_COMPUTE_FUNCTIONAL_AS_HPP 13 | 14 | namespace boost { 15 | namespace compute { 16 | namespace detail { 17 | 18 | template 19 | struct invoked_as 20 | { 21 | invoked_as(const Arg &arg) 22 | : m_arg(arg) 23 | { 24 | } 25 | 26 | Arg m_arg; 27 | }; 28 | 29 | } // end detail namespace 30 | 31 | /// The \ref as function converts its argument to type \c T (similar to 32 | /// reinterpret_cast). 33 | /// 34 | /// \see \ref convert "convert" 35 | template 36 | struct as 37 | { 38 | typedef T result_type; 39 | 40 | /// \internal_ 41 | template 42 | detail::invoked_as operator()(const Arg &arg) const 43 | { 44 | return detail::invoked_as(arg); 45 | } 46 | }; 47 | 48 | } // end compute namespace 49 | } // end boost namespace 50 | 51 | #endif // BOOST_COMPUTE_FUNCTIONAL_AS_HPP 52 | -------------------------------------------------------------------------------- /include/boost/compute/functional/detail/nvidia_popcount.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_FUNCTIONAL_DETAIL_NVIDIA_POPCOUNT_HPP 12 | #define BOOST_COMPUTE_FUNCTIONAL_DETAIL_NVIDIA_POPCOUNT_HPP 13 | 14 | #include 15 | 16 | namespace boost { 17 | namespace compute { 18 | namespace detail { 19 | 20 | template 21 | class nvidia_popcount : public function 22 | { 23 | public: 24 | nvidia_popcount() 25 | : function("nvidia_popcount") 26 | { 27 | this->set_source( 28 | "inline uint nvidia_popcount(const uint x)\n" 29 | "{\n" 30 | " uint count;\n" 31 | " asm(\"popc.b32 %0, %1;\" : \"=r\"(count) : \"r\"(x));\n" 32 | " return count;\n" 33 | "}\n" 34 | ); 35 | } 36 | }; 37 | 38 | } // end detail namespace 39 | } // end compute namespace 40 | } // end boost namespace 41 | 42 | #endif // BOOST_COMPUTE_FUNCTIONAL_DETAIL_NVIDIA_POPCOUNT_HPP 43 | -------------------------------------------------------------------------------- /perf/perf_stl_accumulate.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include "perf.hpp" 17 | 18 | int rand_int() 19 | { 20 | return static_cast((rand() / double(RAND_MAX)) * 25.0); 21 | } 22 | 23 | int main(int argc, char *argv[]) 24 | { 25 | perf_parse_args(argc, argv); 26 | std::cout << "size: " << PERF_N << std::endl; 27 | 28 | // create vector of random numbers on the host 29 | std::vector host_vector(PERF_N); 30 | std::generate(host_vector.begin(), host_vector.end(), rand_int); 31 | 32 | int sum = 0; 33 | perf_timer t; 34 | for(size_t trial = 0; trial < PERF_TRIALS; trial++){ 35 | t.start(); 36 | sum = std::accumulate(host_vector.begin(), host_vector.end(), int(0)); 37 | t.stop(); 38 | } 39 | std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl; 40 | std::cout << "sum: " << sum << std::endl; 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /perf/perf_stl_search.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2014 Roshan 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include "perf.hpp" 17 | 18 | int rand_int() 19 | { 20 | return static_cast((rand() / double(RAND_MAX)) * 25.0); 21 | } 22 | 23 | int main(int argc, char *argv[]) 24 | { 25 | perf_parse_args(argc, argv); 26 | std::cout << "size: " << PERF_N << std::endl; 27 | 28 | // create vector of random numbers on the host 29 | std::vector host_vector(PERF_N); 30 | std::generate(host_vector.begin(), host_vector.end(), rand_int); 31 | 32 | int pattern[] = {2, 6, 6, 7, 8, 4}; 33 | 34 | perf_timer t; 35 | for(size_t trial = 0; trial < PERF_TRIALS; trial++){ 36 | t.start(); 37 | std::search(host_vector.begin(), host_vector.end(), 38 | pattern, pattern + 6); 39 | t.stop(); 40 | } 41 | std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl; 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /test/test_clamp_range.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #define BOOST_TEST_MODULE TestClampRange 12 | #include 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | #include "check_macros.hpp" 19 | #include "context_setup.hpp" 20 | 21 | namespace compute = boost::compute; 22 | 23 | BOOST_AUTO_TEST_CASE(clamp_float_range) 24 | { 25 | float data[] = { 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f }; 26 | compute::vector input(data, data + 8, queue); 27 | 28 | compute::vector result(8, context); 29 | compute::experimental::clamp_range( 30 | input.begin(), 31 | input.end(), 32 | result.begin(), 33 | 3.f, // low 34 | 6.f, // high 35 | queue 36 | ); 37 | CHECK_RANGE_EQUAL( 38 | float, 8, result, 39 | (3.f, 3.f, 3.f, 4.f, 5.f, 6.f, 6.f, 6.f) 40 | ); 41 | } 42 | 43 | BOOST_AUTO_TEST_SUITE_END() 44 | -------------------------------------------------------------------------------- /include/boost/compute/algorithm/generate_n.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_ALGORITHM_GENERATE_N_HPP 12 | #define BOOST_COMPUTE_ALGORITHM_GENERATE_N_HPP 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | namespace boost { 19 | namespace compute { 20 | 21 | /// Stores the result of \p generator for each element in the range 22 | /// [\p first, \p first + \p count). 23 | /// 24 | /// Space complexity: \Omega(1) 25 | template 26 | inline void generate_n(OutputIterator first, 27 | Size count, 28 | Generator generator, 29 | command_queue &queue = system::default_queue()) 30 | { 31 | ::boost::compute::generate(first, first + count, generator, queue); 32 | } 33 | 34 | } // end compute namespace 35 | } // end boost namespace 36 | 37 | #endif // BOOST_COMPUTE_ALGORITHM_GENERATE_N_HPP 38 | -------------------------------------------------------------------------------- /perf/perf_stl_find_end.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2014 Roshan 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include "perf.hpp" 17 | 18 | int rand_int() 19 | { 20 | return static_cast((rand() / double(RAND_MAX)) * 25.0); 21 | } 22 | 23 | int main(int argc, char *argv[]) 24 | { 25 | perf_parse_args(argc, argv); 26 | std::cout << "size: " << PERF_N << std::endl; 27 | 28 | // create vector of random numbers on the host 29 | std::vector host_vector(PERF_N); 30 | std::generate(host_vector.begin(), host_vector.end(), rand_int); 31 | 32 | int pattern[] = {2, 6, 6, 7, 8, 4}; 33 | 34 | perf_timer t; 35 | for(size_t trial = 0; trial < PERF_TRIALS; trial++){ 36 | t.start(); 37 | std::find_end(host_vector.begin(), host_vector.end(), 38 | pattern, pattern + 6); 39 | t.stop(); 40 | } 41 | std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl; 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /perf/perf_stl_partition.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2014 Roshan 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include "perf.hpp" 17 | 18 | int rand_int() 19 | { 20 | return static_cast((rand() / double(RAND_MAX)) * 25.0); 21 | } 22 | 23 | bool less_than_10(int value) 24 | { 25 | return value < 10; 26 | } 27 | 28 | int main(int argc, char *argv[]) 29 | { 30 | perf_parse_args(argc, argv); 31 | std::cout << "size: " << PERF_N << std::endl; 32 | 33 | // create vector of random numbers on the host 34 | std::vector host_vector(PERF_N); 35 | std::generate(host_vector.begin(), host_vector.end(), rand_int); 36 | 37 | perf_timer t; 38 | for(size_t trial = 0; trial < PERF_TRIALS; trial++){ 39 | t.start(); 40 | std::partition(host_vector.begin(), host_vector.end(), less_than_10); 41 | t.stop(); 42 | } 43 | std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl; 44 | 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /doc/platforms_and_compilers.qbk: -------------------------------------------------------------------------------- 1 | [/=========================================================================== 2 | Copyright (c) 2013-2015 Kyle Lutz 3 | 4 | Distributed under the Boost Software License, Version 1.0 5 | See accompanying file LICENSE_1_0.txt or copy at 6 | http://www.boost.org/LICENSE_1_0.txt 7 | =============================================================================/] 8 | 9 | [section:platforms_and_compilers Platforms and Compilers] 10 | 11 | Boost.Compute has been tested on the following: 12 | 13 | [section Compilers] 14 | 15 | * GCC (>= 4.6) 16 | * Clang (>= 3.0) 17 | * MSVC (>= 2010) 18 | 19 | Boost.Compute requires variadic macro support. Variadic macros are supported by 20 | most modern C++98 compilers and all C++11 compilers. 21 | 22 | To explicitly enable variadic support for Boost.Preprocessor add 23 | `-DBOOST_PP_VARIADICS=1` to your compiler flags. 24 | 25 | [endsect] 26 | 27 | [section Platforms] 28 | 29 | * Linux 30 | * Mac OSX 31 | * Windows 32 | 33 | [endsect] 34 | 35 | [section OpenCL Implementations] 36 | 37 | * NVIDIA (NVIDIA GPUs only) 38 | * AMD (CPUs and AMD GPUs) 39 | * Intel (CPUs and Intel GPUs) 40 | * POCL (CPUs only) 41 | * Beignet (Intel GPUs only) 42 | * Apple (CPUs and GPUs) 43 | * Xilinx (FPGA) 44 | 45 | [endsect] 46 | 47 | If you have an additional platform you would like to see supported please 48 | [@https://github.com/boostorg/compute/issues/new submit] a bug-report. 49 | 50 | [endsect] 51 | -------------------------------------------------------------------------------- /perf/perf_bolt_fill.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2015 Jakub Szuppe 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | #include "perf.hpp" 20 | 21 | int main(int argc, char *argv[]) 22 | { 23 | perf_parse_args(argc, argv); 24 | 25 | std::cout << "size: " << PERF_N << std::endl; 26 | 27 | bolt::cl::control ctrl = bolt::cl::control::getDefault(); 28 | ::cl::Device device = ctrl.getDevice(); 29 | std::cout << "device: " << device.getInfo() << std::endl; 30 | 31 | // create device vector (filled with zeros) 32 | bolt::cl::device_vector d_vec(PERF_N, 0); 33 | 34 | perf_timer t; 35 | for(size_t trial = 0; trial < PERF_TRIALS; trial++){ 36 | t.start(); 37 | bolt::cl::fill(d_vec.begin(), d_vec.end(), int(trial)); 38 | t.stop(); 39 | } 40 | std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl; 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /perf/perf_stl_unique_copy.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2014 Roshan 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include "perf.hpp" 17 | 18 | int rand_int() 19 | { 20 | return static_cast((rand() / double(RAND_MAX)) * 25.0); 21 | } 22 | 23 | int main(int argc, char *argv[]) 24 | { 25 | perf_parse_args(argc, argv); 26 | std::cout << "size: " << PERF_N << std::endl; 27 | 28 | // create vector of random numbers on the host 29 | std::vector host_vector(PERF_N); 30 | std::vector host_vector2(PERF_N); 31 | 32 | perf_timer t; 33 | for(size_t trial = 0; trial < PERF_TRIALS; trial++){ 34 | std::generate(host_vector.begin(), host_vector.end(), rand_int); 35 | t.start(); 36 | std::unique_copy( 37 | host_vector.begin(), host_vector.end(), host_vector2.begin() 38 | ); 39 | t.stop(); 40 | } 41 | std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl; 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /perf/perf_stl_rotate_copy.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2014 Roshan 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include "perf.hpp" 17 | 18 | int rand_int() 19 | { 20 | return static_cast((rand() / double(RAND_MAX)) * 25.0); 21 | } 22 | 23 | int main(int argc, char *argv[]) 24 | { 25 | perf_parse_args(argc, argv); 26 | std::cout << "size: " << PERF_N << std::endl; 27 | 28 | // create vector of random numbers on the host 29 | std::vector host_vector(PERF_N); 30 | std::generate(host_vector.begin(), host_vector.end(), rand_int); 31 | 32 | std::vector host_vector2(PERF_N); 33 | 34 | perf_timer t; 35 | for(size_t trial = 0; trial < PERF_TRIALS; trial++){ 36 | t.start(); 37 | std::rotate_copy(host_vector.begin(), host_vector.begin()+(PERF_N/2), host_vector.end(), host_vector2.begin()); 38 | t.stop(); 39 | } 40 | std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl; 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /test/test_stable_partition.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2014 Roshan 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #define BOOST_TEST_MODULE TestStablePartition 12 | #include 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #include "check_macros.hpp" 21 | #include "context_setup.hpp" 22 | 23 | namespace bc = boost::compute; 24 | 25 | BOOST_AUTO_TEST_CASE(partition_int) 26 | { 27 | int dataset[] = {1, 1, -2, 0, 5, -1, 2, 4, 0, -1}; 28 | bc::vector vector(dataset, dataset + 10, queue); 29 | 30 | bc::vector::iterator iter = 31 | bc::stable_partition(vector.begin(), vector.begin() + 10, 32 | bc::_1 > 0, queue); 33 | 34 | CHECK_RANGE_EQUAL(int, 10, vector, (1, 1, 5, 2, 4, -2, 0, -1, 0, -1)); 35 | BOOST_VERIFY(iter == vector.begin()+5); 36 | } 37 | 38 | BOOST_AUTO_TEST_SUITE_END() 39 | -------------------------------------------------------------------------------- /include/boost/compute/functional/convert.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_FUNCTIONAL_CONVERT_HPP 12 | #define BOOST_COMPUTE_FUNCTIONAL_CONVERT_HPP 13 | 14 | namespace boost { 15 | namespace compute { 16 | namespace detail { 17 | 18 | template 19 | struct invoked_convert 20 | { 21 | invoked_convert(const Arg &arg) 22 | : m_arg(arg) 23 | { 24 | } 25 | 26 | Arg m_arg; 27 | }; 28 | 29 | } // end detail namespace 30 | 31 | /// The \ref convert function converts its argument to type \c T (similar to 32 | /// static_cast). 33 | /// 34 | /// \see \ref as "as" 35 | template 36 | struct convert 37 | { 38 | typedef T result_type; 39 | 40 | /// \internal_ 41 | template 42 | detail::invoked_convert operator()(const Arg &arg) const 43 | { 44 | return detail::invoked_convert(arg); 45 | } 46 | }; 47 | 48 | } // end compute namespace 49 | } // end boost namespace 50 | 51 | #endif // BOOST_COMPUTE_FUNCTIONAL_CONVERT_HPP 52 | -------------------------------------------------------------------------------- /test/test_partial_sum.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #define BOOST_TEST_MODULE TestPartialSum 12 | #include 13 | 14 | #include 15 | #include 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include "check_macros.hpp" 24 | #include "context_setup.hpp" 25 | 26 | namespace bc = boost::compute; 27 | 28 | BOOST_AUTO_TEST_CASE(partial_sum_int) 29 | { 30 | int data[] = { 1, 2, 5, 3, 9, 1, 4, 2 }; 31 | bc::vector a(8, context); 32 | bc::copy(data, data + 8, a.begin(), queue); 33 | 34 | bc::vector b(a.size(), context); 35 | bc::vector::iterator iter = 36 | bc::partial_sum(a.begin(), a.end(), b.begin(), queue); 37 | BOOST_CHECK(iter == b.end()); 38 | CHECK_RANGE_EQUAL(int, 8, b, (1, 3, 8, 11, 20, 21, 25, 27)); 39 | } 40 | 41 | BOOST_AUTO_TEST_SUITE_END() 42 | -------------------------------------------------------------------------------- /include/boost/compute/functional.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_FUNCTIONAL_HPP 12 | #define BOOST_COMPUTE_FUNCTIONAL_HPP 13 | 14 | /// \file 15 | /// 16 | /// Meta-header to include all Boost.Compute functional headers. 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #endif // BOOST_COMPUTE_FUNCTIONAL_HPP 35 | -------------------------------------------------------------------------------- /test/test_attach_user_queue_error.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2019 Anthony Chang 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #define BOOST_TEST_MODULE TestAttachUserQueueError 12 | #include 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | namespace compute = boost::compute; 19 | 20 | // For correct usage of setting up global default queue, see test_system.cpp 21 | BOOST_AUTO_TEST_CASE(user_context_device_mismatch) 22 | { 23 | //! [queue_mismatch] 24 | compute::device user_device = compute::system::devices().front(); 25 | compute::context user_context(user_device); 26 | compute::command_queue user_queue(user_context, user_device); 27 | 28 | // Don't call default_device() or default_context() before calling 29 | // default_queue() if you wish to attach your command queue 30 | compute::system::default_context(); 31 | 32 | BOOST_CHECK_THROW( 33 | compute::system::default_queue(user_queue), 34 | compute::set_default_queue_error); 35 | //! [queue_mismatch] 36 | } 37 | -------------------------------------------------------------------------------- /include/boost/compute/type_traits/result_of.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_TYPE_TRAITS_RESULT_OF_HPP 12 | #define BOOST_COMPUTE_TYPE_TRAITS_RESULT_OF_HPP 13 | 14 | #include 15 | 16 | namespace boost { 17 | namespace compute { 18 | 19 | /// Returns the result of \c Function when called with \c Args. 20 | /// 21 | /// For example, 22 | /// \code 23 | /// // int + int = int 24 | /// result_of::type == int 25 | /// \endcode 26 | template 27 | struct result_of 28 | { 29 | // the default implementation uses the TR1-style result_of protocol. note 30 | // that we explicitly do *not* use the C++11 decltype operator as we want 31 | // the result type as it would be on an OpenCL device, not the actual C++ 32 | // type resulting from "invoking" the function on the host. 33 | typedef typename ::boost::tr1_result_of::type type; 34 | }; 35 | 36 | } // end compute namespace 37 | } // end boost namespace 38 | 39 | #endif // BOOST_COMPUTE_TYPE_TRAITS_RESULT_OF_HPP 40 | -------------------------------------------------------------------------------- /test/test_transform_if.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #define BOOST_TEST_MODULE TestTransformIf 12 | #include 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | #include "check_macros.hpp" 19 | #include "context_setup.hpp" 20 | 21 | namespace compute = boost::compute; 22 | 23 | BOOST_AUTO_TEST_CASE(transform_if_odd) 24 | { 25 | using boost::compute::abs; 26 | using boost::compute::lambda::_1; 27 | 28 | int data[] = { -2, -3, -4, -5, -6, -7, -8, -9 }; 29 | compute::vector input(data, data + 8, queue); 30 | compute::vector output(input.size(), context); 31 | 32 | compute::vector::iterator end = compute::transform_if( 33 | input.begin(), input.end(), output.begin(), abs(), _1 % 2 != 0, queue 34 | ); 35 | BOOST_CHECK_EQUAL(std::distance(output.begin(), end), 4); 36 | 37 | CHECK_RANGE_EQUAL(int, 4, output, (+3, +5, +7, +9)); 38 | } 39 | 40 | BOOST_AUTO_TEST_SUITE_END() 41 | -------------------------------------------------------------------------------- /include/boost/compute/utility/source.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_UTILITY_SOURCE_HPP 12 | #define BOOST_COMPUTE_UTILITY_SOURCE_HPP 13 | 14 | /// Stringizes OpenCL source code. 15 | /// 16 | /// For example, to create a simple kernel which squares each input value: 17 | /// \code 18 | /// const char source[] = BOOST_COMPUTE_STRINGIZE_SOURCE( 19 | /// __kernel void square(const float *input, float *output) 20 | /// { 21 | /// const uint i = get_global_id(0); 22 | /// const float x = input[i]; 23 | /// output[i] = x * x; 24 | /// } 25 | /// ); 26 | /// 27 | /// // create and build square program 28 | /// program square_program = program::build_with_source(source, context); 29 | /// 30 | /// // create square kernel 31 | /// kernel square_kernel(square_program, "square"); 32 | /// \endcode 33 | #ifdef BOOST_COMPUTE_DOXYGEN_INVOKED 34 | #define BOOST_COMPUTE_STRINGIZE_SOURCE(source) 35 | #else 36 | #define BOOST_COMPUTE_STRINGIZE_SOURCE(...) #__VA_ARGS__ 37 | #endif 38 | 39 | #endif // BOOST_COMPUTE_UTILITY_SOURCE_HPP 40 | -------------------------------------------------------------------------------- /perf/perf_stl_count.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "perf.hpp" 16 | 17 | int rand_int() 18 | { 19 | return static_cast((rand() / double(RAND_MAX)) * 25.0); 20 | } 21 | 22 | int main(int argc, char *argv[]) 23 | { 24 | perf_parse_args(argc, argv); 25 | std::cout << "size: " << PERF_N << std::endl; 26 | 27 | // create vector of random numbers on the host 28 | std::vector host_vector(PERF_N); 29 | std::generate(host_vector.begin(), host_vector.end(), rand_int); 30 | 31 | // count values equal to four in the vector 32 | size_t count = 0; 33 | perf_timer t; 34 | for(size_t trial = 0; trial < PERF_TRIALS; trial++){ 35 | t.start(); 36 | count = std::count( 37 | host_vector.begin(), host_vector.end(), 4 38 | ); 39 | t.stop(); 40 | } 41 | std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl; 42 | std::cout << "count: " << count << std::endl; 43 | 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /perf/perf_stl_inner_product.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include "perf.hpp" 17 | 18 | int rand_int() 19 | { 20 | return static_cast((rand() / double(RAND_MAX)) * 25.0); 21 | } 22 | 23 | int main(int argc, char *argv[]) 24 | { 25 | perf_parse_args(argc, argv); 26 | std::cout << "size: " << PERF_N << std::endl; 27 | 28 | std::vector h1(PERF_N); 29 | std::vector h2(PERF_N); 30 | std::generate(h1.begin(), h1.end(), rand_int); 31 | std::generate(h2.begin(), h2.end(), rand_int); 32 | 33 | int product = 0; 34 | perf_timer t; 35 | for(size_t trial = 0; trial < PERF_TRIALS; trial++){ 36 | t.start(); 37 | product = std::inner_product( 38 | h1.begin(), h1.end(), h2.begin(), int(0) 39 | ); 40 | t.stop(); 41 | } 42 | std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl; 43 | std::cout << "product: " << product << std::endl; 44 | 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /perf/perf_stl_prev_permutation.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2014 Roshan 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include "perf.hpp" 17 | 18 | int rand_int() 19 | { 20 | return static_cast((rand() / double(RAND_MAX)) * 25.0); 21 | } 22 | 23 | int main(int argc, char *argv[]) 24 | { 25 | perf_parse_args(argc, argv); 26 | std::cout << "size: " << PERF_N << std::endl; 27 | 28 | // create vector of random numbers on the host 29 | std::vector host_vector(PERF_N); 30 | std::generate(host_vector.begin(), host_vector.end(), rand_int); 31 | std::sort(host_vector.begin(), host_vector.end()); 32 | 33 | perf_timer t; 34 | for(size_t trial = 0; trial < PERF_TRIALS; trial++){ 35 | t.start(); 36 | std::prev_permutation(host_vector.begin(), host_vector.end()); 37 | t.stop(); 38 | std::next_permutation(host_vector.begin(), host_vector.end()); 39 | } 40 | std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl; 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /perf/perf_stl_stable_partition.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2014 Roshan 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include "perf.hpp" 17 | 18 | int rand_int() 19 | { 20 | return static_cast((rand() / double(RAND_MAX)) * 25.0); 21 | } 22 | 23 | bool less_than_10(int value) 24 | { 25 | return value < 10; 26 | } 27 | 28 | int main(int argc, char *argv[]) 29 | { 30 | perf_parse_args(argc, argv); 31 | std::cout << "size: " << PERF_N << std::endl; 32 | 33 | // create vector of random numbers on the host 34 | std::vector host_vector(PERF_N); 35 | std::generate(host_vector.begin(), host_vector.end(), rand_int); 36 | 37 | perf_timer t; 38 | for(size_t trial = 0; trial < PERF_TRIALS; trial++){ 39 | t.start(); 40 | std::stable_partition(host_vector.begin(), host_vector.end(), 41 | less_than_10); 42 | t.stop(); 43 | } 44 | std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl; 45 | 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /perf/perf_thrust_accumulate.cu: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #include "perf.hpp" 22 | 23 | int main(int argc, char *argv[]) 24 | { 25 | perf_parse_args(argc, argv); 26 | 27 | std::cout << "size: " << PERF_N << std::endl; 28 | thrust::host_vector h_vec = generate_random_vector(PERF_N); 29 | 30 | // transfer data to the device 31 | thrust::device_vector d_vec = h_vec; 32 | 33 | int sum = 0; 34 | perf_timer t; 35 | for(size_t trial = 0; trial < PERF_TRIALS; trial++){ 36 | t.start(); 37 | sum = thrust::reduce(d_vec.begin(), d_vec.end()); 38 | cudaDeviceSynchronize(); 39 | t.stop(); 40 | } 41 | std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl; 42 | std::cout << "sum: " << sum << std::endl; 43 | 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /test/test_bernoulli_distribution.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2014 Roshan 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #define BOOST_TEST_MODULE TestBernoulliDistribution 12 | #include 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #include "context_setup.hpp" 21 | 22 | BOOST_AUTO_TEST_CASE(bernoulli_distribution_doctest) 23 | { 24 | boost::compute::vector vec(10, context); 25 | 26 | //! [generate] 27 | // initialize the default random engine 28 | boost::compute::default_random_engine engine(queue); 29 | 30 | // setup the bernoulli distribution to produce booleans 31 | // with parameter p = 0.25 32 | boost::compute::bernoulli_distribution distribution(0.25f); 33 | 34 | // generate the random values and store them to 'vec' 35 | distribution.generate(vec.begin(), vec.end(), engine, queue); 36 | //! [generate] 37 | } 38 | 39 | BOOST_AUTO_TEST_SUITE_END() 40 | -------------------------------------------------------------------------------- /include/boost/compute/interop/vtk/matrix4x4.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_INTEROP_VTK_MATRIX4X4_HPP 12 | #define BOOST_COMPUTE_INTEROP_VTK_MATRIX4X4_HPP 13 | 14 | #include 15 | 16 | #include 17 | 18 | namespace boost { 19 | namespace compute { 20 | 21 | /// Converts a \c vtkMatrix4x4 to a \c float16_. 22 | inline float16_ vtk_matrix4x4_to_float16(const vtkMatrix4x4 *matrix) 23 | { 24 | float16_ result; 25 | 26 | for(int i = 0; i < 4; i++){ 27 | for(int j = 0; j < 4; j++){ 28 | result[i*4+j] = matrix->GetElement(i, j); 29 | } 30 | } 31 | 32 | return result; 33 | } 34 | 35 | /// Converts a \c vtkMatrix4x4 to a \c double16_; 36 | inline double16_ vtk_matrix4x4_to_double16(const vtkMatrix4x4 *matrix) 37 | { 38 | double16_ result; 39 | std::memcpy(&result, matrix->Element, 16 * sizeof(double)); 40 | return result; 41 | } 42 | 43 | } // end compute namespace 44 | } // end boost namespace 45 | 46 | #endif // BOOST_COMPUTE_INTEROP_VTK_MATRIX4X4_HPP 47 | -------------------------------------------------------------------------------- /perf/perf_stl_reverse_copy.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2015 Jakub Szuppe 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include "perf.hpp" 17 | 18 | int rand_int() 19 | { 20 | return static_cast((rand() / double(RAND_MAX)) * 25.0); 21 | } 22 | 23 | int main(int argc, char *argv[]) 24 | { 25 | perf_parse_args(argc, argv); 26 | std::cout << "size: " << PERF_N << std::endl; 27 | 28 | // create vector of random numbers on the host 29 | std::vector host_vector(PERF_N); 30 | std::generate(host_vector.begin(), host_vector.end(), rand_int); 31 | 32 | // create vector for reversed data 33 | std::vector host_reversed_vector(PERF_N); 34 | 35 | perf_timer t; 36 | for(size_t trial = 0; trial < PERF_TRIALS; trial++){ 37 | t.start(); 38 | std::reverse_copy(host_vector.begin(), host_vector.end(), 39 | host_reversed_vector.begin()); 40 | t.stop(); 41 | } 42 | std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl; 43 | 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /perf/perf_stl_next_permutation.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2014 Roshan 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include "perf.hpp" 17 | 18 | int rand_int() 19 | { 20 | return static_cast((rand() / double(RAND_MAX)) * 25.0); 21 | } 22 | 23 | int main(int argc, char *argv[]) 24 | { 25 | perf_parse_args(argc, argv); 26 | std::cout << "size: " << PERF_N << std::endl; 27 | 28 | // create vector of random numbers on the host 29 | std::vector host_vector(PERF_N); 30 | std::generate(host_vector.begin(), host_vector.end(), rand_int); 31 | std::sort(host_vector.begin(), host_vector.end(), std::greater()); 32 | 33 | perf_timer t; 34 | for(size_t trial = 0; trial < PERF_TRIALS; trial++){ 35 | t.start(); 36 | std::next_permutation(host_vector.begin(), host_vector.end()); 37 | t.stop(); 38 | std::prev_permutation(host_vector.begin(), host_vector.end()); 39 | } 40 | std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl; 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /perf/perf_stl_partial_sum.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include 17 | 18 | #include "perf.hpp" 19 | 20 | int rand_int() 21 | { 22 | return static_cast((rand() / double(RAND_MAX)) * 25.0); 23 | } 24 | 25 | int main(int argc, char *argv[]) 26 | { 27 | using boost::compute::int_; 28 | 29 | perf_parse_args(argc, argv); 30 | 31 | std::cout << "size: " << PERF_N << std::endl; 32 | 33 | // create vector of random numbers on the host 34 | std::vector v(PERF_N); 35 | std::vector r(PERF_N); 36 | 37 | perf_timer t; 38 | for(size_t trial = 0; trial < PERF_TRIALS; trial++){ 39 | std::generate(v.begin(), v.end(), rand_int); 40 | t.start(); 41 | std::partial_sum( 42 | v.begin(), 43 | v.end(), 44 | r.begin() 45 | ); 46 | t.stop(); 47 | } 48 | std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl; 49 | 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /example/copy_data.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | //[copy_data_example 12 | 13 | #include 14 | 15 | #include 16 | #include 17 | 18 | namespace compute = boost::compute; 19 | 20 | int main() 21 | { 22 | // get default device and setup context 23 | compute::device device = compute::system::default_device(); 24 | compute::context context(device); 25 | compute::command_queue queue(context, device); 26 | 27 | // create data array on host 28 | int host_data[] = { 1, 3, 5, 7, 9 }; 29 | 30 | // create vector on device 31 | compute::vector device_vector(5, context); 32 | 33 | // copy from host to device 34 | compute::copy( 35 | host_data, host_data + 5, device_vector.begin(), queue 36 | ); 37 | 38 | // create vector on host 39 | std::vector host_vector(5); 40 | 41 | // copy data back to host 42 | compute::copy( 43 | device_vector.begin(), device_vector.end(), host_vector.begin(), queue 44 | ); 45 | 46 | return 0; 47 | } 48 | 49 | //] 50 | -------------------------------------------------------------------------------- /include/boost/compute/type_traits/is_device_iterator.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_TYPE_TRAITS_IS_DEVICE_ITERATOR_HPP 12 | #define BOOST_COMPUTE_TYPE_TRAITS_IS_DEVICE_ITERATOR_HPP 13 | 14 | #include 15 | 16 | namespace boost { 17 | namespace compute { 18 | 19 | /// Meta-function returning \c true if \c Iterator is a device-iterator. 20 | /// 21 | /// By default, this function returns false. Device iterator types (such as 22 | /// buffer_iterator) should specialize this trait and return \c true. 23 | /// 24 | /// For example: 25 | /// \code 26 | /// is_device_iterator>::value == true 27 | /// is_device_iterator::iterator>::value == false 28 | /// \endcode 29 | template 30 | struct is_device_iterator : boost::false_type {}; 31 | 32 | /// \internal_ 33 | template 34 | struct is_device_iterator : is_device_iterator {}; 35 | 36 | } // end compute namespace 37 | } // end boost namespace 38 | 39 | #endif // BOOST_COMPUTE_TYPE_TRAITS_IS_DEVICE_ITERATOR_HPP 40 | -------------------------------------------------------------------------------- /include/boost/compute/experimental/tabulate.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_EXPERIMENTAL_TABULATE_HPP 12 | #define BOOST_COMPUTE_EXPERIMENTAL_TABULATE_HPP 13 | 14 | #include 15 | 16 | #include 17 | #include 18 | 19 | namespace boost { 20 | namespace compute { 21 | namespace experimental { 22 | 23 | template 24 | inline void tabulate(Iterator first, 25 | Iterator last, 26 | UnaryFunction function, 27 | command_queue &queue) 28 | { 29 | size_t n = detail::iterator_range_size(first, last); 30 | 31 | ::boost::compute::transform( 32 | ::boost::compute::make_counting_iterator(0), 33 | ::boost::compute::make_counting_iterator(n), 34 | first, 35 | function, 36 | queue 37 | ); 38 | } 39 | 40 | } // end experimental namespace 41 | } // end compute namespace 42 | } // end boost namespace 43 | 44 | #endif // BOOST_COMPUTE_EXPERIMENTAL_TABULATE_HPP 45 | -------------------------------------------------------------------------------- /test/test_functional_convert.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #define BOOST_TEST_MODULE TestFunctionalConvert 12 | #include 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #include "check_macros.hpp" 21 | #include "context_setup.hpp" 22 | 23 | namespace compute = boost::compute; 24 | 25 | BOOST_AUTO_TEST_CASE(convert_int_float) 26 | { 27 | int data[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; 28 | compute::vector input(8, context); 29 | compute::copy_n(data, 8, input.begin(), queue); 30 | 31 | compute::vector output(8, context); 32 | compute::transform( 33 | input.begin(), 34 | input.end(), 35 | output.begin(), 36 | compute::convert(), 37 | queue 38 | ); 39 | CHECK_RANGE_EQUAL( 40 | float, 8, output, (1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f) 41 | ); 42 | } 43 | 44 | BOOST_AUTO_TEST_SUITE_END() 45 | -------------------------------------------------------------------------------- /include/boost/compute/exception/no_device_found.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2015 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_EXCEPTION_NO_DEVICE_FOUND_HPP 12 | #define BOOST_COMPUTE_EXCEPTION_NO_DEVICE_FOUND_HPP 13 | 14 | #include 15 | 16 | namespace boost { 17 | namespace compute { 18 | 19 | /// \class no_device_found 20 | /// \brief Exception thrown when no OpenCL device is found 21 | /// 22 | /// This exception is thrown when no valid OpenCL device can be found. 23 | /// 24 | /// \see opencl_error 25 | class no_device_found : public std::exception 26 | { 27 | public: 28 | /// Creates a new no_device_found exception object. 29 | no_device_found() throw() 30 | { 31 | } 32 | 33 | /// Destroys the no_device_found exception object. 34 | ~no_device_found() throw() 35 | { 36 | } 37 | 38 | /// Returns a string containing a human-readable error message. 39 | const char* what() const throw() 40 | { 41 | return "No OpenCL device found"; 42 | } 43 | }; 44 | 45 | } // end compute namespace 46 | } // end boost namespace 47 | 48 | #endif // BOOST_COMPUTE_EXCEPTION_NO_DEVICE_FOUND_HPP 49 | -------------------------------------------------------------------------------- /perf/perf_stl_is_permutation.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2014 Roshan 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include "perf.hpp" 17 | 18 | int rand_int() 19 | { 20 | return static_cast((rand() / double(RAND_MAX)) * 25.0); 21 | } 22 | 23 | int main(int argc, char *argv[]) 24 | { 25 | perf_parse_args(argc, argv); 26 | std::cout << "size: " << PERF_N << std::endl; 27 | 28 | // create vector of random numbers on the host 29 | std::vector host_vector(PERF_N); 30 | std::generate(host_vector.begin(), host_vector.end(), rand_int); 31 | 32 | std::vector host_vector2(PERF_N); 33 | std::copy(host_vector.rbegin(), host_vector.rend(), host_vector2.begin()); 34 | 35 | perf_timer t; 36 | for(size_t trial = 0; trial < PERF_TRIALS; trial++){ 37 | t.start(); 38 | std::is_permutation(host_vector.begin(), host_vector.end(), 39 | host_vector2.begin()); 40 | t.stop(); 41 | } 42 | std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl; 43 | 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /perf/perf_thrust_sort.cu: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #include "perf.hpp" 22 | 23 | int main(int argc, char *argv[]) 24 | { 25 | perf_parse_args(argc, argv); 26 | 27 | std::cout << "size: " << PERF_N << std::endl; 28 | thrust::host_vector h_vec = generate_random_vector(PERF_N); 29 | 30 | // transfer data to the device 31 | thrust::device_vector d_vec; 32 | 33 | perf_timer t; 34 | for(size_t trial = 0; trial < PERF_TRIALS; trial++){ 35 | d_vec = h_vec; 36 | 37 | t.start(); 38 | thrust::sort(d_vec.begin(), d_vec.end()); 39 | cudaDeviceSynchronize(); 40 | t.stop(); 41 | } 42 | std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl; 43 | 44 | // transfer data back to host 45 | thrust::copy(d_vec.begin(), d_vec.end(), h_vec.begin()); 46 | 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /test/test_stack.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #define BOOST_TEST_MODULE TestStack 12 | #include 13 | 14 | #include 15 | 16 | #include "context_setup.hpp" 17 | 18 | namespace bc = boost::compute; 19 | 20 | BOOST_AUTO_TEST_CASE(size) 21 | { 22 | bc::stack stack; 23 | BOOST_CHECK_EQUAL(stack.size(), size_t(0)); 24 | 25 | stack.push(1); 26 | stack.push(2); 27 | stack.push(3); 28 | BOOST_CHECK_EQUAL(stack.size(), size_t(3)); 29 | } 30 | 31 | BOOST_AUTO_TEST_CASE(push_and_pop) 32 | { 33 | bc::stack stack; 34 | stack.push(1); 35 | stack.push(2); 36 | stack.push(3); 37 | 38 | BOOST_CHECK_EQUAL(stack.top(), 3); 39 | BOOST_CHECK_EQUAL(stack.size(), size_t(3)); 40 | stack.pop(); 41 | BOOST_CHECK_EQUAL(stack.top(), 2); 42 | BOOST_CHECK_EQUAL(stack.size(), size_t(2)); 43 | stack.pop(); 44 | BOOST_CHECK_EQUAL(stack.top(), 1); 45 | BOOST_CHECK_EQUAL(stack.size(), size_t(1)); 46 | stack.pop(); 47 | BOOST_CHECK_EQUAL(stack.size(), size_t(0)); 48 | } 49 | 50 | BOOST_AUTO_TEST_SUITE_END() 51 | -------------------------------------------------------------------------------- /include/boost/compute/algorithm/fill_n.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_ALGORITHM_FILL_N_HPP 12 | #define BOOST_COMPUTE_ALGORITHM_FILL_N_HPP 13 | 14 | #include 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | namespace boost { 22 | namespace compute { 23 | 24 | /// Fills the range [\p first, \p first + count) with \p value. 25 | /// 26 | /// Space complexity: \Omega(1) 27 | /// 28 | /// \see fill() 29 | template 30 | inline void fill_n(BufferIterator first, 31 | Size count, 32 | const T &value, 33 | command_queue &queue = system::default_queue()) 34 | { 35 | BOOST_STATIC_ASSERT(is_device_iterator::value); 36 | ::boost::compute::fill(first, first + count, value, queue); 37 | } 38 | 39 | } // end compute namespace 40 | } // end boost namespace 41 | 42 | #endif // BOOST_COMPUTE_ALGORITHM_FILL_N_HPP 43 | -------------------------------------------------------------------------------- /perf/perf_thrust_unique.cu: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #include "perf.hpp" 22 | 23 | int rand_int() 24 | { 25 | return static_cast((rand() / double(RAND_MAX)) * 25.0); 26 | } 27 | 28 | int main(int argc, char *argv[]) 29 | { 30 | perf_parse_args(argc, argv); 31 | 32 | std::cout << "size: " << PERF_N << std::endl; 33 | thrust::host_vector h_vec(PERF_N); 34 | std::generate(h_vec.begin(), h_vec.end(), rand_int); 35 | 36 | thrust::device_vector d_vec(PERF_N); 37 | 38 | perf_timer t; 39 | for(size_t trial = 0; trial < PERF_TRIALS; trial++){ 40 | d_vec = h_vec; 41 | 42 | t.start(); 43 | thrust::unique(d_vec.begin(), d_vec.end()); 44 | cudaDeviceSynchronize(); 45 | t.stop(); 46 | } 47 | std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl; 48 | 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /perf/perf_thrust_exclusive_scan.cu: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2014 Benoit 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #include "perf.hpp" 22 | 23 | int main(int argc, char *argv[]) 24 | { 25 | perf_parse_args(argc, argv); 26 | 27 | std::cout << "size: " << PERF_N << std::endl; 28 | thrust::host_vector h_vec = generate_random_vector(PERF_N); 29 | 30 | // transfer data to the device 31 | thrust::device_vector d_vec = h_vec; 32 | 33 | perf_timer t; 34 | for(size_t trial = 0; trial < PERF_TRIALS; trial++){ 35 | d_vec = h_vec; 36 | 37 | t.start(); 38 | thrust::exclusive_scan(d_vec.begin(), d_vec.end(), d_vec.begin()); 39 | cudaDeviceSynchronize(); 40 | t.stop(); 41 | } 42 | std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl; 43 | 44 | // transfer data back to host 45 | thrust::copy(d_vec.begin(), d_vec.end(), h_vec.begin()); 46 | 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /perf/perf_thrust_reverse.cu: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #include "perf.hpp" 22 | 23 | int main(int argc, char *argv[]) 24 | { 25 | perf_parse_args(argc, argv); 26 | 27 | std::cout << "size: " << PERF_N << std::endl; 28 | thrust::host_vector h_vec = generate_random_vector(PERF_N); 29 | 30 | // transfer data to the device 31 | thrust::device_vector d_vec; 32 | 33 | perf_timer t; 34 | for(size_t trial = 0; trial < PERF_TRIALS; trial++){ 35 | d_vec = h_vec; 36 | 37 | t.start(); 38 | thrust::reverse(d_vec.begin(), d_vec.end()); 39 | cudaDeviceSynchronize(); 40 | t.stop(); 41 | } 42 | std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl; 43 | 44 | // transfer data back to host 45 | thrust::copy(d_vec.begin(), d_vec.end(), h_vec.begin()); 46 | 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /test/test_for_each.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #define BOOST_TEST_MODULE TestForEach 12 | #include 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #include "context_setup.hpp" 21 | 22 | namespace bc = boost::compute; 23 | 24 | BOOST_AUTO_TEST_CASE(for_each_nop) 25 | { 26 | bc::vector vector(4, context); 27 | bc::iota(vector.begin(), vector.end(), 0, queue); 28 | 29 | BOOST_COMPUTE_FUNCTION(void, nop, (int ignored), {}); 30 | 31 | bc::for_each(vector.begin(), vector.end(), nop, queue); 32 | queue.finish(); 33 | } 34 | 35 | BOOST_AUTO_TEST_CASE(for_each_n_nop) 36 | { 37 | bc::vector vector(4, context); 38 | bc::iota(vector.begin(), vector.end(), 0, queue); 39 | 40 | BOOST_COMPUTE_FUNCTION(void, nop, (int ignored), {}); 41 | 42 | bc::for_each_n(vector.begin(), vector.size(), nop, queue); 43 | queue.finish(); 44 | } 45 | 46 | BOOST_AUTO_TEST_SUITE_END() 47 | -------------------------------------------------------------------------------- /test/test_inplace_merge.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #define BOOST_TEST_MODULE TestInplaceMerge 12 | #include 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | #include "check_macros.hpp" 19 | #include "context_setup.hpp" 20 | 21 | namespace compute = boost::compute; 22 | 23 | BOOST_AUTO_TEST_CASE(simple_merge_int) 24 | { 25 | int data[] = { 1, 3, 5, 7, 2, 4, 6, 8 }; 26 | compute::vector vector(data, data + 8, queue); 27 | 28 | // merge each half in-place 29 | compute::inplace_merge( 30 | vector.begin(), 31 | vector.begin() + 4, 32 | vector.end(), 33 | queue 34 | ); 35 | CHECK_RANGE_EQUAL(int, 8, vector, (1, 2, 3, 4, 5, 6, 7, 8)); 36 | 37 | // run again on already sorted list 38 | compute::inplace_merge( 39 | vector.begin(), 40 | vector.begin() + 4, 41 | vector.end(), 42 | queue 43 | ); 44 | CHECK_RANGE_EQUAL(int, 8, vector, (1, 2, 3, 4, 5, 6, 7, 8)); 45 | } 46 | 47 | BOOST_AUTO_TEST_SUITE_END() 48 | -------------------------------------------------------------------------------- /include/boost/compute/functional/geometry.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_FUNCTIONAL_GEOMETRY_HPP 12 | #define BOOST_COMPUTE_FUNCTIONAL_GEOMETRY_HPP 13 | 14 | #include 15 | #include 16 | 17 | namespace boost { 18 | namespace compute { 19 | 20 | BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(cross, T (T, T), class T) 21 | BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(dot, typename scalar_type::type (T, T), class T) 22 | BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(distance, typename scalar_type::type (T, T), class T) 23 | BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(fast_distance, typename scalar_type::type (T, T), class T) 24 | BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(length, typename scalar_type::type (T), class T) 25 | BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(fast_length, typename scalar_type::type (T), class T) 26 | BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(normalize, T (T), class T) 27 | BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(fast_normalize, T (T), class T) 28 | 29 | } // end compute namespace 30 | } // end boost namespace 31 | 32 | #endif // BOOST_COMPUTE_FUNCTIONAL_GEOMETRY_HPP 33 | -------------------------------------------------------------------------------- /perf/perf_stl_partition_point.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2014 Roshan 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include "perf.hpp" 17 | 18 | int rand_int() 19 | { 20 | return static_cast((rand() / double(RAND_MAX)) * 25.0); 21 | } 22 | 23 | bool less_than_20(int value) 24 | { 25 | return value < 20; 26 | } 27 | 28 | int main(int argc, char *argv[]) 29 | { 30 | perf_parse_args(argc, argv); 31 | std::cout << "size: " << PERF_N << std::endl; 32 | 33 | // create vector of random numbers on the host 34 | std::vector host_vector(PERF_N); 35 | std::generate(host_vector.begin(), host_vector.end(), rand_int); 36 | std::partition(host_vector.begin(), host_vector.end(), 37 | less_than_20); 38 | perf_timer t; 39 | for(size_t trial = 0; trial < PERF_TRIALS; trial++){ 40 | t.start(); 41 | std::partition_point(host_vector.begin(), host_vector.end(), 42 | less_than_20); 43 | t.stop(); 44 | } 45 | std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl; 46 | 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /perf/perf_thrust_reverse_copy.cu: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2015 Jakub Szuppe 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #include "perf.hpp" 22 | 23 | int main(int argc, char *argv[]) 24 | { 25 | perf_parse_args(argc, argv); 26 | 27 | std::cout << "size: " << PERF_N << std::endl; 28 | thrust::host_vector h_vec = generate_random_vector(PERF_N); 29 | 30 | // transfer data to the device 31 | thrust::device_vector d_vec; 32 | d_vec = h_vec; 33 | 34 | // device vector for reversed data 35 | thrust::device_vector d_reversed_vec(PERF_N); 36 | 37 | perf_timer t; 38 | for(size_t trial = 0; trial < PERF_TRIALS; trial++){ 39 | t.start(); 40 | thrust::reverse_copy(d_vec.begin(), d_vec.end(), d_reversed_vec.begin()); 41 | cudaDeviceSynchronize(); 42 | t.stop(); 43 | } 44 | std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl; 45 | 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /perf/perf_thrust_partial_sum.cu: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #include "perf.hpp" 22 | 23 | int main(int argc, char *argv[]) 24 | { 25 | perf_parse_args(argc, argv); 26 | 27 | std::cout << "size: " << PERF_N << std::endl; 28 | thrust::host_vector h_vec = generate_random_vector(PERF_N); 29 | 30 | // transfer data to the device 31 | thrust::device_vector d_vec = h_vec; 32 | 33 | perf_timer t; 34 | for(size_t trial = 0; trial < PERF_TRIALS; trial++){ 35 | d_vec = h_vec; 36 | 37 | t.start(); 38 | thrust::inclusive_scan(d_vec.begin(), d_vec.end(), d_vec.begin()); 39 | cudaDeviceSynchronize(); 40 | t.stop(); 41 | } 42 | std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl; 43 | 44 | // transfer data back to host 45 | thrust::copy(d_vec.begin(), d_vec.end(), h_vec.begin()); 46 | 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /test/test_functional_popcount.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #define BOOST_TEST_MODULE TestFunctionalPopcount 12 | #include 13 | #include 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | #include "check_macros.hpp" 20 | #include "context_setup.hpp" 21 | 22 | namespace compute = boost::compute; 23 | 24 | typedef boost::mpl::list< 25 | compute::uchar_, compute::ushort_, compute::uint_, compute::ulong_ 26 | > popcount_test_types; 27 | 28 | BOOST_AUTO_TEST_CASE_TEMPLATE(popcount, T, popcount_test_types) 29 | { 30 | compute::vector vec(context); 31 | vec.push_back(0x00, queue); 32 | vec.push_back(0x01, queue); 33 | vec.push_back(0x03, queue); 34 | vec.push_back(0xff, queue); 35 | 36 | compute::vector popcounts(vec.size(), context); 37 | compute::transform( 38 | vec.begin(), vec.end(), popcounts.begin(), compute::popcount(), queue 39 | ); 40 | CHECK_RANGE_EQUAL(int, 4, popcounts, (0, 1, 2, 8)); 41 | } 42 | 43 | BOOST_AUTO_TEST_SUITE_END() 44 | -------------------------------------------------------------------------------- /include/boost/compute/interop/qt/qvector.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_INTEROP_QT_QVECTOR_HPP 12 | #define BOOST_COMPUTE_INTEROP_QT_QVECTOR_HPP 13 | 14 | #include 15 | 16 | #include 17 | 18 | namespace boost { 19 | namespace compute { 20 | namespace detail { 21 | 22 | template 23 | struct _is_contiguous_iterator< 24 | Iterator, 25 | typename boost::enable_if< 26 | typename boost::is_same< 27 | Iterator, 28 | typename QVector::iterator 29 | >::type 30 | >::type 31 | > : public boost::true_type {}; 32 | 33 | template 34 | struct _is_contiguous_iterator< 35 | Iterator, 36 | typename boost::enable_if< 37 | typename boost::is_same< 38 | Iterator, 39 | typename QVector::const_iterator 40 | >::type 41 | >::type 42 | > : public boost::true_type {}; 43 | 44 | } // end detail namespace 45 | } // end compute namespace 46 | } // end boost namespace 47 | 48 | #endif // BOOST_COMPUTE_INTEROP_QT_QVECTOR_HPP 49 | -------------------------------------------------------------------------------- /test/test_function_input_iterator.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #define BOOST_TEST_MODULE TestFunctionInputIterator 12 | #include 13 | 14 | #include 15 | 16 | #include 17 | #include 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include "check_macros.hpp" 25 | #include "context_setup.hpp" 26 | 27 | BOOST_AUTO_TEST_CASE(generate_42_doctest) 28 | { 29 | boost::compute::vector result(4, context); 30 | 31 | //! [generate_42] 32 | BOOST_COMPUTE_FUNCTION(int, ret42, (), 33 | { 34 | return 42; 35 | }); 36 | 37 | boost::compute::copy( 38 | boost::compute::make_function_input_iterator(ret42, 0), 39 | boost::compute::make_function_input_iterator(ret42, result.size()), 40 | result.begin(), 41 | queue 42 | ); 43 | 44 | // result == { 42, 42, 42, 42 } 45 | //! [generate_42] 46 | 47 | CHECK_RANGE_EQUAL(int, 4, result, (42, 42, 42, 42)); 48 | } 49 | 50 | BOOST_AUTO_TEST_SUITE_END() 51 | -------------------------------------------------------------------------------- /include/boost/compute/detail/global_static.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_DETAIL_GLOBAL_STATIC_HPP 12 | #define BOOST_COMPUTE_DETAIL_GLOBAL_STATIC_HPP 13 | 14 | #include 15 | 16 | #ifdef BOOST_COMPUTE_THREAD_SAFE 17 | # ifdef BOOST_COMPUTE_HAVE_THREAD_LOCAL 18 | // use c++11 thread local storage 19 | # define BOOST_COMPUTE_DETAIL_GLOBAL_STATIC(type, name, ctor) \ 20 | thread_local type name ctor; 21 | # else 22 | // use thread_specific_ptr from boost.thread 23 | # include 24 | # define BOOST_COMPUTE_DETAIL_GLOBAL_STATIC(type, name, ctor) \ 25 | static ::boost::thread_specific_ptr< type > BOOST_PP_CAT(name, _tls_ptr_); \ 26 | if(!BOOST_PP_CAT(name, _tls_ptr_).get()){ \ 27 | BOOST_PP_CAT(name, _tls_ptr_).reset(new type ctor); \ 28 | } \ 29 | static type &name = *BOOST_PP_CAT(name, _tls_ptr_); 30 | # endif 31 | #else 32 | // no thread-safety, just use static 33 | # define BOOST_COMPUTE_DETAIL_GLOBAL_STATIC(type, name, ctor) \ 34 | static type name ctor; 35 | #endif 36 | 37 | #endif // BOOST_COMPUTE_DETAIL_GLOBAL_STATIC_HPP 38 | -------------------------------------------------------------------------------- /perf/perf_bernoulli_distribution.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2014 Roshan 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #include "perf.hpp" 21 | 22 | namespace compute = boost::compute; 23 | 24 | int main(int argc, char *argv[]) 25 | { 26 | perf_parse_args(argc, argv); 27 | std::cout << "size: " << PERF_N << std::endl; 28 | 29 | compute::device device = compute::system::default_device(); 30 | compute::context context(device); 31 | compute::command_queue queue(context, device); 32 | 33 | compute::vector vector(PERF_N, context); 34 | 35 | compute::default_random_engine rng(queue); 36 | compute::bernoulli_distribution dist(0.5); 37 | 38 | perf_timer t; 39 | t.start(); 40 | dist.generate(vector.begin(), vector.end(), rng, queue); 41 | queue.finish(); 42 | t.stop(); 43 | std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl; 44 | 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /perf/perf_stl_saxpy.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "perf.hpp" 16 | 17 | float rand_float() 18 | { 19 | return (float(rand()) / float(RAND_MAX)) * 1000.f; 20 | } 21 | 22 | // y <- alpha * x + y 23 | void serial_saxpy(size_t n, float alpha, const float *x, float *y) 24 | { 25 | for(size_t i = 0; i < n; i++){ 26 | y[i] = alpha * x[i] + y[i]; 27 | } 28 | } 29 | 30 | int main(int argc, char *argv[]) 31 | { 32 | perf_parse_args(argc, argv); 33 | 34 | std::cout << "size: " << PERF_N << std::endl; 35 | 36 | float alpha = 2.5f; 37 | 38 | std::vector host_x(PERF_N); 39 | std::vector host_y(PERF_N); 40 | std::generate(host_x.begin(), host_x.end(), rand_float); 41 | std::generate(host_y.begin(), host_y.end(), rand_float); 42 | 43 | perf_timer t; 44 | for(size_t trial = 0; trial < PERF_TRIALS; trial++){ 45 | t.start(); 46 | serial_saxpy(PERF_N, alpha, &host_x[0], &host_y[0]); 47 | t.stop(); 48 | } 49 | std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl; 50 | 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /include/boost/compute/algorithm/for_each_n.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_ALGORITHM_FOR_EACH_N_HPP 12 | #define BOOST_COMPUTE_ALGORITHM_FOR_EACH_N_HPP 13 | 14 | #include 15 | 16 | #include 17 | #include 18 | 19 | namespace boost { 20 | namespace compute { 21 | 22 | /// Calls \p function on each element in the range [\p first, \p first 23 | /// \c + \p count). 24 | /// 25 | /// Space complexity: \Omega(1) 26 | /// 27 | /// \see for_each() 28 | template 29 | inline UnaryFunction for_each_n(InputIterator first, 30 | Size count, 31 | UnaryFunction function, 32 | command_queue &queue = system::default_queue()) 33 | { 34 | BOOST_STATIC_ASSERT(is_device_iterator::value); 35 | return ::boost::compute::for_each(first, first + count, function, queue); 36 | } 37 | 38 | } // end compute namespace 39 | } // end boost namespace 40 | 41 | #endif // BOOST_COMPUTE_ALGORITHM_FOR_EACH_N_HPP 42 | -------------------------------------------------------------------------------- /perf/perf_fill.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #include 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | #include "perf.hpp" 18 | 19 | int main(int argc, char *argv[]) 20 | { 21 | perf_parse_args(argc, argv); 22 | std::cout << "size: " << PERF_N << std::endl; 23 | 24 | // setup context and queue for the default device 25 | boost::compute::device device = boost::compute::system::default_device(); 26 | boost::compute::context context(device); 27 | boost::compute::command_queue queue(context, device); 28 | std::cout << "device: " << device.name() << std::endl; 29 | 30 | // create vector on the device (filled with zeros) 31 | boost::compute::vector vec(PERF_N, 0, queue); 32 | 33 | perf_timer t; 34 | for(size_t trial = 0; trial < PERF_TRIALS; trial++){ 35 | t.start(); 36 | boost::compute::fill(vec.begin(), vec.end(), int(trial), queue); 37 | queue.finish(); 38 | t.stop(); 39 | } 40 | std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl; 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /include/boost/compute/algorithm/all_of.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_ALGORITHM_ALL_OF_HPP 12 | #define BOOST_COMPUTE_ALGORITHM_ALL_OF_HPP 13 | 14 | #include 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | namespace boost { 21 | namespace compute { 22 | 23 | /// Returns \c true if \p predicate returns \c true for all of the elements in 24 | /// the range [\p first, \p last). 25 | /// 26 | /// Space complexity: \Omega(1) 27 | /// 28 | /// \see any_of(), none_of() 29 | template 30 | inline bool all_of(InputIterator first, 31 | InputIterator last, 32 | UnaryPredicate predicate, 33 | command_queue &queue = system::default_queue()) 34 | { 35 | BOOST_STATIC_ASSERT(is_device_iterator::value); 36 | return ::boost::compute::find_if_not(first, last, predicate, queue) == last; 37 | } 38 | 39 | } // end compute namespace 40 | } // end boost namespace 41 | 42 | #endif // BOOST_COMPUTE_ALGORITHM_ALL_OF_HPP 43 | -------------------------------------------------------------------------------- /include/boost/compute/algorithm/none_of.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_ALGORITHM_NONE_OF_HPP 12 | #define BOOST_COMPUTE_ALGORITHM_NONE_OF_HPP 13 | 14 | #include 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | namespace boost { 21 | namespace compute { 22 | 23 | /// Returns \c true if \p predicate returns \c true for none of the elements in 24 | /// the range [\p first, \p last). 25 | /// 26 | /// Space complexity: \Omega(1) 27 | /// 28 | /// \see all_of(), any_of() 29 | template 30 | inline bool none_of(InputIterator first, 31 | InputIterator last, 32 | UnaryPredicate predicate, 33 | command_queue &queue = system::default_queue()) 34 | { 35 | BOOST_STATIC_ASSERT(is_device_iterator::value); 36 | return ::boost::compute::find_if(first, last, predicate, queue) == last; 37 | } 38 | 39 | } // end compute namespace 40 | } // end boost namespace 41 | 42 | #endif // BOOST_COMPUTE_ALGORITHM_NONE_OF_HPP 43 | -------------------------------------------------------------------------------- /include/boost/compute/interop/opencv/ocl.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_INTEROP_OPENCV_OCL_HPP 12 | #define BOOST_COMPUTE_INTEROP_OPENCV_OCL_HPP 13 | 14 | #include 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | namespace boost { 21 | namespace compute { 22 | 23 | context opencv_ocl_get_context() 24 | { 25 | void *ocl_context = cv::ocl::getoclContext(); 26 | if(!ocl_context){ 27 | return context(); 28 | } 29 | 30 | return context(*(static_cast(ocl_context))); 31 | } 32 | 33 | command_queue opencv_ocl_get_command_queue() 34 | { 35 | void *ocl_queue = cv::ocl::getoclCommandQueue(); 36 | if(!ocl_queue){ 37 | return command_queue(); 38 | } 39 | 40 | return command_queue(*(static_cast(ocl_queue))); 41 | } 42 | 43 | buffer opencv_ocl_get_buffer(const cv::ocl::oclMat &mat) 44 | { 45 | return buffer(reinterpret_cast(mat.data)); 46 | } 47 | 48 | } // end compute namespace 49 | } // end boost namespace 50 | 51 | #endif // BOOST_COMPUTE_INTEROP_OPENCV_OCL_HPP 52 | -------------------------------------------------------------------------------- /perf/perf_thrust_count.cu: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | #include "perf.hpp" 20 | 21 | int rand_int() 22 | { 23 | return static_cast((rand() / double(RAND_MAX)) * 25.0); 24 | } 25 | 26 | int main(int argc, char *argv[]) 27 | { 28 | perf_parse_args(argc, argv); 29 | std::cout << "size: " << PERF_N << std::endl; 30 | 31 | // create vector of random numbers on the host 32 | thrust::host_vector host_vector(PERF_N); 33 | thrust::generate(host_vector.begin(), host_vector.end(), rand_int); 34 | 35 | thrust::device_vector v = host_vector; 36 | 37 | size_t count = 0; 38 | perf_timer t; 39 | for(size_t trial = 0; trial < PERF_TRIALS; trial++){ 40 | t.start(); 41 | count = thrust::count(v.begin(), v.end(), 4); 42 | cudaDeviceSynchronize(); 43 | t.stop(); 44 | } 45 | std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl; 46 | std::cout << "count: " << count << std::endl; 47 | 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /example/print_vector.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | namespace compute = boost::compute; 20 | 21 | // this example demonstrates how to print the values in a vector 22 | int main() 23 | { 24 | // get default device and setup context 25 | compute::device gpu = compute::system::default_device(); 26 | compute::context context(gpu); 27 | compute::command_queue queue(context, gpu); 28 | std::cout << "device: " << gpu.name() << std::endl; 29 | 30 | // create vector on the device and fill with the sequence 1..10 31 | compute::vector vector(10, context); 32 | compute::iota(vector.begin(), vector.end(), 1, queue); 33 | 34 | //[print_vector_example 35 | std::cout << "vector: [ "; 36 | boost::compute::copy( 37 | vector.begin(), vector.end(), 38 | std::ostream_iterator(std::cout, ", "), 39 | queue 40 | ); 41 | std::cout << "]" << std::endl; 42 | //] 43 | 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /include/boost/compute/detail/iterator_range_size.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_DETAIL_ITERATOR_RANGE_SIZE_H 12 | #define BOOST_COMPUTE_DETAIL_ITERATOR_RANGE_SIZE_H 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | namespace boost { 19 | namespace compute { 20 | namespace detail { 21 | 22 | // This is a convenience function which returns the size of a range 23 | // bounded by two iterators. This function has two differences from 24 | // the std::distance() function: 1) the return type (size_t) is 25 | // unsigned, and 2) the return value is always positive. 26 | template 27 | inline size_t iterator_range_size(Iterator first, Iterator last) 28 | { 29 | typedef typename 30 | std::iterator_traits::difference_type 31 | difference_type; 32 | 33 | difference_type difference = std::distance(first, last); 34 | 35 | return static_cast( 36 | (std::max)(difference, static_cast(0)) 37 | ); 38 | } 39 | 40 | } // end detail namespace 41 | } // end compute namespace 42 | } // end boost namespace 43 | 44 | #endif // BOOST_COMPUTE_DETAIL_ITERATOR_RANGE_SIZE_H 45 | -------------------------------------------------------------------------------- /perf/perf_uniform_int_distribution.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2014 Roshan 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #include "perf.hpp" 21 | 22 | namespace compute = boost::compute; 23 | 24 | int main(int argc, char *argv[]) 25 | { 26 | perf_parse_args(argc, argv); 27 | std::cout << "size: " << PERF_N << std::endl; 28 | 29 | compute::device device = compute::system::default_device(); 30 | compute::context context(device); 31 | compute::command_queue queue(context, device); 32 | 33 | compute::vector vector(PERF_N, context); 34 | 35 | compute::default_random_engine rng(queue); 36 | compute::uniform_int_distribution dist(0, 1); 37 | 38 | perf_timer t; 39 | t.start(); 40 | dist.generate(vector.begin(), vector.end(), rng, queue); 41 | queue.finish(); 42 | t.stop(); 43 | std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl; 44 | 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /test/test_async_wait_guard.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2015 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #define BOOST_TEST_MODULE TestAsyncWaitGuard 12 | #include 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #include "check_macros.hpp" 21 | #include "context_setup.hpp" 22 | 23 | namespace compute = boost::compute; 24 | 25 | static size_t wait_num = 0; 26 | 27 | struct waitable_object 28 | { 29 | void wait() 30 | { 31 | wait_num++; 32 | } 33 | }; 34 | 35 | BOOST_AUTO_TEST_CASE(wait_guard_test) 36 | { 37 | waitable_object waitable; 38 | 39 | BOOST_CHECK(wait_num == 0); 40 | { 41 | compute::wait_guard waitable_object_guard(waitable); 42 | } 43 | BOOST_CHECK(wait_num == 1); 44 | { 45 | compute::wait_guard waitable_object_guard1(waitable); 46 | compute::wait_guard waitable_object_guard2(waitable); 47 | } 48 | BOOST_CHECK(wait_num == 3); 49 | } 50 | 51 | BOOST_AUTO_TEST_SUITE_END() 52 | -------------------------------------------------------------------------------- /include/boost/compute/allocator/pinned_allocator.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_ALLOCATOR_PINNED_ALLOCATOR_HPP 12 | #define BOOST_COMPUTE_ALLOCATOR_PINNED_ALLOCATOR_HPP 13 | 14 | #include 15 | 16 | namespace boost { 17 | namespace compute { 18 | 19 | template 20 | class pinned_allocator : public buffer_allocator 21 | { 22 | public: 23 | explicit pinned_allocator(const context &context) 24 | : buffer_allocator(context) 25 | { 26 | buffer_allocator::set_mem_flags( 27 | buffer::read_write | buffer::alloc_host_ptr 28 | ); 29 | } 30 | 31 | pinned_allocator(const pinned_allocator &other) 32 | : buffer_allocator(other) 33 | { 34 | } 35 | 36 | pinned_allocator& operator=(const pinned_allocator &other) 37 | { 38 | if(this != &other){ 39 | buffer_allocator::operator=(other); 40 | } 41 | 42 | return *this; 43 | } 44 | 45 | ~pinned_allocator() 46 | { 47 | } 48 | }; 49 | 50 | } // end compute namespace 51 | } // end boost namespace 52 | 53 | #endif // BOOST_COMPUTE_ALLOCATOR_PINNED_ALLOCATOR_HPP 54 | -------------------------------------------------------------------------------- /example/mapped_view.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | namespace compute = boost::compute; 19 | 20 | // this example demonstrates how to use the mapped_view class to map 21 | // an array of numbers to device memory and use the reduce() algorithm 22 | // to calculate the sum. 23 | int main() 24 | { 25 | // get default device and setup context 26 | compute::device gpu = compute::system::default_device(); 27 | compute::context context(gpu); 28 | compute::command_queue queue(context, gpu); 29 | std::cout << "device: " << gpu.name() << std::endl; 30 | 31 | // create data on host 32 | int data[] = { 4, 2, 3, 7, 8, 9, 1, 6 }; 33 | 34 | // create mapped view on device 35 | compute::mapped_view view(data, 8, context); 36 | 37 | // use reduce() to calculate sum on the device 38 | int sum = 0; 39 | compute::reduce(view.begin(), view.end(), &sum, queue); 40 | 41 | // print the sum on the host 42 | std::cout << "sum: " << sum << std::endl; 43 | 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /example/list_devices.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #include 12 | 13 | #include 14 | 15 | namespace compute = boost::compute; 16 | 17 | int main() 18 | { 19 | std::vector platforms = compute::system::platforms(); 20 | 21 | for(size_t i = 0; i < platforms.size(); i++){ 22 | const compute::platform &platform = platforms[i]; 23 | 24 | std::cout << "Platform '" << platform.name() << "'" << std::endl; 25 | 26 | std::vector devices = platform.devices(); 27 | for(size_t j = 0; j < devices.size(); j++){ 28 | const compute::device &device = devices[j]; 29 | 30 | std::string type; 31 | if(device.type() & compute::device::gpu) 32 | type = "GPU Device"; 33 | else if(device.type() & compute::device::cpu) 34 | type = "CPU Device"; 35 | else if(device.type() & compute::device::accelerator) 36 | type = "Accelerator Device"; 37 | else 38 | type = "Unknown Device"; 39 | 40 | std::cout << " " << type << ": " << device.name() << std::endl; 41 | } 42 | } 43 | 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /include/boost/compute/functional/detail/nvidia_ballot.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_FUNCTIONAL_DETAIL_NVIDIA_BALLOT_HPP 12 | #define BOOST_COMPUTE_FUNCTIONAL_DETAIL_NVIDIA_BALLOT_HPP 13 | 14 | #include 15 | #include 16 | 17 | namespace boost { 18 | namespace compute { 19 | namespace detail { 20 | 21 | template 22 | class nvidia_ballot : public function 23 | { 24 | public: 25 | nvidia_ballot() 26 | : function("nvidia_ballot") 27 | { 28 | this->set_source( 29 | "inline uint nvidia_ballot(const uint x)\n" 30 | "{\n" 31 | " uint result;\n" 32 | " asm volatile(\n" 33 | " \"setp.ne.u32 %%p1, %1, 0;\"\n" 34 | " \"vote.ballot.b32 %0, %%p1;\"\n" 35 | " : \"=r\"(result)\n" 36 | " : \"r\"(x)\n" 37 | " );\n" 38 | " return result;\n" 39 | "}\n" 40 | ); 41 | } 42 | }; 43 | 44 | } // end detail namespace 45 | } // end compute namespace 46 | } // end boost namespace 47 | 48 | #endif // BOOST_COMPUTE_FUNCTIONAL_DETAIL_NVIDIA_BALLOT_HPP 49 | -------------------------------------------------------------------------------- /include/boost/compute/exception/set_default_queue_error.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2019 Anthony Chang 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_EXCEPTION_SET_DEFAULT_QUEUE_ERROR_HPP 12 | #define BOOST_COMPUTE_EXCEPTION_SET_DEFAULT_QUEUE_ERROR_HPP 13 | 14 | #include 15 | 16 | namespace boost { 17 | namespace compute { 18 | 19 | /// \class set_default_queue_error 20 | /// \brief Exception thrown when failure to set default command queue 21 | /// 22 | /// This exception is thrown when Boost.Compute fails to set up user-provided 23 | /// default command queue for the system. 24 | class set_default_queue_error : public std::exception 25 | { 26 | public: 27 | /// Creates a new set_default_queue_error exception object. 28 | set_default_queue_error() throw() 29 | { 30 | } 31 | 32 | /// Destroys the set_default_queue_error object. 33 | ~set_default_queue_error() throw() 34 | { 35 | } 36 | 37 | /// Returns a string with a description of the error. 38 | const char* what() const throw() 39 | { 40 | return "User command queue mismatches default device and/or context"; 41 | } 42 | }; 43 | 44 | } // end compute namespace 45 | } // end boost namespace 46 | 47 | #endif // BOOST_COMPUTE_EXCEPTION_SET_DEFAULT_QUEUE_ERROR_HPP 48 | -------------------------------------------------------------------------------- /perf/perf_discrete_distribution.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2014 Roshan 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #include "perf.hpp" 21 | 22 | namespace compute = boost::compute; 23 | 24 | int main(int argc, char *argv[]) 25 | { 26 | perf_parse_args(argc, argv); 27 | std::cout << "size: " << PERF_N << std::endl; 28 | 29 | compute::device device = compute::system::default_device(); 30 | compute::context context(device); 31 | compute::command_queue queue(context, device); 32 | 33 | compute::vector vector(PERF_N, context); 34 | 35 | int weights[] = {1, 1}; 36 | 37 | compute::default_random_engine rng(queue); 38 | compute::discrete_distribution dist(weights, weights+2); 39 | 40 | perf_timer t; 41 | t.start(); 42 | dist.generate(vector.begin(), vector.end(), rng, queue); 43 | queue.finish(); 44 | t.stop(); 45 | std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl; 46 | 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /include/boost/compute/algorithm/binary_search.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_ALGORITHM_BINARY_SEARCH_HPP 12 | #define BOOST_COMPUTE_ALGORITHM_BINARY_SEARCH_HPP 13 | 14 | #include 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | namespace boost { 22 | namespace compute { 23 | 24 | /// Returns \c true if \p value is in the sorted range [\p first, 25 | /// \p last). 26 | /// 27 | /// Space complexity: \Omega(1) 28 | template 29 | inline bool binary_search(InputIterator first, 30 | InputIterator last, 31 | const T &value, 32 | command_queue &queue = system::default_queue()) 33 | { 34 | BOOST_STATIC_ASSERT(is_device_iterator::value); 35 | InputIterator position = lower_bound(first, last, value, queue); 36 | 37 | return position != last && position.read(queue) == value; 38 | } 39 | 40 | } // end compute namespace 41 | } // end boost namespace 42 | 43 | #endif // BOOST_COMPUTE_ALGORITHM_BINARY_SEARCH_HPP 44 | -------------------------------------------------------------------------------- /include/boost/compute/algorithm/find_if.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_ALGORITHM_FIND_IF_HPP 12 | #define BOOST_COMPUTE_ALGORITHM_FIND_IF_HPP 13 | 14 | #include 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | namespace boost { 22 | namespace compute { 23 | 24 | /// Returns an iterator pointing to the first element in the range 25 | /// [\p first, \p last) for which \p predicate returns \c true. 26 | /// 27 | /// Space complexity: \Omega(1) 28 | template 29 | inline InputIterator find_if(InputIterator first, 30 | InputIterator last, 31 | UnaryPredicate predicate, 32 | command_queue &queue = system::default_queue()) 33 | { 34 | BOOST_STATIC_ASSERT(is_device_iterator::value); 35 | return detail::find_if_with_atomics(first, last, predicate, queue); 36 | } 37 | 38 | } // end compute namespace 39 | } // end boost namespace 40 | 41 | #endif // BOOST_COMPUTE_ALGORITHM_FIND_IF_HPP 42 | -------------------------------------------------------------------------------- /include/boost/compute/detail/literal.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_DETAIL_LITERAL_HPP 12 | #define BOOST_COMPUTE_DETAIL_LITERAL_HPP 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | #include 19 | 20 | #include 21 | 22 | namespace boost { 23 | namespace compute { 24 | namespace detail { 25 | 26 | template 27 | std::string make_literal(T x) 28 | { 29 | std::stringstream s; 30 | s << std::setprecision( 31 | #ifndef BOOST_NO_CXX11_NUMERIC_LIMITS 32 | std::numeric_limits::max_digits10 33 | #else 34 | // We don't have max_digits10, so add 3 other digits (this is what is required for 35 | // float, and is one more than required for double). 36 | 3 + std::numeric_limits::digits10 37 | #endif 38 | ) 39 | << std::scientific 40 | << x; 41 | 42 | if(boost::is_same::value || boost::is_same::value){ 43 | s << "f"; 44 | } 45 | 46 | return s.str(); 47 | } 48 | 49 | } // end detail namespace 50 | } // end compute namespace 51 | } // end boost namespace 52 | 53 | #endif // BOOST_COMPUTE_DETAIL_LITERAL_HPP 54 | -------------------------------------------------------------------------------- /include/boost/compute/experimental/malloc.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #ifndef BOOST_COMPUTE_EXPERIMENTAL_MALLOC_HPP 12 | #define BOOST_COMPUTE_EXPERIMENTAL_MALLOC_HPP 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | namespace boost { 20 | namespace compute { 21 | namespace experimental { 22 | 23 | // bring device_ptr into the experimental namespace 24 | using detail::device_ptr; 25 | 26 | template 27 | inline device_ptr 28 | malloc(std::size_t size, const context &context = system::default_context()) 29 | { 30 | buffer buf(context, size * sizeof(T)); 31 | clRetainMemObject(buf.get()); 32 | return device_ptr(buf); 33 | } 34 | 35 | inline device_ptr 36 | malloc(std::size_t size, const context &context = system::default_context()) 37 | { 38 | return malloc(size, context); 39 | } 40 | 41 | template 42 | inline void free(device_ptr &ptr) 43 | { 44 | clReleaseMemObject(ptr.get_buffer().get()); 45 | } 46 | 47 | } // end experimental namespace 48 | } // end compute namespace 49 | } // end boost namespace 50 | 51 | #endif // BOOST_COMPUTE_EXPERIMENTAL_MALLOC_HPP 52 | -------------------------------------------------------------------------------- /test/test_platform.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2013-2014 Kyle Lutz 3 | // 4 | // Distributed under the Boost Software License, Version 1.0 5 | // See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt 7 | // 8 | // See http://boostorg.github.com/compute for more information. 9 | //---------------------------------------------------------------------------// 10 | 11 | #define BOOST_TEST_MODULE TestPlatform 12 | #include 13 | 14 | #include 15 | 16 | #include 17 | #include 18 | 19 | BOOST_AUTO_TEST_CASE(platform_id) 20 | { 21 | boost::compute::platform platform = 22 | boost::compute::system::platforms().front(); 23 | 24 | boost::compute::platform platform_copy(platform.id()); 25 | 26 | BOOST_CHECK(platform == platform_copy); 27 | BOOST_CHECK(platform.id() == platform_copy.id()); 28 | } 29 | 30 | BOOST_AUTO_TEST_CASE(platform_supports_extension) 31 | { 32 | boost::compute::platform platform = 33 | boost::compute::system::platforms().front(); 34 | 35 | std::string extensions = platform.get_info(); 36 | if(extensions.empty()){ 37 | std::cerr << "platform doesn't support any extensions" << std::endl; 38 | return; 39 | } 40 | 41 | size_t space = extensions.find(' '); 42 | std::string first_extension = extensions.substr(0, space); 43 | BOOST_CHECK(platform.supports_extension(first_extension) == true); 44 | BOOST_CHECK(platform.supports_extension("invalid_extension_name") == false); 45 | } 46 | --------------------------------------------------------------------------------