Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate RAJA execution policies specification from linear algebra classes implementations #240

Closed
pelesh opened this issue May 31, 2021 · 4 comments
Assignees

Comments

@pelesh
Copy link
Collaborator

pelesh commented May 31, 2021

Linear algebra classes that use preprocessor directives to specify RAJA execution policies. This may become cumbersome as we add more execution policies (CUDA, HIP, etc.). Furthermore, each linear algebra object implementation duplicates part of policy specifications adding some maintenance overhead. Consider specifying RAJA policies within a container class in a separate source file.

CC @ashermancinelli @cameronrutherford @nychiang @cnpetra

Potential additional benefits: In addition to making linear algebra code more compact, this could simplify creation of linear algebra class templates parametrized by execution type. See #241 for more details. Currently, same execution policies are set at configure time for all linear algebra objects in HiOp.

@pelesh
Copy link
Collaborator Author

pelesh commented May 31, 2021

Possible solution could be to create policy specification containers like this:

// hiopExecPolicies.hpp

#include <hiop_defs.hpp>

#ifdef HIOP_USE_RAJA

#ifdef HIOP_USE_GPU
struct hiopCudaPolicies
{
  hiopExecutionPolicies() = default;
  using hiop_raja_exec   = RAJA::cuda_exec<HIOP_CUDA_BLOCK_SIZE>;
  using hiop_raja_reduce = RAJA::cuda_reduce;
  using hiop_raja_atomic = RAJA::cuda_atomic;
  namespace policy_namespace = RAJA;
};
#endif // HIOP_USE_GPU

struct hiopOmpPolicies
{
  hiopExecutionPolicies() = default;
  using hiop_raja_exec   = RAJA::omp_parallel_for_exec;
  using hiop_raja_reduce = RAJA::omp_reduce;
  using hiop_raja_atomic = RAJA::omp_atomic;
  namespace policy_namespace = RAJA;
};

#endif // HIOP_USE_RAJA

Then in, for example, hiopVectorRajaPar class, one can simplify the preprocessor directives like this:

// hiopVectorRajaPar.cpp

#include <hiopExecPolicies.hpp>

// some code

#ifdef HIOP_USE_GPU  
#include "cuda.h"
#define RAJA_LAMBDA [=] __device__
using hiop_policy_type = hiopCudaPolicies;
#else  
#define RAJA_LAMBDA [=]
using hiop_policy_type = hiopOmpPolicies;
#endif

using hiop_raja_exec   = hiop_policy_type::hiop_raja_exec;
using hiop_raja_reduce = hiop_policy_type::hiop_raja_reduce;
using hiop_raja_atomic = hiop_policy_type::hiop_raja_atomic;
namespace policy_namespace = hiop_policy_type::policy_namespace;

// more code ...

@ashermancinelli
Copy link
Contributor

I think these are great ideas, but what's the point of policy_namespace? Is this foreshadowing some hiopForAll function that doesn't use a raja policy?

@pelesh
Copy link
Collaborator Author

pelesh commented May 31, 2021

I think these are great ideas, but what's the point of policy_namespace? Is this foreshadowing some hiopForAll function that doesn't use a raja policy?

Yes, indeed. This could allow for replacing RAJA function forall and objects Range, ReduceSum, etc. with those from HiOp namespace. With that, you could create RAJA and non-RAJA linear algebra objects from the same code by just passing appropriate template parameter. At least, that is the idea.

@cnpetra
Copy link
Collaborator

cnpetra commented Dec 19, 2022

closed by #543 with a couple of small, follow-up action items tracked by #574

@cnpetra cnpetra closed this as completed Dec 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants