Peano
Loading...
Searching...
No Matches
OMPTargetPrinter.py
Go to the documentation of this file.
1from ..AbstractSyntaxTree import *
2from .CPPPrinter import CPPPrinter
3import os
4
6 def __init__(self, spaces_per_tab: int):
7 CPPPrinter.__init__(self, spaces_per_tab)
8 self.nested_level = 0
9
10 def print_data_block_assignment(self, data_block_assignment: DataBlockAssignment, indent_level: int = 0) -> str:
11 return f"""{self.get_indent(indent_level)}#pragma omp target teams loop collapse(Dimensions + 1) device(deviceNumber)
12{data_block_assignment.assignment.print(self, indent_level)}"""
13
14 def print_data_block_construction_from_function_call(self, data_block_construction_from_function_call: DataBlockConstructionFromFunctionCall, indent_level: int = 0):
15 return f"""{data_block_construction_from_function_call.allocation.print(self, indent_level)}
16{self.get_indent(indent_level)}#pragma omp target teams loop collapse(Dimensions) device(deviceNumber)
17{data_block_construction_from_function_call.initialisation.print(self, indent_level)}"""
18
19 # A unary max evaluation is a reduction, so it requires a little more care in parallelising it
20 def print_data_block_unary_max(self, data_block_unary_max: DataBlockUnaryMax, indent_level: int = 0) -> str:
21 outer_loop_index_print = data_block_unary_max.loops[0].iteration_variable.print(self)
22 outer_loop_start_print = data_block_unary_max.loops[0].iteration_start.print(self)
23 outer_loop_end_print = data_block_unary_max.loops[0].iteration_end.print(self)
24
25 return f"""{self.get_indent(indent_level)}for (int {outer_loop_index_print} = {outer_loop_start_print}; {outer_loop_index_print} < {outer_loop_end_print}; {outer_loop_index_print}++) {{
26#pragma omp target teams loop collapse(Dimensions + 1) reduction(max:{data_block_unary_max.lhs.index_at([data_block_unary_max.loops[0].get_iteration_variable()]).print(self)})
27{data_block_unary_max.loops[1].print(self, indent_level + 1)}
28{self.get_indent(indent_level)}}}"""
29
30 def print_memory_allocation(self, memory_allocation: MemoryAllocation, indent_level: int = 0) -> str:
31 type_print = memory_allocation.type.print(self)
32 lhs_print = memory_allocation.lhs.print(self)
33 size_print = memory_allocation.allocation_size.print(self)
34
35 if isinstance(memory_allocation.lhs, Variable):
36 return f"""{type_print}* {lhs_print} = tarch::accelerator::GPUMemoryManager::getInstance().allocate<{type_print}>({size_print}, deviceNumber);"""
37 else:
38 # lhs is either a variable or a subscript, only variables require a type specifier
39 # In general a GPU code will always flatten the arrays, so this branch will not be reached
40 return f"""{lhs_print} = tarch::accelerator::GPUMemoryManager::getInstance().allocate<{type_print}>({size_print}, deviceNumber);"""
41
42 def print_memory_deallocation(self, memory_deallocation: MemoryDeallocation, indent_level: int = 0) -> str:
43 lhs_print = memory_deallocation.lhs.print(self)
44 return f"""tarch::accelerator::GPUMemoryManager::getInstance().free({lhs_print}, deviceNumber);"""
45
str print_memory_deallocation(self, MemoryDeallocation memory_deallocation, int indent_level=0)
print_data_block_construction_from_function_call(self, DataBlockConstructionFromFunctionCall data_block_construction_from_function_call, int indent_level=0)
str print_data_block_unary_max(self, DataBlockUnaryMax data_block_unary_max, int indent_level=0)
__init__(self, int spaces_per_tab)
str print_data_block_assignment(self, DataBlockAssignment data_block_assignment, int indent_level=0)
str print_memory_allocation(self, MemoryAllocation memory_allocation, int indent_level=0)