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

fix cost > 1 #315

Draft
wants to merge 25 commits into
base: devel
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e098c1c
Fix Instruction cost > 1 (does not work for Instruction cost > 1 and …
leekillough Sep 5, 2024
dabb69a
make --enableMemH and --randomizeCosts options use smart syntax
leekillough Sep 6, 2024
813eeba
fix typo
leekillough Sep 6, 2024
11e096e
convert two more references
leekillough Sep 6, 2024
1cd0c49
add const
leekillough Sep 6, 2024
2049031
randomize costs in CI tests
leekillough Sep 6, 2024
a96420d
simplify scripts by using exec redirection of stderr to stdout
leekillough Sep 6, 2024
e686971
Cache floating-point extension status
leekillough Sep 6, 2024
89b668c
Merge remote-tracking branch 'tcl/devel' into InstCost
leekillough Sep 8, 2024
b4ec2c5
fix initialization order
leekillough Sep 9, 2024
25a33ab
Merge remote-tracking branch 'tcl/devel' into InstCost
leekillough Sep 9, 2024
1968fff
Merge remote-tracking branch 'tcl/devel' into InstCost
leekillough Sep 13, 2024
d4343d5
Merge remote-tracking branch 'tcl/devel' into InstCost
leekillough Sep 13, 2024
f8315eb
remove Feature and unused fields
leekillough Sep 16, 2024
042b1e3
update
leekillough Sep 16, 2024
2131add
Merge remote-tracking branch 'tcl/devel' into InstCost
leekillough Sep 17, 2024
1312e14
update
leekillough Sep 18, 2024
daa2c47
Merge remote-tracking branch 'tcl/devel' into InstCost
leekillough Sep 18, 2024
91313c3
Merge remote-tracking branch 'tcl/devel' into InstCost
leekillough Sep 23, 2024
a43f105
Merge remote-tracking branch 'tcl/devel' into InstCost
leekillough Sep 23, 2024
47566f5
Merge remote-tracking branch 'tcl/devel' into InstCost
leekillough Sep 23, 2024
25b3236
Don't store RevRegFile in RevHart
leekillough Sep 25, 2024
95f1ab9
Merge remote-tracking branch 'tcl/devel' into InstCost
leekillough Sep 25, 2024
51862b4
fix memory corruption
leekillough Oct 2, 2024
ddb0d06
partial refactoring of pipeline code
leekillough Oct 4, 2024
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
3 changes: 2 additions & 1 deletion include/RevCPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class RevCPU : public SST::Component {
{ "trcStartCycle", "Starting tracer cycle (disables trcOp)", "0" },
{ "splash", "Display the splash logo", "0" },
{ "independentCoprocClock", "Enables each coprocessor to register its own clock handler", "0" },
{ "randomizeCosts", "Randomizes the cost of each instruction", "0" },
)

// -------------------------------------------------------
Expand Down Expand Up @@ -233,7 +234,7 @@ class RevCPU : public SST::Component {

// Adds Thread with ThreadID to AssignedThreads vector for ProcID
// - Handles updating LSQueue & MarkLoadComplete function pointers
void AssignThread( std::unique_ptr<RevThread>&& ThreadToAssign, unsigned ProcID );
void SetThread( std::unique_ptr<RevThread>&& ThreadToAssign, unsigned ProcID );

// Checks the status of ALL threads that are currently blocked.
void CheckBlockedThreads();
Expand Down
188 changes: 105 additions & 83 deletions include/RevCore.h

Large diffs are not rendered by default.

22 changes: 19 additions & 3 deletions include/RevExt.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
#include "RevInstTable.h"
#include "RevMem.h"

// Maximum cost when randomizing costs of instructions
#define MAX_COST 2

namespace SST::RevCPU {

struct RevExt {
Expand All @@ -46,16 +49,16 @@ struct RevExt {
/// RevExt: sets the internal instruction table
// Note: && means the argument should be an rvalue or std::move(lvalue)
// This avoids deep std::vector copies and uses only one std::vector move.
void SetTable( std::vector<RevInstEntry>&& InstVect ) { table = std::move( InstVect ); }
void SetTable( std::vector<RevInstEntry>&& InstVect ) { RandomizeCosts( table = std::move( InstVect ) ); }

/// RevExt: sets the internal compressed instruction table
void SetCTable( std::vector<RevInstEntry>&& InstVect ) { ctable = std::move( InstVect ); }
void SetCTable( std::vector<RevInstEntry>&& InstVect ) { RandomizeCosts( ctable = std::move( InstVect ) ); }

/// RevExt: retrieve the extension name
std::string_view GetName() const { return name; }

/// RevExt: baseline execution function
bool Execute( unsigned Inst, const RevInst& Payload, uint16_t HartID, RevRegFile* regFile ) const;
bool Execute( unsigned Inst, RevInst& Payload, uint16_t HartID, RevRegFile* regFile ) const;

/// RevExt: retrieves the extension's instruction table
const std::vector<RevInstEntry>& GetTable() const { return table; }
Expand All @@ -64,13 +67,26 @@ struct RevExt {
const std::vector<RevInstEntry>& GetCTable() const { return ctable; }

private:
// RevExt: Randomize instruction costs if randomizeCosts == true
void RandomizeCosts( std::vector<RevInstEntry>& table ) const {
if( feature->GetRandomizeCosts() ) {
for( auto& entry : table ) {
if( entry.cost == 1 ) {
entry.cost = RevRand( 1, MAX_COST );
}
}
}
}

std::string_view const name; ///< RevExt: extension name
const RevFeature* const feature; ///< RevExt: feature object
RevMem* const mem; ///< RevExt: memory object
SST::Output* const output; ///< RevExt: output handler
std::vector<RevInstEntry> table{}; ///< RevExt: instruction table
std::vector<RevInstEntry> ctable{}; ///< RevExt: compressed instruction table

public:
const bool isFloat = name == "RV32F" || name == "RV32D" || name == "RV64F" || name == "RV64D";
}; // class RevExt

} // namespace SST::RevCPU
Expand Down
9 changes: 6 additions & 3 deletions include/RevFeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ enum RevFeatureType : uint32_t {

struct RevFeature {
/// RevFeature: standard constructor
RevFeature( std::string Machine, SST::Output* Output, unsigned Min, unsigned Max, unsigned Id );
RevFeature( std::string Machine, SST::Output* Output, unsigned Min, unsigned Max, unsigned Id, bool randomizeCosts );

/// RevFeature: standard destructor
~RevFeature() = default;
Expand Down Expand Up @@ -99,6 +99,9 @@ struct RevFeature {
/// SetHartToExecID: Set the current executing Hart
void SetHartToExecID( unsigned hart ) { HartToExecID = hart; }

/// GetRandomizeCosts: Return whether to randomize costs
bool GetRandomizeCosts() const { return randomizeCosts; }

private:
const std::string machine; ///< RevFeature: feature string
SST::Output* const output; ///< RevFeature: output handler
Expand All @@ -108,9 +111,9 @@ struct RevFeature {
unsigned HartToExecID{}; ///< RevFeature: The current executing Hart on RevCore
RevFeatureType features{ RV_UNKNOWN }; ///< RevFeature: feature elements
unsigned xlen{}; ///< RevFeature: RISC-V Xlen
const bool randomizeCosts; ///< RevFeature: Whether to randomize costs
bool ParseMachineModel(); ///< RevFeature: Parse the machine model string

/// ParseMachineModel: parse the machine model string
bool ParseMachineModel();
}; // class RevFeature

} // namespace SST::RevCPU
Expand Down
77 changes: 52 additions & 25 deletions include/RevHart.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,18 @@

namespace SST::RevCPU {

enum class RevHartState {
Idle,
Fetching,
Decoding,
Halted,
Executing,
Retired,
};

class RevHart {
///< RevHart: Id for the Hart (0,1,2,3,etc)
unsigned ID{};
unsigned const ID;

///< RevHart: State management object when a Hart is executing a system call
EcallState Ecall{};
Expand All @@ -29,14 +38,16 @@ class RevHart {
const std::shared_ptr<std::unordered_multimap<uint64_t, MemReq>>& LSQueue;

///< RevHart: Pointer to the Proc's MarkLoadCompleteFunc
std::function<void( const MemReq& )> MarkLoadCompleteFunc{};
std::function<void( const MemReq& )> const MarkLoadCompleteFunc;

///< RevHart: Thread currently executing on this Hart
std::unique_ptr<RevThread> Thread = nullptr;
std::unique_ptr<RevRegFile> RegFile = nullptr;
std::unique_ptr<RevThread> Thread = nullptr;

///< RevHart: State of hart
RevHartState State = RevHartState::Idle;

///< RevHart: Make RevCore a friend of this
friend class RevCore;
///<RevHart: Cost of executing instruction
unsigned Cost = 0;

public:
///< RevHart: Constructor
Expand All @@ -47,41 +58,57 @@ class RevHart {
)
: ID( ID ), LSQueue( LSQueue ), MarkLoadCompleteFunc( std::move( MarkLoadCompleteFunc ) ) {}

///< RevHart: disallow copying and assignment
RevHart( const RevHart& ) = delete;
RevHart& operator=( const RevHart& ) = delete;

///< RevHart: Destructor
~RevHart() = default;
~RevHart() = default;

///< RevHart: Get the State
RevHartState GetState() const { return State; }

///< RevHart: Set the State
void SetState( RevHartState state ) { State = state; }

///< RevHart: Get the Cost
unsigned GetCost() const { return Cost; }

///< RevHart: Set the Cost
void SetCost( unsigned cost ) { Cost = cost; }

///< RevHart: Get the EcallState
EcallState& GetEcallState() { return Ecall; }

const EcallState& GetEcallState() const { return Ecall; }
///< RevHart: Get the RegFile
RevRegFile* GetRegFile() const { return Thread->GetRegFile(); }

///< RevHart: Add new file descriptor to this hart's thread (ie. rev_open)
void AddFD( int fd ) { Thread->AddFD( fd ); }

///< RevHart: Remove file descriptor from this hart's thread (ie. rev_close)
void RemoveFD( int fd ) { Thread->RemoveFD( fd ); }

///< See if file descriptor exists/is owned by this hart's thread
bool FindFD( int fd ) const { return Thread->FindFD( fd ); }

///< RevHart: Get Hart's ID
uint16_t GetID() const { return ID; }

///< RevHart: Returns the ID of the assigned thread
uint32_t GetAssignedThreadID() const { return Thread ? Thread->GetID() : _INVALID_TID_; }
uint32_t GetThreadID() const { return Thread ? Thread->GetID() : _INVALID_TID_; }

///< RevHart: Load the register file from the RevThread
void LoadRegFile( std::unique_ptr<RevRegFile> regFile ) {
RegFile = std::move( regFile );
///< RevHart: Assigns a RevThread to this Hart
void SetThread( std::unique_ptr<RevThread> ThreadToAssign ) {
Thread = std::move( ThreadToAssign );
auto RegFile = Thread->GetRegFile();
RegFile->SetMarkLoadComplete( MarkLoadCompleteFunc );
RegFile->SetLSQueue( LSQueue );
}

///< RevHart: Assigns a RevThread to this Hart
void AssignThread( std::unique_ptr<RevThread> ThreadToAssign ) {
Thread = std::move( ThreadToAssign );
Thread->SetState( ThreadState::RUNNING );
LoadRegFile( Thread->TransferVirtRegState() );
}

///< RevHart: Removed a RevThread from this Hart
std::unique_ptr<RevThread> PopThread() {
// return the register file to the thread
Thread->UpdateVirtRegState( std::move( RegFile ) );
// return the thread
return std::move( Thread );
}
///< RevHart: Remove a RevThread from this Hart
std::unique_ptr<RevThread> PopThread() { return std::move( Thread ); }
}; // class RevHart

} // namespace SST::RevCPU
Expand Down
Loading