Example #1
0
def clip_v11_gpu(node: Node, alloc_map, config: Config) -> Callable[[], None]:

    input_io = node.inputs["input"]
    min_io = node.get_input("min")
    max_io = node.get_input("max")

    output_io = node.outputs["output"]

    inp = input_io.get_data(alloc_map)
    min_data = min_io.get_data(alloc_map)
    if min_data is None:
        min_data = cupy.array([float("-inf")])

    max_data = max_io.get_data(alloc_map)
    if max_data is None:
        max_data = cupy.array([float("inf")])

    output = output_io.get_data(alloc_map)

    def fn():
        with cupy.cuda.Device(node.device_id):
            cupy.copyto(
                output,
                chainer.functions.clip(inp, min_data[0], max_data[0]).array)

    return fn
Example #2
0
def conv_gpu(node: Node, alloc_map, config: Config) -> Callable[[], None]:
    """
        GPU Function:
                Y = X CONV W (Using padding, stride and dilaton attribute
    """
    x_io = node.inputs["X"]
    w_io = node.inputs["W"]
    b_io = node.get_input("B")
    y_io = node.outputs["Y"]

    x = x_io.get_data(alloc_map)
    w = w_io.get_data(alloc_map)
    b = b_io.get_data(alloc_map)
    y = y_io.get_data(alloc_map)

    stride = node.get_attr("strides")[
        0]  # Assuming same stride in all directions
    padding = node.get_attr("pads")[
        0]  # Assuming same padding in all directions
    dilations = node.get_attr("dilations")[
        0]  # Assuming same padding in all directions
    groups = node.get_attr("group", 1)

    stride = (stride, stride)
    padding = (padding, padding)
    dilations = (dilations, dilations)

    def fn():
        # time_st = datetime.datetime.now()
        # logging.log(logging.INFO, f"CONVOP got -->  {x[-1]} CONVOP")

        with cupy.cuda.Device(node.device_id):

            cupy.cudnn.convolution_forward(x,
                                           w,
                                           b,
                                           y,
                                           padding,
                                           stride,
                                           dilations,
                                           groups,
                                           auto_tune=False,
                                           tensor_core='auto')

        # time_end = datetime.datetime.now()
        # logging.log(logging.INFO, f"TIMER: <{node.operator},{node.node_id}> {time_st} -> {time_end}")
        # logging.log(logging.INFO, f"CONV sent -->  {y[-1]} CONV")

    return fn
Example #3
0
def conv_cpu(node: Node, alloc_map, config: Config) -> Callable[[], None]:
    """
        Function:
            Y = X CONV W (Using padding, stride and dilaton attribute
    """
    x_io = node.inputs["X"]
    w_io = node.inputs["W"]
    b_io = node.get_input("B")
    y_io = node.outputs["Y"]

    x = x_io.get_data(alloc_map)
    w = w_io.get_data(alloc_map)
    b = b_io.get_data(alloc_map)
    y = y_io.get_data(alloc_map)

    # Assuming same stride in all directions
    stride = node.get_attr("strides", [1])[0]
    # Assuming same padding in all directions
    padding = node.get_attr("pads", [0])[0]
    dilations = node.get_attr(
        "dilations", [1])[0]  # Assuming same padding in all directions
    groups = node.get_attr("group", 1)

    def fn():
        np.copyto(
            y,
            (chainer.functions.convolution_2d(
                x,
                w,
                b=b,
                stride=stride,
                pad=padding,
                dilate=dilations,
                groups=groups,
            )).array,
        )

    return fn
Example #4
0
def clip_v11_cpu(node: Node, alloc_map, config: Config) -> Callable[[], None]:

    input_io = node.inputs["input"]
    min_io = node.get_input("min")
    max_io = node.get_input("max")

    output_io = node.outputs["output"]

    inp = input_io.get_data(alloc_map)
    min_data = min_io.get_data(alloc_map)
    if min_data is None:
        min_data = [-np.inf]
    max_data = max_io.get_data(alloc_map)
    if max_data is None:
        max_data = [np.inf]

    output = output_io.get_data(alloc_map)

    def fn():
        np.copyto(output,
                  chainer.functions.clip(inp, min_data[0], max_data[0]).array)

    return fn