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

Use RAJA plugin capability #224

Merged
merged 46 commits into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
3270b20
plugins
Jun 22, 2023
623221d
Delete BenchmarkPlugin.cpp
neelakausik Jun 22, 2023
a779f5e
undoing accidental changes
Jun 22, 2023
0128aee
Merge branch 'feature/kausik1/plugins' of https://github.com/LLNL/CAR…
Jun 22, 2023
ac5f37e
fix RAJAPlugin.cpp
Jun 22, 2023
e932a33
resolved some issues
Jun 22, 2023
2cbb56e
small tweak
Jun 22, 2023
5a4ee77
fixed formatting
Jun 23, 2023
bb73878
trying to revert 2 files and deleted RAJAPlugin class
Jun 23, 2023
4838863
replaced calls to RAJAPlugin
Jun 26, 2023
4b21f12
fixing build errors hopefully
Jun 26, 2023
7d0f25e
fix vector error
Jun 28, 2023
0e556f3
Merge branch 'develop' into feature/kausik1/plugins
neelakausik Jun 29, 2023
2941ed7
Merge branch 'develop' into feature/kausik1/plugins
adayton1 Jun 29, 2023
c758f8f
new class for plugin data
Jun 29, 2023
15ce40b
Merge branch 'feature/kausik1/plugins' of https://github.com/LLNL/CAR…
Jun 29, 2023
37eaa87
manually set chai execution space for 2d
Jun 29, 2023
ee08aca
fixed plugindata class
Jun 30, 2023
1b2a7c0
remove unnecessary includes
Jun 30, 2023
ce7f9ec
fixed formatting and small issues
Jul 5, 2023
07ad1d5
registration function
Jul 5, 2023
b968cf9
fixed reg function
Jul 5, 2023
1c4e47f
Merge branch 'develop' into feature/kausik1/plugins
neelakausik Jul 5, 2023
d2241d3
resolved comments
Jul 11, 2023
c046990
Merge branch 'feature/kausik1/plugins' of https://github.com/LLNL/CAR…
Jul 11, 2023
e98394e
Delete BenchmarkForall.cpp
neelakausik Jul 11, 2023
7422eb6
removed streams stuff
Jul 11, 2023
f5899fc
Merge branch 'feature/kausik1/plugins' of https://github.com/LLNL/CAR…
Jul 11, 2023
50858aa
restored orignal BenchmarkForall.cpp
Jul 11, 2023
5119e23
Care->CARE
Jul 11, 2023
3d66171
resolved more comments
Jul 11, 2023
95ad98a
resolved comments and errors
Jul 11, 2023
00efa02
fixes profileplugin registration
Jul 11, 2023
80a8b17
added comments and formatting
Jul 11, 2023
f4388e0
fixed HIP warning
Jul 11, 2023
36cf8a0
tweaked plugindata description
Jul 12, 2023
52475a1
actionmap alias
Jul 12, 2023
7ef02b2
forgot one actionmap
Jul 12, 2023
6d59f0a
move actionmap inside care namespace
Jul 13, 2023
65ab328
fix indentation
Jul 13, 2023
6fabbdb
Merge branch 'develop' into feature/kausik1/plugins
adayton1 Jul 13, 2023
013ff95
try to fix printf errors
Jul 13, 2023
8f42b88
Merge branch 'feature/kausik1/plugins' of https://github.com/LLNL/CAR…
Jul 13, 2023
6c887d0
fixed warnings in debugplugin and forall
Jul 13, 2023
c123396
maybe silence profileplugin warnings
Jul 13, 2023
52504cd
forall unused parameter warning
Jul 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .radiuss-ci
neelakausik marked this conversation as resolved.
Show resolved Hide resolved
neelakausik marked this conversation as resolved.
Show resolved Hide resolved
Submodule .radiuss-ci updated 102 files
169 changes: 169 additions & 0 deletions src/care/DebugPlugin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
#include "care/DebugPlugin.h"

#include "chai/ArrayManager.hpp"
neelakausik marked this conversation as resolved.
Show resolved Hide resolved

#include "chai/ExecutionSpaces.hpp"

#include "care/CHAICallback.h"

#include "care/RAJAPlugin.h"

/* CUDA profiling macros */
#if defined(__CUDACC__) && CARE_HAVE_NVTOOLSEXT
#include "nvToolsExt.h"
#endif

// Std library headers
#if defined(CARE_DEBUG) && !defined(_WIN32)
#include <execinfo.h>
#endif // defined(CARE_DEBUG) && !defined(_WIN32)

#include <unordered_set>

using namespace care;

namespace chai{

std::string s_current_loop_file_name = "N/A";
int s_current_loop_line_number = -1;
std::vector<const chai::PointerRecord*> s_active_pointers_in_loop = std::vector<const chai::PointerRecord*>{};

DebugPlugin::DebugPlugin() {}

/////////////////////////////////////////////////////////////////////////////////
///
/// @brief Set up to be done before executing a RAJA loop.
///
/// @arg[in] space The execution space
/// @arg[in] name The name of the loop
///
/////////////////////////////////////////////////////////////////////////////////

void
DebugPlugin::preLaunch(const RAJA::util::PluginContext& p) {
#if !defined(CHAI_DISABLE_RM)
// Prepare to record CHAI data
if (CHAICallback::isActive()) {
s_current_loop_file_name = fileName;
s_current_loop_line_number = lineNumber;
s_active_pointers_in_loop.clear();

#if defined(CARE_GPUCC) && defined(CARE_DEBUG)
GPUWatchpoint::setOrCheckWatchpoint<int>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@robinson96, can we remove the GPUWatchpoint stuff? Since we are not passing any address to it, I don't see how it can do anything useful.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see - you'd have to manually set a watchpoint before the loop. But I looked it up and cuda-gdb at least has the ability to set a watchpoint on both host and GPU memory. So I don't think we need this watchpoint code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, wait. cuda-gdb only supports watchpoints on host memory. Sad day.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The question still remains, though, is this used enough to keep it around? I've never used it myself.

Copy link
Member

@adayton1 adayton1 Jul 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the ROCm platform supports watchpoints on device memory: https://docs.amd.com/projects/ROCdbgapi/en/docs-5.0.0/doxygen/docBin/html/group__watchpoint__group.html

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we can leave the support in for now and it would be easy to remove later if we decide to get rid of it.

#endif // defined(CARE_GPUCC) && defined(CARE_DEBUG)
}
#endif // !defined(CHAI_DISABLE_RM)

}



void
DebugPlugin::postLaunch(const RAJA::util::PluginContext& p) {
#if !defined(CHAI_DISABLE_RM)

chai::ExecutionSpace space;
neelakausik marked this conversation as resolved.
Show resolved Hide resolved

switch (p.platform) {
case RAJA::Platform::host:
space = chai::CPU; break;
#if defined(CHAI_ENABLE_CUDA)
case RAJA::Platform::cuda:
space = chai::GPU; break;
#endif
#if defined(CHAI_ENABLE_HIP)
case RAJA::Platform::hip:
space = chai::GPU; break;
#endif
default:
space = chai::NONE;
}

if (CHAICallback::isActive()) {
writeLoopData(space, fileName, lineNumber);

// Clear out the captured arrays
s_active_pointers_in_loop.clear();

#if defined(CARE_GPUCC) && defined(CARE_DEBUG)
GPUWatchpoint::setOrCheckWatchpoint<int>();
#endif // defined(CARE_GPUCC) && defined(CARE_DEBUG)
}

#endif // !defined(CHAI_DISABLE_RM)
}

void
DebugPlugin::writeLoopData(chai::ExecutionSpace space, const char * fileName, int lineNumber) {
if (CHAICallback::loggingIsEnabled()) {
const int s_log_data = CHAICallback::getLogData();

if (s_log_data == (int) space ||
s_log_data == (int) chai::ExecutionSpace::NUM_EXECUTION_SPACES) {
// Get the output file
FILE* callback_output_file = CHAICallback::getLogFile();

// Write the loop header
int numArrays = 0;
std::unordered_set<const chai::PointerRecord*> usedRecords;

for (const chai::PointerRecord* record : s_active_pointers_in_loop) {
if (usedRecords.count(record) > 0) {
continue;
}
else {
usedRecords.emplace(record);
++numArrays;
}
}

fprintf(callback_output_file, "[CARE] AFTER LOOP EXECUTION %s:%i (%i arrays)\n", fileName, lineNumber, numArrays);

#if defined(CARE_DEBUG) && !defined(_WIN32)
// Write the stack trace
const int stackDepth = 16;
void *stackArray[stackDepth];
size_t stackSize = backtrace(stackArray, stackDepth);
char **stackStrings = backtrace_symbols(stackArray, stackSize);

// Skip the first two contexts
for (size_t i = 2 ; i < stackSize ; ++i) {
fprintf(callback_output_file, "[CARE] [STACK] %lu: %s\n", i, stackStrings[i]);
}

if (CHAICallback::isDiffFriendly()) {
// For diff-friendly output, keep the number of lines constant
for (size_t i = stackSize ; i < stackDepth ; ++i) {
fprintf(callback_output_file, "[CARE] [STACK] %lu: <empty>\n", i);
}
}

free(stackStrings);
#endif // defined(CARE_DEBUG) && !defined(_WIN32)

// Flush to the output file
fflush(callback_output_file);

#ifdef CARE_DEBUG
// Write the arrays captured in the loop
usedRecords.clear();

for (const chai::PointerRecord* record : s_active_pointers_in_loop) {
if (record && usedRecords.find(record) == usedRecords.end()) {
usedRecords.emplace(record);
CHAICallback::writeArray(record, space);
fflush(callback_output_file);
}
}
#else // CARE_DEBUG
// Write message that -logchaidata is not supported
fprintf(callback_output_file, "[CARE] [CHAI] -logchaidata is not supported in this build\n");
fflush(callback_output_file);
#endif // CARE_DEBUG
}
}
}
}

static RAJA::util::PluginRegistry::add<chai::DebugPlugin> L ("Debug plugin", "test");

45 changes: 45 additions & 0 deletions src/care/DebugPlugin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#ifndef _CARE_DebugPlugin_H_
#define _CARE_DebugPlugin_H_

#include "RAJA/util/PluginStrategy.hpp"
#include "chai/ExecutionSpaces.hpp"
#include "care/config.h"
#include "care/CHAICallback.h"
#include "care/RAJAPlugin.h"

using namespace care;

namespace care{

class RAJAPlugin;

}

namespace chai{

class DebugPlugin : public RAJA::util::PluginStrategy
{
public:
DebugPlugin();

char * fileName;

int lineNumber;

void preLaunch(const RAJA::util::PluginContext& p) override;

void postLaunch(const RAJA::util::PluginContext& p) override;

void writeLoopData(chai::ExecutionSpace space, const char * fileName, int lineNumber);

private:

std::string s_current_loop_file_name;

int s_current_loop_line_number;

std::vector<const chai::PointerRecord*> s_active_pointers_in_loop;
};
}

#endif
86 changes: 86 additions & 0 deletions src/care/ProfilePlugin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#include "care/ProfilePlugin.h"

#include "chai/ArrayManager.hpp"
neelakausik marked this conversation as resolved.
Show resolved Hide resolved

#include "chai/ExecutionSpaces.hpp"

#include "care/CHAICallback.h"

#include "care/RAJAPlugin.h"

/* CUDA profiling macros */
#if defined(__CUDACC__) && CARE_HAVE_NVTOOLSEXT
#include "nvToolsExt.h"
#endif

// Std library headers
#if defined(CARE_DEBUG) && !defined(_WIN32)
#include <execinfo.h>
#endif // defined(CARE_DEBUG) && !defined(_WIN32)

#include <unordered_set>
neelakausik marked this conversation as resolved.
Show resolved Hide resolved

using namespace care;
neelakausik marked this conversation as resolved.
Show resolved Hide resolved

namespace chai{
neelakausik marked this conversation as resolved.
Show resolved Hide resolved

bool s_profile_host_loops = true;
static uint32_t s_colors[7];
static int s_num_colors;
static unsigned int s_current_color;

ProfilePlugin::ProfilePlugin() {}

/////////////////////////////////////////////////////////////////////////////////
///
/// @brief Set up to be done before executing a RAJA loop.
///
/// @arg[in] space The execution space
/// @arg[in] name The name of the loop
///
/////////////////////////////////////////////////////////////////////////////////

void
ProfilePlugin::preLaunch(const RAJA::util::PluginContext& p) {
#if CARE_HAVE_NVTOOLSEXT
adayton1 marked this conversation as resolved.
Show resolved Hide resolved
#if defined(CARE_GPUCC)
neelakausik marked this conversation as resolved.
Show resolved Hide resolved
// Profile the host loops
if (s_profile_host_loops) {
if (p.platform == RAJA::Platform::host) {
std::string name = fileName + std::to_string(lineNumber);

int color_id = s_current_color + 1;
color_id = color_id % s_num_colors;

// TODO: Add error checking
nvtxEventAttributes_t eventAttrib = { 0 };
eventAttrib.version = NVTX_VERSION;
eventAttrib.size = NVTX_EVENT_ATTRIB_STRUCT_SIZE;
eventAttrib.colorType = NVTX_COLOR_ARGB;
eventAttrib.color = s_colors[color_id];
eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII;
eventAttrib.message.ascii = name.c_str();
nvtxRangePushEx(&eventAttrib);
}
}
#endif // CARE_HAVE_NVTOOLSEXT
#endif // defined(CARE_GPUCC)
adayton1 marked this conversation as resolved.
Show resolved Hide resolved
}

void
ProfilePlugin::postLaunch(const RAJA::util::PluginContext& p) {
#if defined(CARE_GPUCC)
if (s_profile_host_loops) {
if (p.platform == RAJA::Platform::host) {
// TODO: Add error checking
nvtxRangePop();
}
}
#endif

}
}

static RAJA::util::PluginRegistry::add<chai::ProfilePlugin> L ("Care profile plugin", "test");


46 changes: 46 additions & 0 deletions src/care/ProfilePlugin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#ifndef _CARE_ProfilePlugin_H_
#define _CARE_ProfilePlugin_H_

#include "RAJA/util/PluginStrategy.hpp"
#include "chai/ExecutionSpaces.hpp"
#include "care/config.h"
#include "care/CHAICallback.h"
#include "care/RAJAPlugin.h"

using namespace care;
neelakausik marked this conversation as resolved.
Show resolved Hide resolved

namespace care{

class RAJAPlugin;
neelakausik marked this conversation as resolved.
Show resolved Hide resolved

}

namespace chai{
neelakausik marked this conversation as resolved.
Show resolved Hide resolved

class ProfilePlugin : public RAJA::util::PluginStrategy
neelakausik marked this conversation as resolved.
Show resolved Hide resolved
{
public:
ProfilePlugin();

char * fileName;
neelakausik marked this conversation as resolved.
Show resolved Hide resolved

int lineNumber;

void preLaunch(const RAJA::util::PluginContext& p) override;

void postLaunch(const RAJA::util::PluginContext& p) override;

private:

bool s_profile_host_loops;

unsigned int s_current_color;

int s_num_colors;

uint32_t s_colors[7];

};
}

#endif
3 changes: 3 additions & 0 deletions src/care/RAJAPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

#include <unordered_set>

using namespace std;
neelakausik marked this conversation as resolved.
Show resolved Hide resolved

namespace care {
bool RAJAPlugin::s_update_chai_execution_space = true;
bool RAJAPlugin::s_debug_chai_data = true;
Expand All @@ -43,6 +45,7 @@ namespace care {
std::vector<const chai::PointerRecord*> RAJAPlugin::s_active_pointers_in_loop = std::vector<const chai::PointerRecord*>{};
std::unordered_map<void *, std::function<void(chai::ExecutionSpace, const char *, int)>> RAJAPlugin::s_post_parallel_forall_actions = std::unordered_map<void *, std::function<void(chai::ExecutionSpace, const char *, int)>>{};
int RAJAPlugin::s_threadID = -1;

/////////////////////////////////////////////////////////////////////////////////
///
/// @brief Set up to be done before executing a RAJA loop.
Expand Down
Loading
Loading