-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.rkt
120 lines (98 loc) · 3.75 KB
/
main.rkt
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#lang rosette
(require
"ptx.rkt"
"emulate.rkt")
;; % ptxas --help 2>&1 | sed -n 's/^\(.*\) <.*(\(.*\)).*$/"\1" "\2"/p'
(define flags-with-option
'("--allow-expensive-optimizations" "-allow-expensive-optimizations"
"--device-function-maxrregcount" "-func-maxrregcount"
"--entry" "-e"
"--fmad" "-fmad"
"--gpu-name" "-arch"
"--input-as-string" "-ias"
"--machine" "-m"
"--maxrregcount" "-maxrregcount"
"--opt-level" "-O"
"--options-file" "-optf"
"--output-file" "-o"
"--def-load-cache" "-dlcm"
"--def-store-cache" "-dscm"
"--machine" "-m"
"--opt-level"
))
;; % ptxas --help 2>&1 | sed -n 's/^\(--[^ ]*\) *(\(.*\)).*$/"\1" "\2"/p'
(define flags-without-option
'("--compile-as-tools-patch" "-astoolspatch"
"--compile-only" "-c"
"--device-debug" "-g"
"--disable-optimizer-constants" "-disable-optimizer-consts"
"--disable-warnings" "-w"
"--dont-merge-basicblocks" "-no-bb-merge"
"--extensible-whole-program" "-ewp"
"--force-load-cache" "-flcm"
"--force-store-cache" "-fscm"
"--generate-line-info" "-lineinfo"
"--help" "-h"
"--legacy-bar-warp-wide-behavior" "-legacy-bar-warp-wide-behavior"
"--optimize-float-atomics" "-opt-fp-atomics"
"--preserve-relocs" "-preserve-relocs"
"--return-at-end" "-ret-end"
"--sp-bounds-check" "-sp-bounds-check"
"--suppress-debug-info" "-suppress-debug-info"
"--suppress-double-demote-warning" "-suppress-double-demote-warning"
"--suppress-stack-size-warning" "-suppress-stack-size-warning"
"--verbose" "-v"
"--version" "-V"
"--warn-on-double-precision-use" "-warn-double-usage"
"--warn-on-local-memory-usage" "-warn-lmem-usage"
"--warn-on-spills" "-warn-spills"
"--warning-as-error" "-Werror"
"--m32" "-m32"
"--m64" "-m64"
"-O0" "-O1" "-O2" "-O3" "-O4"
))
(define (extract-filename args)
(if (null? args) #f
(let ([head (car args)])
(cond
[(member head flags-with-option)
(extract-filename (cddr args))]
[(let* ([m (regexp-match #rx"(.*)=(.*)" head)]
[r (and m (list-ref m 1))])
(member r flags-with-option))
(extract-filename (cdr args))]
[(member head flags-without-option)
(extract-filename (cdr args))]
[else head]
))))
(define (main args)
(define filename (extract-filename args))
(unless filename
(error "No input"))
;; Load PTX
(define ptxasm (ptx-read filename))
(unless ptxasm
(error "Failed to parse" filename))
;; Optimize; then, Store PTX
(ptx-write (emulate ptxasm) filename))
(module+ main
;; Define a variable to omit the output of the return value
(define exit-code (main (vector->list (current-command-line-arguments)))))
(module+ test
(require rackunit rackunit/text-ui)
(run-tests
(test-suite "main"
(test-case "extract-filename"
(define gcc-args '("-c" "-o" "/dev/null" "/tmp/ccXuhZoA.o" "--gpu-name" "sm_35" "-O0"))
(define gcc-file "/tmp/ccXuhZoA.o")
(define llvm-args '("-m64" "-O3" "--gpu-name" "sm_70" "--output-file" "/tmp/omp-4b445e.cubin" "/tmp/omp-115202.s" "-c"))
(define llvm-file "/tmp/omp-115202.s")
(define pgi-args '("-arch=sm_70" "-w" "-m64" "-O3" "-o" "/tmp/pgaccD1TqxfhCgqfQ.bin" "--compile-only" "/tmp/pgacc11TqF5NiESNX.ptx"))
(define pgi-file "/tmp/pgacc11TqF5NiESNX.ptx")
(check-equal? (extract-filename gcc-args) gcc-file )
(check-equal? (extract-filename llvm-args) llvm-file)
(check-equal? (extract-filename pgi-args) pgi-file )
(define nvptx-none-args '("-m" "sm_35" "-o" "/tmp/cca5iFKt.o" "/tmp/ccKMbo2z.s"))
(define nvptx-none-file "/tmp/ccKMbo2z.s")
(check-equal? (extract-filename nvptx-none-args) nvptx-none-file) )
)))