-
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathgenerate.go
More file actions
116 lines (110 loc) · 3.36 KB
/
Copy pathgenerate.go
File metadata and controls
116 lines (110 loc) · 3.36 KB
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
//go:build ignore
package main
import (
"fmt"
"os"
"path/filepath"
"regexp"
"github.com/gocnn/gocu/internal/codegen"
)
var (
Package = "gocu"
HeaderDir = filepath.Join("internal", "cuda")
Versions = []codegen.Version{
{Version: "v11.8", BuildTag: "cuda11"},
{Version: "v12.9", BuildTag: "cuda12"},
{Version: "v13.0", BuildTag: "cuda13"},
}
)
func main() {
cuResultCfg := codegen.Config{
Package: Package,
Filename: "result",
Versions: Versions,
HeaderDir: HeaderDir,
HeaderFile: "cuda.h",
Include: "cuda.h",
StructName: "Result",
CGoType: "",
StartString: "typedef enum cudaError_enum",
TemplatePath: filepath.Join("internal", "tmpl", "cuda_enum.tmpl"),
IsEnum: true,
FieldRegex: regexp.MustCompile(`^\s*(\w+)\s*=\s*(0x[0-9a-fA-F]+|\d+),?\s*(?:/\*\*<?\s*(.*?)\s*\*/)?$`),
}
deviceAttrCfg := codegen.Config{
Package: Package,
Filename: "device_attr",
Versions: Versions,
HeaderDir: HeaderDir,
HeaderFile: "cuda.h",
Include: "cuda.h",
StructName: "DeviceAttr",
CGoType: "",
StartString: "typedef enum CUdevice_attribute_enum",
TemplatePath: filepath.Join("internal", "tmpl", "cuda_enum.tmpl"),
IsEnum: true,
FieldRegex: regexp.MustCompile(`^\s*(\w+)\s*=\s*(0x[0-9a-fA-F]+|\d+),?\s*(?:/\*\*<?\s*(.*?)\s*\*/)?$`),
}
limitCfg := codegen.Config{
Package: Package,
Filename: "limit",
Versions: Versions,
HeaderDir: HeaderDir,
HeaderFile: "cuda.h",
Include: "cuda.h",
StructName: "Limit",
CGoType: "",
StartString: "typedef enum CUlimit_enum",
TemplatePath: filepath.Join("internal", "tmpl", "cuda_enum.tmpl"),
IsEnum: true,
FieldRegex: regexp.MustCompile(`^\s*(\w+)\s*=\s*(0x[0-9a-fA-F]+|\d+),?\s*(?:/\*\*<?\s*(.*?)\s*\*/)?$`),
}
contextFlagCfg := codegen.Config{
Package: Package,
Filename: "context_flag",
Versions: Versions,
HeaderDir: HeaderDir,
HeaderFile: "cuda.h",
Include: "cuda.h",
StructName: "ContextFlag",
CGoType: "",
StartString: "typedef enum CUctx_flags_enum",
TemplatePath: filepath.Join("internal", "tmpl", "cuda_enum.tmpl"),
IsEnum: true,
FieldRegex: regexp.MustCompile(`^\s*(\w+)\s*=\s*(0x[0-9a-fA-F]+|\d+),?\s*(?:/\*\*<?\s*(.*?)\s*\*/)?$`),
}
jitOptionCfg := codegen.Config{
Package: Package,
Filename: "jit_option",
Versions: Versions,
HeaderDir: HeaderDir,
HeaderFile: "cuda.h",
Include: "cuda.h",
StructName: "JitOption",
CGoType: "",
StartString: "typedef enum CUjit_option_enum",
TemplatePath: filepath.Join("internal", "tmpl", "cuda_enum.tmpl"),
IsEnum: true,
FieldRegex: regexp.MustCompile(`^\s*(\w+)\s*(?:=\s*(0x[0-9a-fA-F]+|\d+))?,?\s*(?:/\*\*<?\s*(.*?)\s*\*/)?$`),
}
if err := codegen.Generate(cuResultCfg); err != nil {
fmt.Fprintf(os.Stderr, "CUResult: %v\n", err)
os.Exit(1)
}
if err := codegen.Generate(deviceAttrCfg); err != nil {
fmt.Fprintf(os.Stderr, "DeviceAttr: %v\n", err)
os.Exit(1)
}
if err := codegen.Generate(limitCfg); err != nil {
fmt.Fprintf(os.Stderr, "Limit: %v\n", err)
os.Exit(1)
}
if err := codegen.Generate(contextFlagCfg); err != nil {
fmt.Fprintf(os.Stderr, "ContextFlag: %v\n", err)
os.Exit(1)
}
if err := codegen.Generate(jitOptionCfg); err != nil {
fmt.Fprintf(os.Stderr, "JitOption: %v\n", err)
os.Exit(1)
}
}