code: def main():
      # Register the converter for custom Keras layer
      hls4ml.converters.register_keras_layer_handler(
          "KLLoss", parse_klloss_layer
      )
  
      # Register the hls4ml's IR layer
      hls4ml.model.layers.register_layer("KLLoss", HKLLoss)
  
      # Register the optimization passes (if any)
      backend = hls4ml.backends.get_backend("Vivado")
  
      # Register template passes for the given backend
      backend.register_template(HKLLossConfigTemplate)
      backend.register_template(HKLLossFunctionTemplate)
  
      # Register HLS implementation
      p = Path(__file__).parent / "kl_layer.h"
      backend.register_source(p)
  
      # Test if it works
      # Create a dummy Keras model with KL loss layer
      inp = tf.keras.layers.Input(shape=(19, 3, 1))
      z_mean = tf.keras.layers.Dense(10)(inp)
      z_log_var = tf.keras.layers.Dense(10)(inp)
      custom_output = KLLoss()([z_mean, z_log_var])
      # create new model
      kmodel = tf.keras.models.Model(inputs=inp, outputs=custom_output)
      kmodel.summary()
  
      # test on random inputs
      x = np.random.randint(-5, 5, (1, 19, 3, 1), dtype="int32")
      kres = kmodel(x)
  
      # Create dummy config
      config = {}
      config["Model"] = {
          "Precision": "ap_fixed<16,6>",
          "ReuseFactor": 1,
          "ParallelizationFactor": 1,
          "Strategy": "Resource",
      }
      hmodel = hls4ml.converters.convert_from_keras_model(
          kmodel,
          output_dir="hls4mlprj_kl_layer",
          backend="Vivado",
          io_type="io_parallel",
          part="xcvu9p-flga2577-2-e",
          hls_config=config,
      )
  
      hmodel.compile()
      hres = hmodel.predict(x.astype("float32"))
  
      print("Compare prediction by hls4ml model to Keras one")
      print(kres - hres)
  
      print("Building model")
      report = hmodel.build(
          reset=True, csim=False, cosim=True, synth=True, vsynth=True
      )
      print(report)
  
imports: from pathlib import Path
  import numpy
  import tensorflow
  from tensorflow.python.keras.utils import tf_utils
  from tensorflow.python.ops import math_ops
  import hls4ml
  from hls4ml.converters.keras_to_hls import parse_default_keras_layer
  from hls4ml.model.attributes import ConfigurableAttribute, TypeAttribute
  from hls4ml.model.types import FixedPrecisionType, RoundingMode, SaturationMode
label_desc: Use image node_id 2 for calling a global function with example usage: main() without return types