File: fence.py

package info (click to toggle)
llvm-toolchain-21 1%3A21.1.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 2,245,044 kB
  • sloc: cpp: 7,619,726; ansic: 1,434,018; asm: 1,058,748; python: 252,740; f90: 94,671; objc: 70,685; lisp: 42,813; pascal: 18,401; sh: 8,601; ml: 5,111; perl: 4,720; makefile: 3,666; awk: 3,523; javascript: 2,409; xml: 892; fortran: 770
file content (56 lines) | stat: -rw-r--r-- 1,857 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# For manual usage, not as a part of lit tests. Used for generating the following tests:
# fence-sm30.ll, fence-sm70.ll, fence-sm90.ll

from string import Template
from itertools import product

fence_func = Template(
    """
define void @fence_${ordering}_${ptx_scope}() {
    fence syncscope(\"${llvm_scope}\") ${ordering}
    ret void
}
"""
)

run_statement = Template(
    """; RUN: llc < %s -march=nvptx64 -mcpu=sm_${sm} -mattr=+ptx${ptx} | FileCheck %s --check-prefix=SM${sm}
; RUN: %if ptxas %{ llc < %s -march=nvptx -mcpu=sm_${sm} -mattr=+ptx${ptx} | %ptxas-verify %}"""
)

# (sm, ptx)
TESTS = [(30, 50), (70, 60), (90, 87)]

LLVM_SCOPES_NO_CLUSTER = ["", "block", "device"]

SCOPE_LLVM_TO_PTX = {"": "sys", "block": "cta", "cluster": "cluster", "device": "gpu"}

ORDERINGS = ["acquire", "release", "acq_rel", "seq_cst"]

if __name__ == "__main__":
    # non-cluster orderings are supported on SM30, SM70 and SM90
    with open("fence-nocluster.ll", "w") as fp:
        for sm, ptx in TESTS:
            print(run_statement.substitute(sm=sm, ptx=ptx), file=fp)
        for ordering, llvm_scope in product(ORDERINGS, LLVM_SCOPES_NO_CLUSTER):
            print(
                fence_func.substitute(
                    llvm_scope=llvm_scope,
                    ptx_scope=SCOPE_LLVM_TO_PTX[llvm_scope],
                    ordering=ordering,
                ),
                file=fp,
            )

    # cluster ordering only supported on SM90
    with open("fence-cluster.ll", "w") as fp:
        print(run_statement.substitute(sm=90, ptx=87), file=fp)
        for ordering in ORDERINGS:
            print(
                fence_func.substitute(
                    llvm_scope="cluster",
                    ptx_scope=SCOPE_LLVM_TO_PTX["cluster"],
                    ordering=ordering,
                ),
                file=fp,
            )