Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mcopik
Created September 12, 2017 10:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcopik/06220318f8d3b88ef732b74e14084565 to your computer and use it in GitHub Desktop.
Save mcopik/06220318f8d3b88ef732b74e14084565 to your computer and use it in GitHub Desktop.
///////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2016 Marcin Copik
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
///////////////////////////////////////////////////////////////////////////////
#include <hpx/include/compute.hpp>
#include <hpx/include/partitioned_vector.hpp>
#include <hpx/include/parallel_copy.hpp>
#include <hpx/hpx_init.hpp>
#include <numeric>
#include <iostream>
#include <string>
#include <vector>
int hpx_main(boost::program_options::variables_map& vm)
{
unsigned int seed = (unsigned int)std::time(nullptr);
if (vm.count("seed"))
seed = vm["seed"].as<unsigned int>();
std::cout << "using seed: " << seed << std::endl;
std::srand(seed);
int const N = 100;
std::vector<int> host(N);
std::vector<int> new_host(N);
std::iota(host.begin(), host.end(), (std::rand() % 100));
typedef hpx::compute::sycl::allocator<int> target_allocator;
//{
hpx::compute::sycl::target target;
target_allocator alloc(target);
hpx::compute::vector<int, target_allocator> device(N, alloc);
std::cout << "Write at 0 val " << host[0] << "\n";
device[0] = host[0];
std::cout << "Read at 0 val " << device[0] << "\n";
hpx::parallel::copy(hpx::parallel::par, host.begin(), host.end(), device.begin());
hpx::parallel::copy(hpx::parallel::par, device.begin(), device.end(), new_host.begin());
target.synchronize();
if (!std::equal(host.begin(), host.end(), new_host.begin())) {
std::cout << "Wrong copy - not equal!" << std::endl;
}
hpx::compute::sycl::detail::launch<class Kernel>(target, N, 32,
[=](size_t idx, cl::sycl::global_ptr<int> ptr) mutable {
if (idx >= N)
return;
ptr[idx] += 1.0;
}, device.data());
target.synchronize();
{hpx::future<void> f = target.get_future();
std::cout << "Future" << std::endl;
}//f.get();}
std::cout << "Future exists" << std::endl;
/*target.synchronize();*/
//hpx::parallel::copy(hpx::parallel::par, device.begin(), device.end(), new_host.begin());
// }
std::cout << host[0] << " " << new_host[0] << std::endl;
return hpx::finalize();
}
int main(int argc, char* argv[])
{
// add command line option which controls the random number generator seed
using namespace boost::program_options;
options_description desc_commandline(
"Usage: " HPX_APPLICATION_STRING " [options]");
desc_commandline.add_options()
("seed,s", value<unsigned int>(),
"the random number generator seed to use for this run")
;
// Initialize and run HPX
return hpx::init(desc_commandline, argc, argv);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment