Skip to content

Commit

Permalink
build fixes for raja launch x kernel naming
Browse files Browse the repository at this point in the history
  • Loading branch information
artv3 committed Dec 27, 2024
1 parent b638b00 commit ddfcf77
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 174 deletions.
2 changes: 1 addition & 1 deletion examples/dynamic_mat_transpose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ int main(int argc, char *argv[])
RAJA::launch<launch_policy>
(res, RAJA::LaunchParams(RAJA::Teams(outer_Dimc, outer_Dimr),
RAJA::Threads(TILE_DIM, TILE_DIM), dynamic_shared_mem_size),
"Matrix tranpose with dynamic shared memory kernel",
RAJA::expt::KernelName("Matrix tranpose with dynamic shared memory kernel"),
[=] RAJA_HOST_DEVICE(RAJA::LaunchContext ctx)
{
RAJA::loop<outer1>(ctx, RAJA::RangeSegment(0, outer_Dimr), [&] (int by){
Expand Down
6 changes: 4 additions & 2 deletions examples/launch-param-reductions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,15 @@ int main(int RAJA_UNUSED_ARG(argc), char** RAJA_UNUSED_ARG(argv[]))
RAJA::Index_type seq_maxloc2(-1);

RAJA::launch<LAUNCH_POL1>
(host_res, RAJA::LaunchParams(), "SeqReductionKernel",
(host_res, RAJA::LaunchParams(),
RAJA::expt::Reduce<RAJA::operators::plus >(&seq_sum),
RAJA::expt::Reduce<RAJA::operators::minimum>(&seq_min),
RAJA::expt::Reduce<RAJA::operators::maximum>(&seq_max),
RAJA::expt::Reduce<RAJA::operators::minimum>(&seq_minloc),
RAJA::expt::Reduce<RAJA::operators::maximum>(&seq_maxloc),
RAJA::expt::ReduceLoc<RAJA::operators::minimum>(&seq_min2, &seq_minloc2),
RAJA::expt::ReduceLoc<RAJA::operators::maximum>(&seq_max2, &seq_maxloc2),
RAJA::expt::KernelName("SeqReductionKernel"),
[=] RAJA_HOST_DEVICE ( RAJA::LaunchContext ctx,
VALOP_INT_SUM &_seq_sum,
VALOP_INT_MIN &_seq_min,
Expand Down Expand Up @@ -218,14 +219,15 @@ int main(int RAJA_UNUSED_ARG(argc), char** RAJA_UNUSED_ARG(argv[]))
RAJA::Index_type omp_maxloc2(-1);

RAJA::launch<LAUNCH_POL2>
(host_res, RAJA::LaunchParams(), "OmpReductionKernel",
(host_res, RAJA::LaunchParams(),
RAJA::expt::Reduce<RAJA::operators::plus >(&omp_sum),
RAJA::expt::Reduce<RAJA::operators::minimum>(&omp_min),
RAJA::expt::Reduce<RAJA::operators::maximum>(&omp_max),
RAJA::expt::Reduce<RAJA::operators::minimum>(&omp_minloc),
RAJA::expt::Reduce<RAJA::operators::maximum>(&omp_maxloc),
RAJA::expt::ReduceLoc<RAJA::operators::minimum>(&omp_min2, &omp_minloc2),
RAJA::expt::ReduceLoc<RAJA::operators::maximum>(&omp_max2, &omp_maxloc2),
RAJA::expt::KernelName("OmpReductionKernel"),
[=] RAJA_HOST_DEVICE (RAJA::LaunchContext ctx,
VALOP_INT_SUM &_omp_sum,
VALOP_INT_MIN &_omp_min,
Expand Down
2 changes: 1 addition & 1 deletion examples/launch_reductions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ int main(int argc, char *argv[])
(select_cpu_or_gpu,
RAJA::LaunchParams(RAJA::Teams(GRID_SZ),
RAJA::Threads(TEAM_SZ)),
"Launch Reductions",
RAJA::expt::KernelName("Launch Reductions"),
[=] RAJA_HOST_DEVICE(RAJA::LaunchContext ctx)
{

Expand Down
175 changes: 7 additions & 168 deletions include/RAJA/pattern/launch/launch_core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,53 +215,13 @@ class LaunchContext
}
};

//-----------

template <typename LAUNCH_POLICY>
struct LaunchExecute;

//Policy based launch with support to new reducers...
template <typename LAUNCH_POLICY, typename ... ReduceParams>
void launch(LaunchParams const &launch_params, const char *kernel_name, ReduceParams&&... rest_of_launch_args)
{

//Get reducers
auto reducers = expt::make_forall_param_pack(std::forward<ReduceParams>(rest_of_launch_args)...);

//kernel name
std::string kname;

auto&& launch_body = expt::get_lambda(std::forward<ReduceParams>(rest_of_launch_args)...);

//Take the first policy as we assume the second policy is not user defined.
//We rely on the user to pair launch and loop policies correctly.
util::PluginContext context{util::make_context<typename LAUNCH_POLICY::host_policy_t>(&kname)};
util::callPreCapturePlugins(context);

using RAJA::util::trigger_updates_before;
auto p_body = trigger_updates_before(launch_body);

util::callPostCapturePlugins(context);

util::callPreLaunchPlugins(context);

using launch_t = LaunchExecute<typename LAUNCH_POLICY::host_policy_t>;

using Res = typename resources::get_resource<typename LAUNCH_POLICY::host_policy_t>::type;

launch_t::exec(Res::get_default(), launch_params, kernel_name, p_body, reducers);

util::callPostLaunchPlugins(context);
}


//Duplicate of code above on account that we need to support the case in which a kernel_name is not given
template <typename LAUNCH_POLICY, typename ... ReduceParams>
void launch(LaunchParams const &launch_params, ReduceParams&&... rest_of_launch_args)
{
std::cout<<"-----RAJA launch!----"<<std::endl;
const char *kernel_name_ptr = nullptr;

//Get reducers
auto reducers = expt::make_forall_param_pack(std::forward<ReduceParams>(rest_of_launch_args)...);

Expand All @@ -287,7 +247,7 @@ void launch(LaunchParams const &launch_params, ReduceParams&&... rest_of_launch_

using Res = typename resources::get_resource<typename LAUNCH_POLICY::host_policy_t>::type;

launch_t::exec(Res::get_default(), launch_params, kernel_name_ptr, p_body, reducers);
launch_t::exec(Res::get_default(), launch_params, nullptr, p_body, reducers);

util::callPostLaunchPlugins(context);
}
Expand All @@ -301,78 +261,25 @@ void launch(ExecPlace place, LaunchParams const &params, BODY const &body)
launch<POLICY_LIST>(place, params, nullptr, body);
}

template <typename POLICY_LIST, typename BODY>
void launch(ExecPlace place, const LaunchParams &params, const char *kernel_name, BODY const &body)
{

//Forward to single policy launch API - simplifies testing of plugins
switch (place) {
case ExecPlace::HOST: {
using Res = typename resources::get_resource<typename POLICY_LIST::host_policy_t>::type;
launch<LaunchPolicy<typename POLICY_LIST::host_policy_t>>(Res::get_default(), params, kernel_name, body);
break;
}
#if defined(RAJA_GPU_ACTIVE)
case ExecPlace::DEVICE: {
using Res = typename resources::get_resource<typename POLICY_LIST::device_policy_t>::type;
launch<LaunchPolicy<typename POLICY_LIST::device_policy_t>>(Res::get_default(), params, kernel_name, body);
break;
}
#endif
default:
RAJA_ABORT_OR_THROW("Unknown launch place or device is not enabled");
}

}

//Run-time API for new reducer interface
template <typename POLICY_LIST, typename... ReduceParams>
void launch(ExecPlace place, const LaunchParams &launch_params, const char *kernel_name, ReduceParams&&... rest_of_launch_args)
{

//Forward to single policy launch API - simplifies testing of plugins
switch (place) {
case ExecPlace::HOST: {
using Res = typename resources::get_resource<typename POLICY_LIST::host_policy_t>::type;
launch<LaunchPolicy<typename POLICY_LIST::host_policy_t>>
(Res::get_default(), launch_params, kernel_name, std::forward<ReduceParams>(rest_of_launch_args)...);
break;
}
#if defined(RAJA_GPU_ACTIVE)
case ExecPlace::DEVICE: {
using Res = typename resources::get_resource<typename POLICY_LIST::device_policy_t>::type;
launch<LaunchPolicy<typename POLICY_LIST::device_policy_t>>
(Res::get_default(), launch_params, kernel_name, std::forward<ReduceParams>(rest_of_launch_args)...);
break;
}
#endif
default:
RAJA_ABORT_OR_THROW("Unknown launch place or device is not enabled");
}

}

//Run-time API for new reducer interface with support of the case without a new kernel name
template <typename POLICY_LIST, typename... ReduceParams>
void launch(ExecPlace place, const LaunchParams &launch_params, ReduceParams&&... rest_of_launch_args)
//BODY const &body)
{

const char *kernel_name = nullptr;

//Forward to single policy launch API - simplifies testing of plugins
switch (place) {
case ExecPlace::HOST: {
using Res = typename resources::get_resource<typename POLICY_LIST::host_policy_t>::type;
launch<LaunchPolicy<typename POLICY_LIST::host_policy_t>>
(Res::get_default(), launch_params, kernel_name, std::forward<ReduceParams>(rest_of_launch_args)...);
(Res::get_default(), launch_params, std::forward<ReduceParams>(rest_of_launch_args)...);
break;
}
#if defined(RAJA_GPU_ACTIVE)
case ExecPlace::DEVICE: {
using Res = typename resources::get_resource<typename POLICY_LIST::device_policy_t>::type;
launch<LaunchPolicy<typename POLICY_LIST::device_policy_t>>
(Res::get_default(), launch_params, kernel_name, std::forward<ReduceParams>(rest_of_launch_args)...);
(Res::get_default(), launch_params, std::forward<ReduceParams>(rest_of_launch_args)...);
break;
}
#endif
Expand Down Expand Up @@ -400,73 +307,6 @@ RAJA::resources::Resource Get_Host_Resource(T host_res, RAJA::ExecPlace device){
}

//Launch API which takes team resource struct and supports new reducers
template <typename POLICY_LIST, typename ... ReduceParams>
resources::EventProxy<resources::Resource>
launch(RAJA::resources::Resource res, LaunchParams const &launch_params,
const char *kernel_name, ReduceParams&&... rest_of_launch_args)
{

//Get reducers
auto reducers = expt::make_forall_param_pack(std::forward<ReduceParams>(rest_of_launch_args)...);

auto&& launch_body = expt::get_lambda(std::forward<ReduceParams>(rest_of_launch_args)...);

ExecPlace place;
if(res.get_platform() == RAJA::Platform::host) {
place = RAJA::ExecPlace::HOST;
} else {
place = RAJA::ExecPlace::DEVICE;
}

//Get kernel name
std::string kname;

//
//Configure plugins
//
#if defined(RAJA_GPU_ACTIVE)
util::PluginContext context{place == ExecPlace::HOST ?
util::make_context<typename POLICY_LIST::host_policy_t>(&kname) :
util::make_context<typename POLICY_LIST::device_policy_t>(&kname)};
#else
util::PluginContext context{util::make_context<typename POLICY_LIST::host_policy_t>(&kname)};
#endif

util::callPreCapturePlugins(context);

using RAJA::util::trigger_updates_before;
auto p_body = trigger_updates_before(launch_body);

util::callPostCapturePlugins(context);

util::callPreLaunchPlugins(context);

switch (place) {
case ExecPlace::HOST: {
using launch_t = LaunchExecute<typename POLICY_LIST::host_policy_t>;
resources::EventProxy<resources::Resource> e_proxy = launch_t::exec(res, launch_params, kernel_name, p_body, reducers);
util::callPostLaunchPlugins(context);
return e_proxy;
}
#if defined(RAJA_GPU_ACTIVE)
case ExecPlace::DEVICE: {
using launch_t = LaunchExecute<typename POLICY_LIST::device_policy_t>;
resources::EventProxy<resources::Resource> e_proxy = launch_t::exec(res, launch_params, kernel_name, p_body, reducers);
util::callPostLaunchPlugins(context);
return e_proxy;
}
#endif
default: {
RAJA_ABORT_OR_THROW("Unknown launch place or device is not enabled");
}
}

RAJA_ABORT_OR_THROW("Unknown launch place");

//^^ RAJA will abort before getting here
return resources::EventProxy<resources::Resource>(res);
}


//Duplicate of API above on account that we need to handle the case that a kernel name is not provided
template <typename POLICY_LIST, typename ... ReduceParams>
Expand All @@ -475,12 +315,11 @@ launch(RAJA::resources::Resource res, LaunchParams const &launch_params,
ReduceParams&&... rest_of_launch_args)
{

const char *kernel_name = nullptr;

//Get reducers
auto reducers = expt::make_forall_param_pack(std::forward<ReduceParams>(rest_of_launch_args)...);

std::string kname;
auto kernel_name = expt::get_kernel_name(std::forward<ReduceParams>(rest_of_launch_args)...);
std::string kname = get_kernel_name<decltype(kernel_name)>::get(kernel_name);

auto&& launch_body = expt::get_lambda(std::forward<ReduceParams>(rest_of_launch_args)...);

Expand Down Expand Up @@ -514,14 +353,14 @@ launch(RAJA::resources::Resource res, LaunchParams const &launch_params,
switch (place) {
case ExecPlace::HOST: {
using launch_t = LaunchExecute<typename POLICY_LIST::host_policy_t>;
resources::EventProxy<resources::Resource> e_proxy = launch_t::exec(res, launch_params, kernel_name, p_body, reducers);
resources::EventProxy<resources::Resource> e_proxy = launch_t::exec(res, launch_params, nullptr, p_body, reducers);
util::callPostLaunchPlugins(context);
return e_proxy;
}
#if defined(RAJA_GPU_ACTIVE)
case ExecPlace::DEVICE: {
using launch_t = LaunchExecute<typename POLICY_LIST::device_policy_t>;
resources::EventProxy<resources::Resource> e_proxy = launch_t::exec(res, launch_params, kernel_name, p_body, reducers);
resources::EventProxy<resources::Resource> e_proxy = launch_t::exec(res, launch_params, nullptr, p_body, reducers);
util::callPostLaunchPlugins(context);
return e_proxy;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ void LaunchParamExptReduceMinBasicTestImpl(const SEG_TYPE& seg,

RAJA::launch<LAUNCH_POLICY>
(RAJA::LaunchParams(RAJA::Teams(blocks), RAJA::Threads(threads)),
"LaunchMinBasicTest",
RAJA::expt::Reduce<RAJA::operators::minimum>(&mininit),
RAJA::expt::Reduce<RAJA::operators::minimum>(&min),
RAJA::expt::KernelName("LaunchMinBasicTest"),
[=] RAJA_HOST_DEVICE(RAJA::LaunchContext ctx, REF_MIN &_mininit, REF_MIN &_min) {

RAJA::loop<GLOBAL_THREAD_POLICY>(ctx, seg, [&](IDX_TYPE idx) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ void LaunchParamExptReduceSumBasicTestImpl(const SEG_TYPE& seg,

RAJA::launch<LAUNCH_POLICY>
(RAJA::LaunchParams(RAJA::Teams(blocks), RAJA::Threads(threads)),
"LaunchSumBasicTest",
RAJA::expt::Reduce<RAJA::operators::plus>(&sum),
RAJA::expt::Reduce<RAJA::operators::plus>(&sum2),
RAJA::expt::KernelName("LaunchSumBasicTest"),
[=] RAJA_HOST_DEVICE(RAJA::LaunchContext ctx, REF_SUM &_sum, REF_SUM &_sum2) {

RAJA::loop<GLOBAL_THREAD_POLICY>(ctx, seg, [&](IDX_TYPE idx) {
Expand Down

0 comments on commit ddfcf77

Please sign in to comment.