-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
GH-135379: Support limited scalar replacement for replicated uops in the JIT code generator. #135563
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GH-135379: Support limited scalar replacement for replicated uops in the JIT code generator. #135563
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -180,7 +180,7 @@ class Uop: | |
properties: Properties | ||
_size: int = -1 | ||
implicitly_created: bool = False | ||
replicated = 0 | ||
replicated = range(0) | ||
replicates: "Uop | None" = None | ||
# Size of the instruction(s), only set for uops containing the INSTRUCTION_SIZE macro | ||
instruction_size: int | None = None | ||
|
@@ -868,6 +868,28 @@ def compute_properties(op: parser.CodeDef) -> Properties: | |
needs_prev=variable_used(op, "prev_instr"), | ||
) | ||
|
||
def expand(items: list[StackItem], oparg: int) -> list[StackItem]: | ||
# Only replace array item with scalar if no more than item is an array | ||
index = -1 | ||
for i, item in enumerate(items): | ||
if "oparg" in item.size: | ||
if index >= 0: | ||
return items | ||
index = i | ||
if index < 0: | ||
return items | ||
Comment on lines
+873
to
+880
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This entire part is somewhat confusing, but I'll let it slide since there's a comment up top :). |
||
try: | ||
count = int(eval(items[index].size.replace("oparg", str(oparg)))) | ||
except ValueError: | ||
return items | ||
return items[:index] + [ | ||
StackItem(items[index].name + f"_{i}", "", items[index].peek, items[index].used) for i in range(count) | ||
] + items[index+1:] | ||
|
||
def scalarize_stack(stack: StackEffect, oparg: int) -> StackEffect: | ||
stack.inputs = expand(stack.inputs, oparg) | ||
stack.outputs = expand(stack.outputs, oparg) | ||
return stack | ||
|
||
def make_uop( | ||
name: str, | ||
|
@@ -887,20 +909,26 @@ def make_uop( | |
) | ||
for anno in op.annotations: | ||
if anno.startswith("replicate"): | ||
result.replicated = int(anno[10:-1]) | ||
text = anno[10:-1] | ||
start, stop = text.split(":") | ||
result.replicated = range(int(start), int(stop)) | ||
break | ||
else: | ||
return result | ||
for oparg in range(result.replicated): | ||
for oparg in result.replicated: | ||
name_x = name + "_" + str(oparg) | ||
properties = compute_properties(op) | ||
properties.oparg = False | ||
properties.const_oparg = oparg | ||
stack = analyze_stack(op) | ||
if not variable_used(op, "oparg"): | ||
stack = scalarize_stack(stack, oparg) | ||
else: | ||
properties.const_oparg = oparg | ||
rep = Uop( | ||
name=name_x, | ||
context=op.context, | ||
annotations=op.annotations, | ||
stack=analyze_stack(op), | ||
stack=stack, | ||
caches=analyze_caches(inputs), | ||
local_stores=find_variable_stores(op), | ||
body=op.block, | ||
|
Uh oh!
There was an error while loading. Please reload this page.