CIRCT 23.0.0git
Loading...
Searching...
No Matches
Macros | Functions
ArcRuntime.cpp File Reference
#include "circt/Dialect/Arc/Runtime/ArcRuntime.h"
#include "circt/Dialect/Arc/Runtime/Common.h"
#include "circt/Dialect/Arc/Runtime/FmtDescriptor.h"
#include "circt/Dialect/Arc/Runtime/IRInterface.h"
#include "circt/Dialect/Arc/Runtime/Internal.h"
#include "circt/Dialect/Arc/Runtime/ModelInstance.h"
#include "circt/Support/FormatInteger.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/raw_ostream.h"
#include <cassert>
#include <cstdarg>
#include <cstdint>
#include <cstdlib>
#include <iostream>
Include dependency graph for ArcRuntime.cpp:

Go to the source code of this file.

Macros

#define ARC_RUNTIME_ENABLE_EXPORT
 

Functions

static impl::ModelInstance * getModelInstance (const ArcState *instance)
 
ArcStatearcRuntimeAllocateInstance (const ArcRuntimeModelInfo *model, const char *args)
 
void arcRuntimeDeleteInstance (ArcState *instance)
 Destroy and deallocate the state of a model instance.
 
uint64_t arcRuntimeGetAPIVersion ()
 Return the API version of the runtime library.
 
void arcRuntimeOnEval (ArcState *instance)
 Pre-Eval hook. Must be called by the driver once before every eval step.
 
void arcRuntimeOnInitialized (ArcState *instance)
 Must be called by the driver after the model's initial function and before the first onEval call.
 
ArcStatearcRuntimeGetStateFromModelState (uint8_t *modelState, uint64_t offset)
 Project a pointer to the model state to its ArcState container.
 
uint8_t * arcRuntimeIR_allocInstance (const ArcRuntimeModelInfo *model, const char *args)
 Allocate and initialize the state for a new instance of the given hardware model.
 
void arcRuntimeIR_onEval (uint8_t *modelState)
 Pre-Eval hook of the runtime library.
 
void arcRuntimeIR_onInitialized (uint8_t *modelState)
 Post-initialization hook of the runtime library.
 
void arcRuntimeIR_deleteInstance (uint8_t *modelState)
 Destroy and deallocate the state of a model instance.
 
static void formatToStream (llvm::raw_ostream &os, const FmtDescriptor *fmt, va_list args)
 
void arcRuntimeIR_format (const FmtDescriptor *fmt,...)
 Prints a formatted string to stdout.
 
void arcRuntimeIR_formatToStream (uint8_t *stream, const FmtDescriptor *fmt,...)
 Prints a formatted string to the given stream.
 
uint8_t * arcRuntimeIR_getStdoutStream ()
 Return the standard output stream.
 
uint8_t * arcRuntimeIR_getStderrStream ()
 Return the standard error stream.
 
uint64_t * arcRuntimeIR_swapTraceBuffer (const uint8_t *modelState)
 Release the active trace buffer and request an empty new buffer.
 

Macro Definition Documentation

◆ ARC_RUNTIME_ENABLE_EXPORT

#define ARC_RUNTIME_ENABLE_EXPORT

Definition at line 14 of file ArcRuntime.cpp.

Function Documentation

◆ arcRuntimeAllocateInstance()

ArcState * arcRuntimeAllocateInstance ( const ArcRuntimeModelInfo model,
const char *  args 
)

◆ arcRuntimeDeleteInstance()

void arcRuntimeDeleteInstance ( ArcState instance)

Destroy and deallocate the state of a model instance.

Definition at line 64 of file ArcRuntime.cpp.

References ArcState::impl.

Referenced by arcRuntimeIR_deleteInstance().

◆ arcRuntimeGetAPIVersion()

uint64_t arcRuntimeGetAPIVersion ( )

Return the API version of the runtime library.

Definition at line 70 of file ArcRuntime.cpp.

References ARC_RUNTIME_API_VERSION.

◆ arcRuntimeGetStateFromModelState()

ArcState * arcRuntimeGetStateFromModelState ( uint8_t *  modelState,
uint64_t  offset 
)

Project a pointer to the model state to its ArcState container.

offset is the byte offset of the given pointer within the model state.

Definition at line 80 of file ArcRuntime.cpp.

References ARC_RUNTIME_MAGIC, and ArcState::magic.

Referenced by arcRuntimeIR_deleteInstance(), arcRuntimeIR_onEval(), and arcRuntimeIR_onInitialized().

◆ arcRuntimeIR_allocInstance()

uint8_t * arcRuntimeIR_allocInstance ( const ArcRuntimeModelInfo model,
const char *  args 
)

Allocate and initialize the state for a new instance of the given hardware model.

This function must allocate an ArcState struct with at least model->numStateBytes bytes provided for the modelState array. It must return the pointer to the zero initialized model state which is required to be 16-byte-aligned.

args is a zero terminated string containing implementation specific options for the new instance or null.

Definition at line 93 of file ArcRuntime.cpp.

References arcRuntimeAllocateInstance(), and ArcState::modelState.

◆ arcRuntimeIR_deleteInstance()

void arcRuntimeIR_deleteInstance ( uint8_t *  modelState)

Destroy and deallocate the state of a model instance.

This function is responsible for releasing all resources that previously have been allocated by arcRuntimeIR_allocInstance.

Definition at line 107 of file ArcRuntime.cpp.

References arcRuntimeDeleteInstance(), and arcRuntimeGetStateFromModelState().

◆ arcRuntimeIR_format()

void arcRuntimeIR_format ( const circt::arc::runtime::FmtDescriptor fmt,
  ... 
)

Prints a formatted string to stdout.

fmt is an array of FmtDescriptor objects, ending in a descriptor with action Action_End.

The values to format are passed as variadic arguments.

Definition at line 148 of file ArcRuntime.cpp.

References formatToStream().

◆ arcRuntimeIR_formatToStream()

void arcRuntimeIR_formatToStream ( uint8_t *  stream,
const circt::arc::runtime::FmtDescriptor fmt,
  ... 
)

Prints a formatted string to the given stream.

fmt is an array of FmtDescriptor objects, ending in a descriptor with action Action_End.

The values to format are passed as variadic arguments.

Definition at line 157 of file ArcRuntime.cpp.

References formatToStream().

◆ arcRuntimeIR_getStderrStream()

uint8_t * arcRuntimeIR_getStderrStream ( )

Return the standard error stream.

Definition at line 174 of file ArcRuntime.cpp.

◆ arcRuntimeIR_getStdoutStream()

uint8_t * arcRuntimeIR_getStdoutStream ( )

Return the standard output stream.

Definition at line 170 of file ArcRuntime.cpp.

◆ arcRuntimeIR_onEval()

void arcRuntimeIR_onEval ( uint8_t *  modelState)

Pre-Eval hook of the runtime library.

Simulation drivers must call this once before every invocation of the model's eval function.

Definition at line 99 of file ArcRuntime.cpp.

References arcRuntimeGetStateFromModelState(), and arcRuntimeOnEval().

◆ arcRuntimeIR_onInitialized()

void arcRuntimeIR_onInitialized ( uint8_t *  modelState)

Post-initialization hook of the runtime library.

Simulation drivers must call this once after the invocation of the model's initial function.

Definition at line 103 of file ArcRuntime.cpp.

References arcRuntimeGetStateFromModelState(), and arcRuntimeOnInitialized().

◆ arcRuntimeIR_swapTraceBuffer()

uint64_t * arcRuntimeIR_swapTraceBuffer ( const uint8_t *  modelState)

Release the active trace buffer and request an empty new buffer.

Invoked by the model to signal that the currently active trace buffer, referenced by modelState->traceBuffer is ready for processing and contains modelState->traceBufferSize valid uint64_t words.

The runtime must return a pointer to a valid storage of at least traceBufferCapacity x uint64_t size, which will become the new active trace buffer.

Definition at line 178 of file ArcRuntime.cpp.

References ARC_RUNTIME_MAGIC, and getModelInstance().

◆ arcRuntimeOnEval()

void arcRuntimeOnEval ( ArcState instance)

Pre-Eval hook. Must be called by the driver once before every eval step.

Definition at line 72 of file ArcRuntime.cpp.

References getModelInstance().

Referenced by arcRuntimeIR_onEval().

◆ arcRuntimeOnInitialized()

void arcRuntimeOnInitialized ( ArcState instance)

Must be called by the driver after the model's initial function and before the first onEval call.

Definition at line 76 of file ArcRuntime.cpp.

References getModelInstance().

Referenced by arcRuntimeIR_onInitialized().

◆ formatToStream()

static void formatToStream ( llvm::raw_ostream &  os,
const FmtDescriptor fmt,
va_list  args 
)
static

◆ getModelInstance()

static impl::ModelInstance * getModelInstance ( const ArcState instance)
inlinestatic

Definition at line 41 of file ArcRuntime.cpp.

References assert(), and ArcState::impl.

Referenced by arcRuntimeIR_swapTraceBuffer(), arcRuntimeOnEval(), and arcRuntimeOnInitialized().