brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.2 KiB · 75623a5 Raw
134 lines · python
1# For manual usage, not as a part of lit tests. Used for generating the following tests:2# cmpxchg-sm30.ll, cmpxchg-sm70.ll, cmpxchg-sm90.ll3 4from string import Template5from itertools import product6 7cmpxchg_func = Template(8    """define i$size @${success}_${failure}_i${size}_${addrspace}_${ptx_scope}(ptr${addrspace_cast} %addr, i$size %cmp, i$size %new) {9    %pairold = cmpxchg ptr${addrspace_cast} %addr, i$size %cmp, i$size %new syncscope(\"${llvm_scope}\") $success $failure10    ret i$size %new11}12"""13)14 15cmpxchg_func_no_scope = Template(16    """define i$size @${success}_${failure}_i${size}_${addrspace}(ptr${addrspace_cast} %addr, i$size %cmp, i$size %new) {17    %pairold = cmpxchg ptr${addrspace_cast} %addr, i$size %cmp, i$size %new $success $failure18    ret i$size %new19}20"""21)22 23run_statement = Template(24    """; RUN: llc < %s -march=nvptx64 -mcpu=sm_${sm} -mattr=+ptx${ptx} | FileCheck %s --check-prefix=SM${sm}25; RUN: %if ptxas %{ llc < %s -march=nvptx64 -mcpu=sm_${sm} -mattr=+ptx${ptx} | %ptxas-verify -arch=sm_${sm} %}26"""27)28 29 30def get_addrspace_cast(addrspace):31    if addrspace == 0:32        return ""33    else:34        return " addrspace({})".format(str(addrspace))35 36 37TESTS = [(60, 50), (70, 63), (90, 87)]38 39LLVM_SCOPES = ["", "block", "cluster", "device"]40 41SCOPE_LLVM_TO_PTX = {"": "sys", "block": "cta", "cluster": "cluster", "device": "gpu"}42 43SUCCESS_ORDERINGS = ["monotonic", "acquire", "release", "acq_rel", "seq_cst"]44 45FAILURE_ORDERINGS = ["monotonic", "acquire", "seq_cst"]46 47SIZES = [8, 16, 32, 64]48 49ADDRSPACES = [0, 1, 3]50 51ADDRSPACE_NUM_TO_ADDRSPACE = {0: "generic", 1: "global", 3: "shared"}52 53 54if __name__ == "__main__":55    for sm, ptx in TESTS:56        with open("cmpxchg-sm{}.ll".format(str(sm)), "w") as fp:57            print(run_statement.substitute(sm=sm, ptx=ptx), file=fp)58 59            # Our test space is: SIZES X SUCCESS_ORDERINGS X FAILURE_ORDERINGS X ADDRSPACES X LLVM_SCOPES60            # This is very large, so we instead test 3 slices.61 62            # First slice:  are all orderings correctly supported, with and without emulation loops?63            # set addrspace to global, scope to cta, generate all possible orderings, for all operation sizes64            addrspace, llvm_scope = 1, "block"65            for size, success, failure in product(66                SIZES, SUCCESS_ORDERINGS, FAILURE_ORDERINGS67            ):68                print(69                    cmpxchg_func.substitute(70                        success=success,71                        failure=failure,72                        size=size,73                        addrspace=ADDRSPACE_NUM_TO_ADDRSPACE[addrspace],74                        addrspace_cast=get_addrspace_cast(addrspace),75                        llvm_scope=llvm_scope,76                        ptx_scope=SCOPE_LLVM_TO_PTX[llvm_scope],77                    ),78                    file=fp,79                )80 81            # Second slice: Are all scopes correctlly supported, with and without emulation loops?82            # fix addrspace, ordering, generate all possible scopes, for operation sizes i8, i3283            addrspace, success, failure = 1, "acq_rel", "acquire"84            for size in [8, 32]:85                print(86                    cmpxchg_func_no_scope.substitute(87                        success=success,88                        failure=failure,89                        size=size,90                        addrspace=ADDRSPACE_NUM_TO_ADDRSPACE[addrspace],91                        addrspace_cast=get_addrspace_cast(addrspace),92                    ),93                    file=fp,94                )95 96            for llvm_scope in LLVM_SCOPES:97                if sm < 90 and llvm_scope == "cluster":98                    continue99                if llvm_scope == "block":100                    # skip (acq_rel, acquire, global, cta)101                    continue102                print(103                    cmpxchg_func.substitute(104                        success=success,105                        failure=failure,106                        size=size,107                        addrspace=ADDRSPACE_NUM_TO_ADDRSPACE[addrspace],108                        addrspace_cast=get_addrspace_cast(addrspace),109                        llvm_scope=llvm_scope,110                        ptx_scope=SCOPE_LLVM_TO_PTX[llvm_scope],111                    ),112                    file=fp,113                )114 115            # Third slice: Are all address spaces correctly supported?116            # fix ordering, scope, generate all possible address spaces, for operation sizes i8, i32117            success, failure, llvm_scope = "acq_rel", "acquire", "block"118            for size, addrspace in product([8, 32], ADDRSPACES):119                if addrspace == 1:120                    # skip (acq_rel, acquire, global, cta)121                    continue122                print(123                    cmpxchg_func.substitute(124                        success=success,125                        failure=failure,126                        size=size,127                        addrspace=ADDRSPACE_NUM_TO_ADDRSPACE[addrspace],128                        addrspace_cast=get_addrspace_cast(addrspace),129                        llvm_scope=llvm_scope,130                        ptx_scope=SCOPE_LLVM_TO_PTX[llvm_scope],131                    ),132                    file=fp,133                )134