DPC++ Runtime
Runtime libraries for oneAPI DPC++
ze_api_generator.py
Go to the documentation of this file.
1 import re
2 import sys
3 
4 
5 def camel_to_snake(src):
6  return re.sub(r"(?<!^)(?=[A-Z])", "_", src).lower()
7 
8 
9 def snake_to_camel(src):
10  temp = src.split("_")
11  return "".join(x.title() for x in temp)
12 
13 
14 def extract_ze_apis(header):
15  """
16  Emit file with contents of
17  _ZE_API(api_name, api_domain, cb, param_type)
18  """
19  api = open("ze_api.def", "w")
20 
21  matches = re.finditer(
22  r"typedef struct _ze_([_a-z]+)_callbacks_t\n\{\n([a-zA-Z_;\s\n]+)\n\} ze_([_a-z]+)_callbacks_t;",
23  header,
24  )
25 
26  for match in matches:
27  api_domain = snake_to_camel(match.group(1))
28  for l in match.group(2).splitlines():
29  parts = l.split()
30  api_match = re.match(r"ze_pfn([a-zA-Z]+)Cb_t", parts[0])
31  api_name_tail = api_match.group(1)
32  api_name = "ze" + api_name_tail
33 
34  param_type = "ze_" + camel_to_snake(api_name_tail) + "_params_t"
35 
36  cb = "pfn" + api_name_tail.replace(api_domain, "") + "Cb"
37 
38  api.write(
39  "_ZE_API({}, {}, {}, {})\n".format(api_name, api_domain, cb, param_type)
40  )
41 
42  api.close()
43 
44 
45 if __name__ == "__main__":
46  with open(sys.argv[1], "r") as f:
47  header = f.read()
48  extract_ze_apis(header)
sycl::kernel_bundle< State > join(const std::vector< sycl::kernel_bundle< State >> &Bundles)
def camel_to_snake(src)
def extract_ze_apis(header)
def snake_to_camel(src)