Skip to content

Commit

Permalink
Add loader code generation scripts to /scripts dir
Browse files Browse the repository at this point in the history
Signed-off-by: Brandon Yates <[email protected]>
  • Loading branch information
bmyates committed Jul 22, 2022
1 parent 45148fc commit 474188a
Show file tree
Hide file tree
Showing 18 changed files with 66,814 additions and 2 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# Level zero loader changelog

## v1.8.5
* Remove RTLD_DEEPBIND from driver dlopen calls
* Add loader code generation scripts
* Update to spec 1.4.8 which includes fixes to zes_power_limit_ext_desc_t

## v1.8.1
*Add missing sTypes
*Fix argument names in some exp APIs
* Add missing sTypes
* Fix argument names in some exp APIs

## v1.8.0
* Add Support for L0 Spec v1.4 which includes
Expand Down
352 changes: 352 additions & 0 deletions scripts/generate_code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,352 @@
"""
Copyright (C) 2019-2021 Intel Corporation
SPDX-License-Identifier: MIT
"""
import os
import re
import util

templates_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "templates")
tracing_templates_dir = os.path.join(templates_dir, "tracing")

"""
generates c/c++ files from the specification documents
"""
def _mako_ddi_cpp(path, namespace, tags, version, specs, meta):
template = "ddi.h.mako"
fin = os.path.join(templates_dir, template)

filename = "%s_ddi.h"%(namespace)
fout = os.path.join(path, filename)

print("Generating %s..."%fout)
return util.makoWrite(
fin, fout,
ver=version,
namespace=namespace,
tags=tags,
specs=specs,
meta=meta)

"""
generates c/c++ files from the specification documents
"""
def _mako_lib_cpp(path, namespace, tags, version, specs, meta):
loc = 0
template = "libapi.cpp.mako"
fin = os.path.join(templates_dir, template)

name = "%s_libapi"%(namespace)
filename = "%s.cpp"%(name)
fout = os.path.join(path, filename)

print("Generating %s..."%fout)
loc += util.makoWrite(
fin, fout,
name = name,
ver=version,
namespace=namespace,
tags=tags,
specs=specs,
meta = meta)

template = "libddi.cpp.mako"
fin = os.path.join(templates_dir, template)

name = "%s_libddi"%(namespace)
filename = "%s.cpp"%(name)
fout = os.path.join(path, filename)

print("Generating %s..."%fout)
loc += util.makoWrite(
fin, fout,
name=name,
ver=version,
namespace=namespace,
tags=tags,
specs=specs,
meta=meta)
return loc

"""
generates c/c++ files from the specification documents
"""
def _mako_wrapper_cpp(path, namespace, tags, version, specs, meta):
loc = 0
template = "wprapi.cpp.mako"
fin = os.path.join(templates_dir, template)

name = "%s_wprapi"%(namespace)
filename = "%s.cpp"%(name)
fout = os.path.join(path, filename)

print("Generating %s..."%fout)
loc += util.makoWrite(
fin, fout,
name = name,
ver=version,
namespace=namespace,
tags=tags,
specs=specs,
meta = meta)
return loc

"""
generates c/c++ files from the specification documents
"""
def _mako_loader_cpp(path, namespace, tags, version, specs, meta):
print("make_loader_cpp path %s namespace %s version %s\n" %(path, namespace, version))
loc = 0
template = "ldrddi.h.mako"
fin = os.path.join(templates_dir, template)

name = "%s_ldrddi"%(namespace)
filename = "%s.h"%(name)
fout = os.path.join(path, filename)

print("Generating %s..."%fout)
loc += util.makoWrite(
fin, fout,
name=name,
ver=version,
namespace=namespace,
tags=tags,
specs=specs,
meta=meta)

template = "ldrddi.cpp.mako"
fin = os.path.join(templates_dir, template)

name = "%s_ldrddi"%(namespace)
filename = "%s.cpp"%(name)
fout = os.path.join(path, filename)

print("Generating %s..."%fout)
loc += util.makoWrite(
fin, fout,
name=name,
ver=version,
namespace=namespace,
tags=tags,
specs=specs,
meta=meta)
return loc

"""
generates c/c++ files from the specification documents
"""
def _mako_validation_layer_cpp(path, namespace, tags, version, specs, meta):
dstpath = os.path.join(path, "validation")
os.makedirs(dstpath, exist_ok=True)

template = "valddi.cpp.mako"
fin = os.path.join(templates_dir, template)

name = "%s_valddi"%(namespace)
filename = "%s.cpp"%(name)
fout = os.path.join(dstpath, filename)

print("Generating %s..."%fout)
return util.makoWrite(
fin, fout,
name=name,
ver=version,
namespace=namespace,
tags=tags,
specs=specs,
meta=meta)


"""
generates c/c++ files from the specification documents
"""
def _mako_tracing_layer_h(path, namespace, tags, version, specs, meta):
dstpath = os.path.join(path, "layers")
os.makedirs(dstpath, exist_ok=True)

template = "trc_setters.h.mako"
fin = os.path.join(tracing_templates_dir, template)

name = "zel_tracing_register_cb"
filename = "%s.h"%(name)
fout = os.path.join(dstpath, filename)

print("Generating %s..."%fout)
return util.makoWrite(
fin, fout,
name=name,
ver=version,
namespace=namespace,
tags=tags,
specs=specs,
meta=meta)


"""
generates c/c++ files from the specification documents
"""
def _mako_tracing_layer_cpp(path, namespace, tags, version, specs, meta):
dstpath = os.path.join(path, "tracing")
os.makedirs(dstpath, exist_ok=True)

template = "trcddi.cpp.mako"
fin = os.path.join(tracing_templates_dir, template)

name = "%s_trcddi"%(namespace)
filename = "%s.cpp"%(name)
fout = os.path.join(dstpath, filename)

print("Generating %s..."%fout)
loc = util.makoWrite(
fin, fout,
name=name,
ver=version,
namespace=namespace,
tags=tags,
specs=specs,
meta=meta)

template = "trc_setters.cpp.mako"
fin = os.path.join(tracing_templates_dir, template)

name = "ze_tracing_register_cb"
filename = "%s.cpp"%(name)
fout = os.path.join(dstpath, filename)

print("Generating %s..."%fout)
loc += util.makoWrite(
fin, fout,
name=name,
ver=version,
namespace=namespace,
tags=tags,
specs=specs,
meta=meta)

template = "trc_cb_struct.h.mako"
fin = os.path.join(tracing_templates_dir, template)

name = "ze_tracing_cb_structs"
filename = "%s.h"%(name)
fout = os.path.join(dstpath, filename)

print("Generating %s..."%fout)
loc += util.makoWrite(
fin, fout,
name=name,
ver=version,
namespace=namespace,
tags=tags,
specs=specs,
meta=meta)

return loc

"""
generates c/c++ files from the specification documents
"""
def _mako_tracing_lib_cpp(path, namespace, tags, version, specs, meta):
dstpath = os.path.join(path, "lib")
os.makedirs(dstpath, exist_ok=True)

template = "trc_register_cb_libapi.cpp.mako"
fin = os.path.join(tracing_templates_dir, template)

name = "ze_tracing_register_cb_libapi"
filename = "%s.cpp"%(name)
fout = os.path.join(dstpath, filename)

print("Generating %s..."%fout)
return util.makoWrite(
fin, fout,
name=name,
ver=version,
namespace=namespace,
tags=tags,
specs=specs,
meta=meta)

"""
generates c/c++ files from the specification documents
"""
def _mako_null_driver_cpp(path, namespace, tags, version, specs, meta):
dstpath = os.path.join(path, "null")
os.makedirs(dstpath, exist_ok=True)

template = "nullddi.cpp.mako"
fin = os.path.join(templates_dir, template)

name = "%s_nullddi"%(namespace)
filename = "%s.cpp"%(name)
fout = os.path.join(dstpath, filename)

print("Generating %s..."%fout)
return util.makoWrite(
fin, fout,
name=name,
ver=version,
namespace=namespace,
tags=tags,
specs=specs,
meta=meta)

"""
Entry-point:
generates lib code
"""
def generate_lib(path, section, namespace, tags, version, specs, meta):
dstpath = os.path.join(path, "lib")
os.makedirs(dstpath, exist_ok=True)

loc = 0
loc += _mako_lib_cpp(dstpath, namespace, tags, version, specs, meta)
print("Generated %s lines of code.\n"%loc)

"""
Entry-point:
generates loader for level_zero driver
"""
def generate_loader(path, section, namespace, tags, version, specs, meta):
dstpath = os.path.join(path, "loader")
os.makedirs(dstpath, exist_ok=True)

loc = 0
loc += _mako_loader_cpp(dstpath, namespace, tags, version, specs, meta)
print("Generated %s lines of code.\n"%loc)

"""
Entry-point:
generates layers for level_zero driver
"""
def generate_layers(path, section, namespace, tags, version, specs, meta):
print("GL section %s\n"%section)
print("GL namespace %s\n"%namespace)
layer_dstpath = os.path.join(path, "layers")
include_dstpath = os.path.join(path, "../include")
os.makedirs(layer_dstpath, exist_ok=True)
os.makedirs(include_dstpath, exist_ok=True)

loc = 0
loc += _mako_validation_layer_cpp(layer_dstpath, namespace, tags, version, specs, meta)
print("VALIDATION Generated %s lines of code.\n"%loc)
if section == "core":
loc += _mako_tracing_layer_cpp(layer_dstpath, namespace, tags, version, specs, meta)
print("TRACING Generated %s lines of code.\n"%loc)
loc += _mako_tracing_lib_cpp(path, namespace, tags, version, specs, meta)
print("TRACING Generated %s lines of code.\n"%loc)
loc += _mako_tracing_layer_h(include_dstpath, namespace, tags, version, specs, meta)
print("TRACING header Generated %s lines of code.\n"%loc)

"""
Entry-point:
generates drivers for level_zero driver
"""
def generate_drivers(path, section, namespace, tags, version, specs, meta):
dstpath = os.path.join(path, "drivers")
os.makedirs(dstpath, exist_ok=True)

loc = 0
loc += _mako_null_driver_cpp(dstpath, namespace, tags, version, specs, meta)
print("Generated %s lines of code.\n"%loc)
Loading

0 comments on commit 474188a

Please sign in to comment.