-
Notifications
You must be signed in to change notification settings - Fork 21
Simplify rev opts #352
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
Simplify rev opts #352
Changes from all commits
7d15916
6b7a3af
3a7f890
4eb3057
d208318
278c9c9
7312fae
a89f14d
884fdd4
ceacdb2
04f4db7
cb7cacc
e2e3116
df1584f
b6f1a9c
fddeb8a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,30 +15,69 @@ | |
#include "SST.h" | ||
|
||
// -- Standard Headers | ||
#include "RevCommon.h" | ||
#include <cinttypes> | ||
#include <map> | ||
#include <string> | ||
#include <tuple> | ||
#include <type_traits> | ||
#include <unordered_map> | ||
#include <utility> | ||
#include <vector> | ||
|
||
namespace SST::RevCPU { | ||
|
||
class RevOpts { | ||
|
||
// Queries whether type is a std::vector type | ||
template<typename T> | ||
struct is_vector : std::false_type {}; | ||
|
||
template<typename T> | ||
struct is_vector<std::vector<T>> : std::true_type {}; | ||
|
||
// Return a property by looking up its table | ||
// VAL is a universal reference so that either an lvalue reference or an assignable rvalue reference such as std::tie can be used | ||
template<typename MAP, typename VAL> | ||
bool GetProperty( uint32_t Core, const MAP& Map, VAL&& Val ) const { | ||
if constexpr( is_vector<MAP>::value ) { | ||
// If MAP is a vector | ||
return Core < numCores ? Val = Map[Core], true : false; | ||
} else { | ||
// If MAP is a map/unordered_map | ||
auto it = Map.find( Core ); | ||
return it != Map.end() ? Val = it->second, true : false; | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only one of the So we can write one function which operates differently depending on whether
|
||
|
||
template<typename VEC> | ||
bool InitPropertyMap( const std::vector<std::string>& Opts, VEC& map ); | ||
|
||
template<typename VEC> | ||
bool InitPropertyMapCores( const std::vector<std::string>& Opts, VEC& map ); | ||
|
||
public: | ||
/// RevOpts: options constructor | ||
RevOpts( uint32_t NumCores, uint32_t NumHarts, const int Verbosity ); | ||
RevOpts( uint32_t NumCores, uint32_t NumHarts, int Verbosity ) | ||
: numCores( NumCores ), numHarts( NumHarts ), verbosity( Verbosity ) {} | ||
|
||
/// RevOpts: Disallow copying and assignment | ||
RevOpts( const RevOpts& ) = delete; | ||
RevOpts( RevOpts&& ) = delete; | ||
RevOpts& operator=( const RevOpts& ) = delete; | ||
RevOpts& operator=( RevOpts&& ) = delete; | ||
|
||
/// RevOpts: options destructor | ||
~RevOpts() = default; | ||
~RevOpts() = default; | ||
|
||
/// RevOpts: retrieve the number of configured cores | ||
uint32_t GetNumCores() { return numCores; } | ||
uint32_t GetNumCores() const { return numCores; } | ||
|
||
/// RevOpts: retrieve the number of configured harts per core | ||
uint32_t GetNumHarts() { return numHarts; } | ||
uint32_t GetNumHarts() const { return numHarts; } | ||
|
||
/// RevOpts: retrieve the verbosity level | ||
int GetVerbosity() { return verbosity; } | ||
int GetVerbosity() const { return verbosity; } | ||
|
||
/// RevOpts: initialize the set of starting addresses | ||
bool InitStartAddrs( const std::vector<std::string>& StartAddrs ); | ||
|
@@ -59,22 +98,24 @@ class RevOpts { | |
bool InitPrefetchDepth( const std::vector<std::string>& Depths ); | ||
|
||
/// RevOpts: retrieve the start address for the target core | ||
bool GetStartAddr( uint32_t Core, uint64_t& StartAddr ); | ||
bool GetStartAddr( uint32_t Core, uint64_t& StartAddr ) const { return GetProperty( Core, startAddr, StartAddr ); } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All of the |
||
|
||
/// RevOpts: retrieve the start symbol for the target core | ||
bool GetStartSymbol( uint32_t Core, std::string& Symbol ); | ||
bool GetStartSymbol( uint32_t Core, std::string& Symbol ) const { return GetProperty( Core, startSym, Symbol ); } | ||
|
||
/// RevOpts: retrieve the machine model string for the target core | ||
bool GetMachineModel( uint32_t Core, std::string& MachModel ); | ||
bool GetMachineModel( uint32_t Core, std::string& MachModel ) const { return GetProperty( Core, machine, MachModel ); } | ||
|
||
/// RevOpts: retrieve instruction table for the target core | ||
bool GetInstTable( uint32_t Core, std::string& Table ); | ||
bool GetInstTable( uint32_t Core, std::string& Table ) const { return GetProperty( Core, table, Table ); } | ||
|
||
/// RevOpts: retrieve the memory cost range for the target core | ||
bool GetMemCost( uint32_t Core, uint32_t& Min, uint32_t& Max ); | ||
bool GetMemCost( uint32_t Core, uint32_t& Min, uint32_t& Max ) const { | ||
return GetProperty( Core, memCosts, std::tie( Min, Max ) ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
/// RevOpts: retrieve the prefetch depth for the target core | ||
bool GetPrefetchDepth( uint32_t Core, uint32_t& Depth ); | ||
bool GetPrefetchDepth( uint32_t Core, uint32_t& Depth ) const { return GetProperty( Core, prefetchDepth, Depth ); } | ||
|
||
/// RevOpts: set the argv array | ||
void SetArgs( const SST::Params& params ); | ||
|
@@ -86,23 +127,34 @@ class RevOpts { | |
static void splitStr( std::string s, const char* delim, std::vector<std::string>& v ) { | ||
char* ptr = s.data(); | ||
char* saveptr = nullptr; | ||
for( v.clear(); auto token = strtok_r( ptr, delim, &saveptr ); ptr = nullptr ) | ||
for( v.clear(); char* token = strtok_r( ptr, delim, &saveptr ); ptr = nullptr ) | ||
v.push_back( token ); | ||
} | ||
|
||
private: | ||
uint32_t numCores{}; ///< RevOpts: number of initialized cores | ||
uint32_t numHarts{}; ///< RevOpts: number of harts per core | ||
int verbosity{}; ///< RevOpts: verbosity level | ||
|
||
std::unordered_map<uint32_t, uint64_t> startAddr{}; ///< RevOpts: map of core id to starting address | ||
std::unordered_map<uint32_t, std::string> startSym{}; ///< RevOpts: map of core id to starting symbol | ||
std::unordered_map<uint32_t, std::string> machine{}; ///< RevOpts: map of core id to machine model | ||
std::unordered_map<uint32_t, std::string> table{}; ///< RevOpts: map of core id to inst table | ||
std::unordered_map<uint32_t, uint32_t> prefetchDepth{}; ///< RevOpts: map of core id to prefretch depth | ||
std::vector<std::pair<uint32_t, uint32_t>> memCosts{}; ///< RevOpts: vector of memory cost ranges | ||
std::vector<std::string> Argv{}; ///< RevOpts: vector of function arguments | ||
std::vector<std::string> MemDumpRanges{}; ///< RevOpts: vector of function arguments | ||
uint32_t const numCores; ///< RevOpts: number of initialized cores | ||
uint32_t const numHarts; ///< RevOpts: number of harts per core | ||
int const verbosity; ///< RevOpts: verbosity level | ||
|
||
// init all the standard options | ||
// -- startAddr = 0x00000000 | ||
// -- machine = "G" aka, "IMAFD" | ||
// -- table = internal | ||
// -- memCosts[core] = 0:10 | ||
// -- prefetch depth = 16 | ||
// -- pipeLine = 5 ??? | ||
|
||
// clang-format off | ||
std::vector<uint64_t> startAddr{decltype( startAddr )( numCores, 0 )}; ///< RevOpts: starting address | ||
std::vector<std::string> machine{decltype( machine )( numCores, "G" )}; ///< RevOpts: machine model | ||
std::vector<std::string> table{decltype( table )( numCores, "_REV_INTERNAL_" )}; ///< RevOpts: inst table | ||
std::vector<std::pair<uint32_t, uint32_t>> memCosts{decltype( memCosts )( numCores, {0, 10} )}; ///< RevOpts: memory cost range | ||
std::vector<uint32_t> prefetchDepth{decltype( prefetchDepth )( numCores, 16 )}; ///< RevOpts: prefretch depth | ||
// clang-format on | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All of the vectors which are initialized to default values are initialized at constructor time, after |
||
|
||
std::unordered_map<uint32_t, std::string> startSym; ///< RevOpts: starting symbol | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because of how |
||
std::vector<std::string> Argv; ///< RevOpts: vector of function arguments | ||
std::vector<std::string> MemDumpRanges; ///< RevOpts: vector of function arguments | ||
|
||
}; // class RevOpts | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is standard traits programming, where a trait query class is defined as false in general, but then a partial specialization is defined for which it's true for a proper subset of the original template.