HPXCL
/home/diehl/git/hpxcl/cuda/program.hpp
00001 // Copyright (c)                2013 Damond Howard
00002 //                                              2015 Patrick Diehl
00003 // Distributed under the Boost Software License, Version 1.0. (See accompanying
00004 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt
00005 #pragma once
00006 #ifndef HPX_CUDA_PROGRAM_HPP_
00007 #define HPX_CUDA_PROGRAM_HPP_
00008 
00009 #include <hpx/include/components.hpp>
00010 #include "cuda/server/program.hpp"
00011 #include "cuda/buffer.hpp"
00012 
00013 namespace hpx {
00014 namespace cuda {
00015 
00029 class program: public hpx::components::client_base<program, server::program> {
00030         typedef hpx::components::client_base<program, server::program> base_type;
00031 
00032 public:
00033 
00034         program() {
00035         }
00036 
00037         program(hpx::future<hpx::naming::id_type> && gid) :
00038                         base_type(std::move(gid)) {
00039         }
00040 
00058         hpx::lcos::future<void> build(std::vector<std::string> compilerFlags,
00059                         std::vector<std::string> modulenames, unsigned int debug = 0) {
00060                 HPX_ASSERT(this->get_gid());
00061                 typedef server::program::build_action action_type;
00062                 return hpx::async<action_type>(this->get_gid(), compilerFlags,
00063                                 modulenames, debug);
00064         }
00065 
00070         void build_sync(std::vector<std::string> compilerFlags,
00071                         std::string modulename, unsigned int debug = 0) {
00072                 std::vector<std::string> modulenames;
00073                 modulenames.push_back(modulename);
00074                 build(compilerFlags, modulenames, debug).get();
00075         }
00076 
00077         hpx::lcos::future<void> build(std::vector<std::string> compilerFlags,
00078                         std::string modulename, unsigned int debug = 0) {
00079                 HPX_ASSERT(this->get_gid());
00080                 std::vector<std::string> modulenames;
00081                 modulenames.push_back(modulename);
00082                 typedef server::program::build_action action_type;
00083                 return hpx::async<action_type>(this->get_gid(), compilerFlags,
00084                                 modulenames, debug);
00085         }
00086 
00091         void build_sync(std::vector<std::string> compilerFlags,
00092                         std::vector<std::string> modulenames, unsigned int debug = 0) {
00093                 build(compilerFlags, modulenames, debug).get();
00094         }
00095 
00099         void set_source_sync(std::string source) {
00100                 HPX_ASSERT(this->get_gid());
00101                 typedef server::program::set_source_action action_type;
00102                 hpx::async<action_type>(this->get_gid(), source).get();
00103         }
00104 
00120         hpx::lcos::future<void> run(std::vector<hpx::cuda::buffer> args,
00121                         std::string modulename, hpx::cuda::server::program::Dim3 grid,
00122                         hpx::cuda::server::program::Dim3 block, int stream = -1) {
00123 
00124                 HPX_ASSERT(this->get_gid());
00125 
00126                 std::vector<hpx::naming::id_type> args_id;
00127 
00128                 for (unsigned int i = 0; i < args.size(); i++) {
00129 
00130                         args_id.push_back(args[i].get_id());
00131                 }
00132 
00133                 std::vector<hpx::naming::id_type> dependencies;
00134 
00135                 typedef server::program::run_action action_type;
00136                 return hpx::async<action_type>(this->get_gid(), args_id, modulename,
00137                                 grid, block, dependencies, stream);
00138 
00139         }
00140 
00156         hpx::lcos::future<void> run(std::vector<hpx::cuda::buffer> args,
00157                         std::string modulename, hpx::cuda::server::program::Dim3 grid,
00158                         hpx::cuda::server::program::Dim3 block,
00159                         std::vector<hpx::cuda::buffer> dependencies, int stream = -1) {
00160 
00161                 HPX_ASSERT(this->get_gid());
00162 
00163                 std::vector<hpx::naming::id_type> args_id;
00164 
00165                 for (unsigned int i = 0; i < args.size(); i++) {
00166 
00167                         args_id.push_back(args[i].get_id());
00168                 }
00169 
00170                 std::vector<hpx::naming::id_type> dependencies_id;
00171 
00172                 for (unsigned int i = 0; i < dependencies.size(); i++) {
00173 
00174                         dependencies_id.push_back(dependencies[i].get_id());
00175                 }
00176 
00177                 typedef server::program::run_action action_type;
00178                 return hpx::async<action_type>(this->get_gid(), args_id, modulename,
00179                                 grid, block, dependencies_id, stream);
00180 
00181         }
00182 
00183         hpx::lcos::future<void> run(std::vector<hpx::cuda::buffer> args,
00184                         std::string modulename, hpx::cuda::server::program::Dim3 grid,
00185                         hpx::cuda::server::program::Dim3 block,
00186                         hpx::cuda::buffer dependency, int stream = -1) {
00187 
00188                 HPX_ASSERT(this->get_gid());
00189 
00190                 std::vector<hpx::naming::id_type> args_id;
00191 
00192                 for (unsigned int i = 0; i < args.size(); i++) {
00193 
00194                         args_id.push_back(args[i].get_id());
00195                 }
00196 
00197                 std::vector<hpx::naming::id_type> dependencies_id;
00198                 dependencies_id.push_back(dependency.get_id());
00199 
00200                 typedef server::program::run_action action_type;
00201                 return hpx::async<action_type>(this->get_gid(), args_id, modulename,
00202                                 grid, block, dependencies_id, stream);
00203 
00204         }
00205 
00213         hpx::lcos::future<unsigned int> get_streams_size() {
00214                 HPX_ASSERT(this->get_gid());
00215                 typedef server::program::get_streams_size_action action_type;
00216                 return hpx::async<action_type>(this->get_gid());
00217 
00218         }
00219 
00227         hpx::lcos::future<unsigned int> create_stream() {
00228                 HPX_ASSERT(this->get_gid());
00229                 typedef server::program::create_stream_action action_type;
00230                 return hpx::async<action_type>(this->get_gid());
00231         }
00232 
00233 };
00234 }
00235 }
00236 #endif //PROGRAM_1_HPP
 All Classes Functions