@@ -29,6 +29,25 @@ class SPIRVCodeLibrary(CPUCodeLibrary):
29
29
def _optimize_functions (self , ll_module ):
30
30
pass
31
31
32
+ @property
33
+ def inline_threshold (self ):
34
+ """The inlining threshold value to be used to optimize the final library"""
35
+ if hasattr (self , "_inline_threshold" ):
36
+ return self ._inline_threshold
37
+ else :
38
+ return 0
39
+
40
+ @inline_threshold .setter
41
+ def inline_threshold (self , value : int ):
42
+ """Returns the current inlining threshold level for the library."""
43
+ if value < 0 or value > 3 :
44
+ logging .warning (
45
+ "Unsupported inline threshold. Set a value between 0 and 3"
46
+ )
47
+ self ._inline_threshold = 0
48
+ else :
49
+ self ._inline_threshold = value
50
+
32
51
def _optimize_final_module (self ):
33
52
# Run some lightweight optimization to simplify the module.
34
53
pmb = ll .PassManagerBuilder ()
@@ -43,12 +62,38 @@ def _optimize_final_module(self):
43
62
)
44
63
45
64
pmb .disable_unit_at_a_time = False
65
+
46
66
if config .INLINE_THRESHOLD is not None :
47
- logging .warning (
48
- "Setting INLINE_THRESHOLD leads to very aggressive "
49
- + "optimizations that may produce incorrect binary."
50
- )
51
- pmb .inlining_threshold = config .INLINE_THRESHOLD
67
+ # Check if a decorator-level inline threshold was set and use that
68
+ # instead of the global configuration.
69
+ if (
70
+ hasattr (self , "_inline_threshold" )
71
+ and self ._inline_threshold > 0
72
+ and self ._inline_threshold <= 3
73
+ ):
74
+ logging .warning (
75
+ "Setting INLINE_THRESHOLD leads to very aggressive "
76
+ + "optimizations that may produce incorrect binary."
77
+ )
78
+ pmb .inlining_threshold = self ._inline_threshold
79
+ elif not hasattr (self , "_inline_threshold" ):
80
+ logging .warning (
81
+ "Setting INLINE_THRESHOLD leads to very aggressive "
82
+ + "optimizations that may produce incorrect binary."
83
+ )
84
+ pmb .inlining_threshold = config .INLINE_THRESHOLD
85
+ else :
86
+ if (
87
+ hasattr (self , "_inline_threshold" )
88
+ and self ._inline_threshold > 0
89
+ and self ._inline_threshold <= 3
90
+ ):
91
+ logging .warning (
92
+ "Setting INLINE_THRESHOLD leads to very aggressive "
93
+ + "optimizations that may produce incorrect binary."
94
+ )
95
+ pmb .inlining_threshold = self ._inline_threshold
96
+
52
97
pmb .disable_unroll_loops = True
53
98
pmb .loop_vectorize = False
54
99
pmb .slp_vectorize = False
0 commit comments