gem5.components.processors.spatter_gen.spatter_kernel.html
gem5.components.processors.spatter_gen.spatter_kernel module¶
- class gem5.components.processors.spatter_gen.spatter_kernel.SpatterKernel(kernel_id: int, kernel_delta: int, kernel_count: int, kernel_type: SpatterKernelType, base_index: int, indices_per_stride: int, stride_size: int, index_size: int, base_index_addr: Addr, value_size: int, base_value_addr: Addr, kernel_trace: List[int])¶
Bases:
object
- This class encapsulates one kernel in a spatter trace.
A spatter trace is represented with a json file. An example of a spatter trace can be found here:
- https://github.com/hpcgarage/spatter/blob/main/standard-suite/app-traces/amg.json
Each trace may have multiple kernels. Each kernel represents a code execution like below
for (int iteration = 0; iteration < count; iteration++) {
- for (int i = 0; i < N; i++) {
value[index[i] + iteration * delta] = rand(); // kernel: scatter // OR sum += value[index[i] + iteration * delta]; // kernel: gather
}
}
Where delta and count are fields in each kernel. kernel is another field that determines whether the accesses to value are loads or stores. The field pattern stores the index array.
- This file provides four utility function to parse spatter traces:
parse_kernel: takes a dictionary and returns a tuple of delta, count, type, and trace. partition_trace: takes an original trace, number of partitions, and interleave_size. It returns a list of num_partitions partitions where each partition includes interleaved elements from original_trace. The elements in the original_trace are interleaved with a granularity of interleave_size. unroll_trace: takes an original trace, delta, count, and minimum number of elements. It will unroll original_trace by adding delta to the last og_len (len(original_trace)) elements of the trace in steps. In each step it will decrement count by 1. If the logical length of original_trace (og_len * count) is smaller than min_elements, it allows for filling the trace with zeros or elements from the pattern. By filling elements from the pattern, the unrolling process goes beyond the count limit. However, it will not decrements count. prepare_kernels: takes a trace_path, number of cores, interleave_size, base_index_addr, and base_value_addr. It will return a list of lists of kernels where each list of kernels represents a kernel with a length of num_cores.
- The code snippet below shows how to use these functions to create kernels.
generator = SpatterGenerator(num_cores)
- with open(trace_path, “r”) as trace_file:
kernels = json.load(trace_file)
- for i, kernel in enumerate(kernels):
delta, count, type, og_trace = parse_kernel(kernel) traces = partition_trace(og_trace, num_cores, 128) kernels = [SpatterKernel(
kernel_id=i, kernel_delta=delta, kernel_count=count, kernel_type=type, kernel_trace=trace, index_size=4, base_index_addr=0, value_size=8, base_value_addr=0x400000000 )
for trace in traces ]
generator.add_kernel(kernels)
- Args:
kernel_id (int): The ID of the kernel. User defined, i.e. spatter traces don’t have this field. It’s used to identify the kernel in the simulation. kernel_delta (int): The delta value of the kernel. delta from spatter trace. kernel_count (int): The count value of the kernel. count from spatter trace. kernel_type (SpatterKernelType): The type of the kernel. kernel from spatter trace. base_index (int): The index from the index array to start from. It’s most meaningful when used in multi-generator simulations. User defined, i.e. spatter traces don’t have this field. indices_per_stride (int): The number of indices from the index array to read from before making a jump of size stride_size. User defined, i.e. spatter traces don’t have this field. stride_size (int): The size of the jump to make after reading indices_per_stride indices from the index array. User defined, i.e. spatter traces don’t have this field. kernel_trace (List[int]): The elements of the index array. pattern from spatter trace. index_size (int): The size of elements in index. User defined, i.e. spatter traces don’t have this field. It represents the size of elements in the index array in code above. base_index_addr (Addr): The base address of the index. User defined, i.e. spatter traces don’t have this field. It represents the pointer to the index array in the code above. value_size (int): The size of elements in value. User defined, i.e. spatter traces don’t have this field. It represents the size of elements in the value array in code above. base_value_addr (Addr): The base address of the value. User defined, i.e. spatter traces don’t have this field. It represents the pointer to the value array in the code above.
- cxx_call_args()¶
- empty()¶
- gem5.components.processors.spatter_gen.spatter_kernel.parse_kernel(kernel: dict, default_delta=8) Tuple[int, int, str, List] ¶
Function to parse a kernel from a dictionary. Each Spatter trace is represented as a list of dictionaries in JSON. Each dictionary in the list represents a kernel. This function will one kernel and return a tuple of delta, count, type, and trace. Args:
kernel (dict): A dictionary representing a kernel. default_delta (int): The default delta value to use when the delta value is not found in the kernel dictionary. Returns:
Tuple[int, int, str, List]: A tuple of delta, count, type, and trace extracted from the kernel.
- gem5.components.processors.spatter_gen.spatter_kernel.partition_trace(original_trace, num_partitions, interleave_size)¶
- gem5.components.processors.spatter_gen.spatter_kernel.prepare_kernels(trace_path: Path, num_cores: int, interleave_size: int, base_index_addr: Addr, base_value_addr: Addr) List[List[SpatterKernel]] ¶
Function to prepare kernels from a spatter trace. It will read the trace from the given path and prepare kernels for the given number of cores and interleave size. It will partition the trace into num_cores partitions with interleave_size elements in each partition. It will also unroll the trace to have at least num_cores * interleave_size elements in the trace using the unroll_trace function. In case the trace is too small, it will ask unroll_trace to fill the trace with elements from the pattern. It will return a list of list of kernels where each list of kernels represents a kernel with a length of num_cores. Args:
trace_path (Path): Path to the spatter trace. num_cores (int): Number of cores to partition the trace. interleave_size (int): Number of elements to interleave the trace by. base_index_addr (Addr): The base address of the index array. base_value_addr (Addr): The base address of the value array.
- Returns:
List[List[SpatterKernel]]: A list of list of kernels where each list of kernels represents a kernel with a length of num_cores.
- gem5.components.processors.spatter_gen.spatter_kernel.unroll_trace(original_trace: List, delta: int, count: int, min_elements: int, fill_zero=False, fill_pattern=False)¶
Function to unroll a trace by creating replicated elements in the trace. This function will add delta to the last og_len (len(original_trace)) elements of the trace in steps. In each step it will decrement count. If the logical length of original_trace (og_len * count) is smaller than min_elements, it allows for filling the trace with zeros or elements from the pattern. By filling elements from the pattern, the unrolling process goes beyond the count limit. However, it will not decrement count.
- Args:
original_trace (List): The original trace to unroll. delta (int): The delta value as provided from the kernel in JSON. count (int): The count value as provided from the kernel in JSON. min_elements (int): The minimum number of elements the trace should have after unrolling. fill_zero (bool): If True, the trace will be filled with zeros when the unrolling process runs out of elements from the original trace. fill_pattern (bool): If True, the trace will be filled with the pattern allowing to go over the count limit (from the kernel in JSON) when unrolling.