Exemple #1
0
    def visualize_variable(var: Variable) -> str:
        if var in added_variables:
            return ""
        node_attrs = {}
        node_attrs["label"] = f"\"{var.name}\n{var.shape}\nOrder={var.order}"
        from webdnn.backend.webgl.attributes.texture_shape import TextureShape
        if var.has_attribute(TextureShape):
            node_attrs["label"] += f"\nTextureShape={TextureShape.get(var)}"
        from webdnn.backend.webgl.attributes.channel_mode import ChannelMode
        if var.has_attribute(ChannelMode):
            node_attrs["label"] += f"\nChannelMode={ChannelMode.get(var).name}"
        node_attrs["label"] += "\""
        if isinstance(var, ConstantVariable):
            node_attrs["shape"] = "doubleoctagon"
        else:
            node_attrs["shape"] = "octagon"
        if var in graph.inputs:
            node_attrs["style"] = "\"dashed\""
        if var in graph.outputs:
            node_attrs["style"] = "\"bold\""

        dot_source_var = ""
        dot_source_var += f"var_{id(var)} [\n"
        dot_source_var += ",".join(
            f"{attr_key}={attr_value}"
            for attr_key, attr_value in node_attrs.items())
        dot_source_var += "];\n"
        added_variables.add(var)
        return dot_source_var
Exemple #2
0
    def __init__(self, base: Variable, mode: ChannelModeEnum):
        if base.has_attribute(ChannelMode):
            raise ValueError(
                f"\'ChannelMode\' attribute has been already registered to {base}."
            )

        super(ChannelMode, self).__init__(base)
        self.mode = mode  # type: ChannelModeEnum
Exemple #3
0
    def get(base: Variable):
        if not base.has_attribute(TextureShape):
            attribute = TextureShape(base)
            base.attributes.add(attribute)
        else:
            attribute = base.get_attribute(TextureShape)[0]

        return [attribute.height, attribute.width]
Exemple #4
0
 def __init__(self, base: Variable):
     if base.has_attribute(TextureShape):
         raise ValueError(f"\'TextureShape\' attribute has been already registered to {base}.")
     MAX_TEXTURE_SIZE = config.WEBGL_MAX_TEXTURE_SIZE
     super(TextureShape, self).__init__(base)
     spacial_size = base.size
     self.width = MAX_TEXTURE_SIZE if spacial_size > MAX_TEXTURE_SIZE else spacial_size  # type: int
     self.height = (spacial_size + MAX_TEXTURE_SIZE - 1) // MAX_TEXTURE_SIZE if spacial_size > MAX_TEXTURE_SIZE else 1  # type: int
Exemple #5
0
    def set(base: Variable, width: int, height: int):
        if not base.has_attribute(TextureShape):
            attribute = TextureShape(base)
            base.attributes.add(attribute)
        else:
            attribute = base.get_attribute(TextureShape)[0]

        attribute.width = width
        attribute.height = height
Exemple #6
0
    def get(variable: Variable):
        if variable.has_attribute(TextureShape):
            attribute = variable.get_attribute(TextureShape)[0]

        else:
            attribute = TextureShape(variable)
            variable.attributes.add(attribute)

        return attribute.height, attribute.width
Exemple #7
0
    def set(variable: Variable, width: int, height: int):
        if variable.has_attribute(TextureShape):
            attribute = variable.get_attribute(TextureShape)[0]
        else:
            attribute = TextureShape(variable)
            variable.attributes.add(attribute)

        attribute.width = width
        attribute.height = height
Exemple #8
0
    def __init__(self, base: Variable):
        if base.has_attribute(TextureShape):
            raise ValueError(
                f"\'TextureShape\' attribute has been already registered to {base}."
            )

        super(TextureShape, self).__init__(base)
        self.width = 2048 if base.size > 2048 else base.size  # type: int
        self.height = (base.size + 2048 -
                       1) // 2048 if base.size > 2048 else 1  # type: int
Exemple #9
0
 def get(base: Variable):
     return base.get_attribute(ChannelMode)[0].mode if base.has_attribute(
         ChannelMode) else ChannelModeEnum.R
Exemple #10
0
 def set(base: Variable, mode: ChannelModeEnum):
     if base.has_attribute(ChannelMode):
         base.get_attribute(ChannelMode)[0].mode = mode
     else:
         base.attributes.add(ChannelMode(base, mode=mode))