-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #224 from LLNL/feature/kausik1/plugins
Use RAJA plugin capability
- Loading branch information
Showing
14 changed files
with
433 additions
and
406 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
#include "care/DebugPlugin.h" | ||
#include "chai/ExecutionSpaces.hpp" | ||
#include "care/CHAICallback.h" | ||
#include "care/PluginData.h" | ||
|
||
// Std library headers | ||
#if defined(CARE_DEBUG) && !defined(_WIN32) | ||
#include <execinfo.h> | ||
#endif // defined(CARE_DEBUG) && !defined(_WIN32) | ||
|
||
#include <unordered_set> | ||
|
||
namespace care{ | ||
void DebugPlugin::registerPlugin() { | ||
static RAJA::util::PluginRegistry::add<care::DebugPlugin> L ("Debug plugin", "CARE plugin for debugging"); | ||
} | ||
|
||
void DebugPlugin::preLaunch(const RAJA::util::PluginContext& /* p */) { | ||
#if !defined(CHAI_DISABLE_RM) | ||
// Prepare to record CHAI data | ||
if (CHAICallback::isActive()) { | ||
PluginData::clearActivePointers(); | ||
|
||
#if defined(CARE_GPUCC) && defined(CARE_DEBUG) | ||
GPUWatchpoint::setOrCheckWatchpoint<int>(); | ||
#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; | ||
|
||
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, PluginData::getFileName(), PluginData::getLineNumber()); | ||
|
||
#if defined(CARE_GPUCC) && defined(CARE_DEBUG) | ||
GPUWatchpoint::setOrCheckWatchpoint<int>(); | ||
#endif // defined(CARE_GPUCC) && defined(CARE_DEBUG) | ||
} | ||
|
||
if (PluginData::isParallelContext()) { | ||
for (auto const & it : PluginData::get_post_parallel_forall_actions()) { | ||
it.second(space, PluginData::getFileName(), PluginData::getLineNumber()); | ||
} | ||
PluginData::clear_post_parallel_forall_actions(); | ||
PluginData::s_threadID = -1; | ||
} | ||
#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 : PluginData::getActivePointers()) { | ||
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 : PluginData::getActivePointers()) { | ||
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 | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#ifndef _CARE_DebugPlugin_H_ | ||
#define _CARE_DebugPlugin_H_ | ||
|
||
#include "RAJA/util/PluginStrategy.hpp" | ||
#include "chai/ExecutionSpaces.hpp" | ||
|
||
namespace care{ | ||
|
||
class DebugPlugin : public RAJA::util::PluginStrategy | ||
{ | ||
public: | ||
DebugPlugin() = default; | ||
|
||
static void registerPlugin(); | ||
|
||
void preLaunch(const RAJA::util::PluginContext& p) override; | ||
|
||
void postLaunch(const RAJA::util::PluginContext& p) override; | ||
|
||
///////////////////////////////////////////////////////////////////////////////// | ||
/// | ||
/// @brief Writes out debugging information after a loop is executed. | ||
/// | ||
/// @arg[in] space The execution space | ||
/// @arg[in] fileName The file where the loop macro was called | ||
/// @arg[in] lineNumber The line number where the loop macro was called | ||
/// | ||
///////////////////////////////////////////////////////////////////////////////// | ||
static void writeLoopData(chai::ExecutionSpace space, const char * fileName, int lineNumber); | ||
}; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#include "PluginData.h" | ||
|
||
namespace care{ | ||
const char * PluginData::s_file_name = "N/A"; | ||
int PluginData::s_line_number = -1; | ||
bool PluginData::s_parallel_context = false; | ||
ActionMap PluginData::s_post_parallel_forall_actions = ActionMap{}; | ||
std::vector<const chai::PointerRecord*> PluginData::s_active_pointers_in_loop = std::vector<const chai::PointerRecord*>{}; | ||
int PluginData::s_threadID = -1; | ||
|
||
void PluginData::setFileName(const char * name) {PluginData::s_file_name = name;} | ||
|
||
void PluginData::setLineNumber(int num) {PluginData::s_line_number = num;} | ||
|
||
const char * PluginData::getFileName() {return s_file_name;} | ||
|
||
int PluginData::getLineNumber() {return s_line_number;} | ||
|
||
void PluginData::setParallelContext(bool isParallel) { | ||
s_parallel_context = isParallel; | ||
} | ||
|
||
bool PluginData::isParallelContext(){ | ||
return s_parallel_context; | ||
} | ||
|
||
ActionMap PluginData::get_post_parallel_forall_actions() { | ||
return s_post_parallel_forall_actions; | ||
} | ||
|
||
void PluginData::register_post_parallel_forall_action(void * key, std::function<void(chai::ExecutionSpace, const char *, int)> action) { | ||
s_post_parallel_forall_actions[key] = action; | ||
} | ||
|
||
bool PluginData::post_parallel_forall_action_registered(void * key) { | ||
bool registered = s_post_parallel_forall_actions.count(key) > 0; | ||
return registered; | ||
} | ||
|
||
void PluginData::clear_post_parallel_forall_actions(){s_post_parallel_forall_actions.clear();} | ||
|
||
std::vector<const chai::PointerRecord*> PluginData::getActivePointers() {return s_active_pointers_in_loop;} | ||
|
||
void PluginData::addActivePointer(const chai::PointerRecord* record) { | ||
s_active_pointers_in_loop.emplace_back(record); | ||
} | ||
|
||
void PluginData::removeActivePointer(const chai::PointerRecord* record) { | ||
for (size_t i = 0; i < s_active_pointers_in_loop.size(); ++i) { | ||
if (s_active_pointers_in_loop[i] == record) { | ||
s_active_pointers_in_loop[i] = nullptr; | ||
} | ||
} | ||
} | ||
|
||
void PluginData::clearActivePointers() {s_active_pointers_in_loop.clear();} | ||
|
||
} |
Oops, something went wrong.