SMAUG
Simulating Machine Learning Applications on gem5-Aladdin
Classes | Namespaces | Macros | Typedefs | Enumerations | Functions
common.h File Reference

Utilities for writing and invoking Aladdin kernels from Operators. More...

#include <stdint.h>
#include "gem5/sampling_interface.h"
#include <string>
#include <utility>
#include <memory>
#include "smaug/core/globals.h"
#include "tracer/trace_logger_aladdin.h"

Go to the source code of this file.

Classes

struct  _activation_param_t
 Parameters to the activation function hardware. More...
 
struct  ActivationInfo
 Specifies an activation function and relevant parameters. More...
 
struct  _SamplingInfo
 Simulation sampling information maintained by the Operator and passed to the accelerated kernel. More...
 

Namespaces

 smaug
 The smaug namespace is the parent namespace of all C++ code in SMAUG.
 

Macros

#define CACHELINE_SIZE   32
 
#define LOG_PAGE_SIZE   12
 
#define VECTOR_SIZE   8
 Vector size used in SMV backends.
 
#define VEC128_MASK(input, mask)   ((v4fp_t)((v4sfx_t)input & mask))
 Apply a elementwise mask to a 128-bit packed single precision FP vector. More...
 
#define VEC256_MASK(input, mask)   ((v8fp_t)((v8sfx_t)input & mask))
 Same as VEC128_MASK, but for 256-bit vectors. More...
 
#define ARRAY_1D(TYPE, output_array_name, input_array_name)   TYPE* output_array_name = (TYPE*)input_array_name
 
#define ARRAY_2D(TYPE, output_array_name, input_array_name, DIM_1)   TYPE(*output_array_name)[DIM_1] = (TYPE(*)[DIM_1])input_array_name
 
#define ARRAY_3D(TYPE, output_array_name, input_array_name, DIM_1, DIM_2)
 
#define ARRAY_4D( TYPE, output_array_name, input_array_name, DIM_1, DIM_2, DIM_3)
 
#define ARRAY_5D( TYPE, output_array_name, input_array_name, DIM_1, DIM_2, DIM_3, DIM_4)
 
#define VEC_ARRAY_1D(TYPE, output_array_name, input_array_name)   TYPE* output_array_name = (TYPE*)(input_array_name)
 
#define VEC_ARRAY_2D(TYPE, output_array_name, input_array_name, cols)
 
#define VEC_ARRAY_3D(TYPE, output_array_name, input_array_name, rows, cols)
 
#define VEC_ARRAY_4D( TYPE, output_array_name, input_array_name, height, rows, cols)
 
#define max2(A, B)   (((A) > (B)) ? (A) : (B))
 
#define max3(e0, e1, e2)   max2(max2(e0, e1), e2)
 
#define max4(e0, e1, e2, e3)   max2(max2(e0, e1), max2(e2, e3))
 
#define max8(e0, e1, e2, e3, e4, e5, e6, e7)   max2(max4(e0, e1, e2, e3), max4(e4, e5, e6, e7))
 
#define max9(e0, e1, e2, e3, e4, e5, e6, e7, e8)   max2(max8(e0, e1, e2, e3, e4, e5, e6, e7), e8)
 
#define min2(A, B)   (((A) < (B)) ? (A) : (B))
 
#define FRAC_CEIL(A, B)   ((A) / (B) + ((A) % (B) != 0))
 Implements the ceiling function of A/B.
 
#define ALWAYS_INLINE
 We have to disable all function inlining at the global level for Aladdin + LLVM-Tracer to work, but sometimes we do want to force inline functions (otherwise we run into all the issues of function call barriers in Aladdin). More...
 
#define ASSERT(x)   assert(x)
 An assertion macro which disables asserts in LLVM-Tracer instrumented code.
 
#define ASSUME_ALIGNED(ptr, args...)   __builtin_assume_aligned((ptr), args)
 Tell the compiler to assume a pointer is aligned on some byte boundary. More...
 
#define MAYBE_UNUSED   __attribute__((__unused__))
 

Typedefs

typedef enum _activation_type activation_type
 The activation function to apply to an operator's output in hardware. More...
 
typedef struct _activation_param_t activation_param_t
 Parameters to the activation function hardware. More...
 
typedef enum _SamplingLevel SamplingLevel
 Levels of simulation sampling to apply to certain accelerator kernels. More...
 
typedef struct _SamplingInfo SamplingInfo
 Simulation sampling information maintained by the Operator and passed to the accelerated kernel.
 
typedef float fp_t
 
typedef int sfx_t
 
typedef unsigned ufx_t
 
typedef uint16_t fp16_t
 
typedef uint16_t float16
 
typedef fp16_t v16fp_t
 16 packed 32-bit floating point values.
 
typedef fp_t v8fp_t
 8 packed 32-bit floating point values.
 
typedef fp_t v4fp_t
 4 packed 32-bit floating point values.
 
typedef fp16_t v16ph_t
 16 packed 16-bit floating point values.
 
typedef fp16_t v8ph_t
 8 packed 16-bit floating point values.
 
typedef fp16_t v4ph_t
 4 packed 16-bit floating point values.
 
typedef sfx_t v8sfx_t
 8 packed 32-bit integer values.
 
typedef sfx_t v4sfx_t
 4 packed 32-bit integer values.
 
typedef uint8_t v8bl_t
 8 packed 8-bit bool values.
 

Enumerations

enum  _activation_type {
  NO_ACTIVATION, RELU, RELU_THRESHOLD, LRELU,
  ELU, SELU, TANH, HARD_TANH,
  SIGMOID, SOFTMAX
}
 The activation function to apply to an operator's output in hardware. More...
 
enum  _SamplingLevel {
  NoSampling = 0, Low = 1, Medium = 2, High = 3,
  VeryHigh = 4
}
 Levels of simulation sampling to apply to certain accelerator kernels. More...
 

Functions

std::string smaug::getTraceName (int accelIdx)
 Return the name of the dynamic trace for this accelerator. More...
 
template<typename Kernel , typename... Args>
void smaug::invokeKernel (int accelIdx, unsigned reqCode, const Kernel &kernel, Args &&... args)
 The generic blocking interface for all accelerator kernel functions. More...
 
template<typename Kernel , typename... Args>
void smaug::invokeKernel (unsigned reqCode, const Kernel &kernel, Args &&... args)
 A generic interface for all accelerator kernel functions. More...
 
template<typename Kernel , typename... Args>
std::unique_ptr< volatile int > smaug::invokeKernelNoBlock (int accelIdx, unsigned reqCode, const Kernel &kernel, Args &&... args)
 A generic non-blocking interface to accelerated kernel functions. More...
 
void smaug::mapArrayToAccel (unsigned reqCode, const char *arrayName, void *baseAddr, size_t size)
 Maps an array of data to the accelerator. More...
 
void smaug::setArrayMemTypeIfSimulating (unsigned reqCode, const char *arrayName, MemoryType memType)
 Sets what memory access mechanism the accelerator will use when accessing this array. More...
 
size_t next_multiple (size_t request, size_t align)
 Returns the smallest multiple of align that is >= request.
 

Detailed Description

Utilities for writing and invoking Aladdin kernels from Operators.

Definition in file common.h.

Typedef Documentation

◆ activation_param_t

Parameters to the activation function hardware.

This is a struct that bridges the C++ class ActivationInfo with the C kernel.

◆ activation_type

The activation function to apply to an operator's output in hardware.

This is a struct that bridges the C++ class ActivationInfo with the C kernel.

◆ SamplingLevel

Levels of simulation sampling to apply to certain accelerator kernels.

It is the responsibility of the kernel writer to translate this qualitative description into a kernel-appropriate modification of the code behavior. For example, Low could mean "only sample the innermost loop", while VeryHigh could be translated to "sample all loop levels". Kernels do not need to support every single sampling level.

Enumeration Type Documentation

◆ _activation_type

The activation function to apply to an operator's output in hardware.

This is a struct that bridges the C++ class ActivationInfo with the C kernel.

Definition at line 175 of file common.h.

◆ _SamplingLevel

Levels of simulation sampling to apply to certain accelerator kernels.

It is the responsibility of the kernel writer to translate this qualitative description into a kernel-appropriate modification of the code behavior. For example, Low could mean "only sample the innermost loop", while VeryHigh could be translated to "sample all loop levels". Kernels do not need to support every single sampling level.

Definition at line 250 of file common.h.