Esempio n. 1
0
def test_stack():

    fname = os.path.join(this_file_dir,
                         'runtime_analysis/{}/general/stack.txt'.format(DIM))
    if os.path.exists(fname):
        os.remove(fname)
    for lib, call in [
        (l, c) for l, c in helpers.calls
            if c not in [helpers.tf_graph_call, helpers.mx_graph_call]
    ]:

        time_lib = LIB_DICT[lib]

        append_to_file(fname, '{}'.format(lib))

        x0 = ivy_gen.tensor([random.uniform(0, 1) for _ in range(DIM)], f=lib)
        x1 = ivy_gen.tensor([random.uniform(0, 1) for _ in range(DIM)], f=lib)

        ivy_gen.stack([x0, x1], f=lib)
        ivy_gen_w_time.stack([x0, x1], f=time_lib)
        TIMES_DICT.clear()

        for _ in range(100):

            log_time(fname, 'tb0')
            ivy_gen_w_time.stack([x0, x1], 0, f=time_lib)
            log_time(fname, 'tb4', time_at_start=True)

            log_time(fname, 'tt0')
            ivy_gen.stack([x0, x1], 0, f=lib)
            log_time(fname, 'tt1', time_at_start=True)

        write_times()

    append_to_file(fname, 'end of analysis')
Esempio n. 2
0
def test_linear():

    fname = os.path.join(this_file_dir,
                         'runtime_analysis/{}/layers/linear.txt'.format(DIM))
    if os.path.exists(fname):
        os.remove(fname)
    for lib, call in [
        (l, c) for l, c in helpers.calls
            if c not in [helpers.tf_graph_call, helpers.mx_graph_call]
    ]:

        time_lib = LIB_DICT[lib]

        append_to_file(fname, '{}'.format(lib))

        x0 = ivy_gen.tensor([[random.uniform(0, 1) for _ in range(DIM)]],
                            f=lib)
        weight = ivy_gen.tensor([[random.uniform(0, 1) for _ in range(DIM)],
                                 [random.uniform(0, 1) for _ in range(DIM)]],
                                f=lib)
        bias = ivy_gen.tensor(
            [random.uniform(0, 1), random.uniform(0, 1)], f=lib)

        ivy_layers.linear(x0, weight, bias, num_hidden=2, f=lib)
        ivy_layers_w_time.linear(x0, weight, bias, num_hidden=2, f=time_lib)
        TIMES_DICT.clear()

        for _ in range(100):

            log_time(fname, 'tb0')
            ivy_layers_w_time.linear(x0,
                                     weight,
                                     bias,
                                     num_hidden=2,
                                     f=time_lib)
            log_time(fname, 'tb4', time_at_start=True)

            log_time(fname, 'tt0')
            ivy_layers.linear(x0, weight, bias, num_hidden=2, f=lib)
            log_time(fname, 'tt1', time_at_start=True)

        write_times()

    append_to_file(fname, 'end of analysis')
Esempio n. 3
0
def test_gradient_descent_update():

    fname = os.path.join(
        this_file_dir,
        'runtime_analysis/{}/gradients/gradient_descent_update.txt'.format(
            DIM))
    if os.path.exists(fname):
        os.remove(fname)
    for lib, call in [
        (l, c) for l, c in helpers.calls
            if c not in [helpers.tf_graph_call, helpers.mx_graph_call]
    ]:

        time_lib = LIB_DICT[lib]

        append_to_file(fname, '{}'.format(lib))

        x0 = ivy_gen.tensor([random.uniform(0, 1) for _ in range(DIM)], f=lib)
        x1 = ivy_gen.tensor([random.uniform(0, 1) for _ in range(DIM)], f=lib)
        ws = [ivy_grad.variable(x0)]
        dcdws = [x1]

        ivy_grad.gradient_descent_update(ws, dcdws, 0.1, f=lib)
        ivy_grad_w_time.gradient_descent_update(ws, dcdws, 0.1, f=time_lib)
        TIMES_DICT.clear()

        for _ in range(100):

            log_time(fname, 'tb0')
            ivy_grad_w_time.gradient_descent_update(ws, dcdws, 0.1, f=time_lib)
            log_time(fname, 'tb4', time_at_start=True)

            log_time(fname, 'tt0')
            ivy_grad.gradient_descent_update(ws, dcdws, 0.1, f=lib)
            log_time(fname, 'tt1', time_at_start=True)

        write_times()

    append_to_file(fname, 'end of analysis')
Esempio n. 4
0
def test_vector_to_skew_symmetric_matrix():

    fname = os.path.join(
        this_file_dir,
        'runtime_analysis/{}/linalg/vector_to_skew_symmetric_matrix.txt'.
        format(DIM))
    if os.path.exists(fname):
        os.remove(fname)
    for lib, call in [
        (l, c) for l, c in helpers.calls
            if c not in [helpers.tf_graph_call, helpers.mx_graph_call]
    ]:

        time_lib = LIB_DICT[lib]

        append_to_file(fname, '{}'.format(lib))

        x0 = ivy_gen.tensor([[
            random.uniform(0, 1),
            random.uniform(0, 1),
            random.uniform(0, 1)
        ] for _ in range(DIM)],
                            f=lib)

        ivy_linalg.vector_to_skew_symmetric_matrix(x0, f=lib)
        ivy_linalg_w_time.vector_to_skew_symmetric_matrix(x0, f=time_lib)
        TIMES_DICT.clear()

        for _ in range(100):

            log_time(fname, 'tb0')
            ivy_linalg_w_time.vector_to_skew_symmetric_matrix(x0, f=time_lib)
            log_time(fname, 'tb4', time_at_start=True)

            log_time(fname, 'tt0')
            ivy_linalg.vector_to_skew_symmetric_matrix(x0, f=lib)
            log_time(fname, 'tt1', time_at_start=True)

        write_times()

    append_to_file(fname, 'end of analysis')
Esempio n. 5
0
def test_compile_fn():

    fname = os.path.join(
        this_file_dir,
        'runtime_analysis/{}/general/compile_fn.txt'.format(DIM))
    if os.path.exists(fname):
        os.remove(fname)
    for lib, call in [
        (l, c) for l, c in helpers.calls
            if c not in [helpers.tf_graph_call, helpers.mx_graph_call]
    ]:

        time_lib = LIB_DICT[lib]

        if call is helpers.mx_call:
            continue

        append_to_file(fname, '{}'.format(lib))

        some_fn = lambda x: x**2
        x0 = ivy_gen.tensor([random.uniform(0, 1) for _ in range(DIM)], f=lib)

        ivy_gen.dtype(x0, f=lib)
        ivy_gen_w_time.dtype(x0, f=time_lib)
        TIMES_DICT.clear()

        for _ in range(100):

            log_time(fname, 'tb0')
            ivy_gen_w_time.compile_fn(some_fn, x0, f=time_lib)
            log_time(fname, 'tb4', time_at_start=True)

            log_time(fname, 'tt0')
            ivy_gen.compile_fn(some_fn, x0, f=lib)
            log_time(fname, 'tt1', time_at_start=True)

        write_times()

    append_to_file(fname, 'end of analysis')
Esempio n. 6
0
def test_one_hot():

    fname = os.path.join(this_file_dir,
                         'runtime_analysis/{}/general/one_hot.txt'.format(DIM))
    if os.path.exists(fname):
        os.remove(fname)
    for lib, call in [
        (l, c) for l, c in helpers.calls
            if c not in [helpers.tf_graph_call, helpers.mx_graph_call]
    ]:

        time_lib = LIB_DICT[lib]

        append_to_file(fname, '{}'.format(lib))

        x0 = ivy_gen.cast(
            ivy_gen.tensor([
                random.randint(0,
                               int(DIM**0.5) - 1) for _ in range(int(DIM**0.5))
            ],
                           f=lib), 'int64')

        ivy_gen.one_hot(x0, int(DIM**0.5), f=lib)
        ivy_gen_w_time.one_hot(x0, int(DIM**0.5), f=time_lib)
        TIMES_DICT.clear()

        for _ in range(100):

            log_time(fname, 'tb0')
            ivy_gen_w_time.one_hot(x0, int(DIM**0.5), f=time_lib)
            log_time(fname, 'tb4', time_at_start=True)

            log_time(fname, 'tt0')
            ivy_gen.one_hot(x0, int(DIM**0.5), f=lib)
            log_time(fname, 'tt1', time_at_start=True)

        write_times()

    append_to_file(fname, 'end of analysis')
Esempio n. 7
0
def test_execute_with_gradients():

    fname = os.path.join(
        this_file_dir,
        'runtime_analysis/{}/gradients/execute_with_gradients.txt'.format(DIM))
    if os.path.exists(fname):
        os.remove(fname)
    for lib, call in [
        (l, c) for l, c in helpers.calls
            if c not in [helpers.tf_graph_call, helpers.mx_graph_call]
    ]:

        time_lib = LIB_DICT[lib]

        append_to_file(fname, '{}'.format(lib))

        x0 = ivy_gen.tensor([random.uniform(0, 1) for _ in range(DIM)], f=lib)
        func = lambda xs_in: (xs_in[0] * xs_in[0])[0]
        xs = [ivy_grad.variable(x0)]

        ivy_grad.execute_with_gradients(func, xs, f=lib)
        ivy_grad_w_time.execute_with_gradients(func, xs, f=time_lib)
        TIMES_DICT.clear()

        for _ in range(100):

            log_time(fname, 'tb0')
            ivy_grad_w_time.execute_with_gradients(func, xs, f=time_lib)
            log_time(fname, 'tb4', time_at_start=True)

            log_time(fname, 'tt0')
            ivy_grad.execute_with_gradients(func, xs, f=lib)
            log_time(fname, 'tt1', time_at_start=True)

        write_times()

    append_to_file(fname, 'end of analysis')
Esempio n. 8
0
def test_conv3d_transpose():

    fname = os.path.join(
        this_file_dir,
        'runtime_analysis/{}/layers/conv3d_transpose.txt'.format(DIM))
    if os.path.exists(fname):
        os.remove(fname)
    for lib, call in [
        (l, c) for l, c in helpers.calls
            if c not in [helpers.tf_graph_call, helpers.mx_graph_call]
    ]:

        time_lib = LIB_DICT[lib]

        if call in [
                helpers.np_call, helpers.jnp_call, helpers.mx_call,
                helpers.mx_graph_call
        ]:
            # numpy and jax do not yet support 3d convolutions, and mxnet only supports with CUDNN
            continue

        x0 = ivy_gen.tensor(
            [[[[[random.uniform(0, 1)], [random.uniform(0, 1)]],
               [[random.uniform(0, 1)], [random.uniform(0, 1)]]],
              [[[random.uniform(0, 1)], [random.uniform(0, 1)]],
               [[random.uniform(0, 1)], [random.uniform(0, 1)]]]]
             for _ in range(DIM)],
            f=lib)
        if call in [helpers.tf_call, helpers.tf_graph_call]:
            data_format = "NDHWC"
        else:
            x0 = ivy_gen.reshape(x0, (DIM, 1, 2, 2, 2))
            data_format = "NCDHW"

        append_to_file(fname, '{}'.format(lib))

        filters = ivy_gen.tensor([[[[[0.]], [[0.]]], [[[1.]], [[1.]]]],
                                  [[[[1.]], [[1.]]], [[[0.]], [[0.]]]]],
                                 f=lib)
        ivy_layers.conv3d_transpose(x0,
                                    filters,
                                    1,
                                    "SAME", (DIM, 2, 2, 2, 1),
                                    data_format,
                                    filter_shape=[2, 2, 2],
                                    num_filters=1,
                                    f=lib)
        ivy_layers_w_time.conv3d_transpose(x0,
                                           filters,
                                           1,
                                           "SAME", (DIM, 2, 2, 2, 1),
                                           data_format,
                                           filter_shape=[2, 2, 2],
                                           num_filters=1,
                                           f=time_lib)
        TIMES_DICT.clear()

        for _ in range(100):

            log_time(fname, 'tb0')
            ivy_layers_w_time.conv3d_transpose(x0,
                                               filters,
                                               1,
                                               "SAME", (DIM, 2, 2, 2, 1),
                                               data_format,
                                               filter_shape=[2, 2, 2],
                                               num_filters=1,
                                               f=time_lib)
            log_time(fname, 'tb4', time_at_start=True)

            log_time(fname, 'tt0')
            ivy_layers.conv3d_transpose(x0,
                                        filters,
                                        1,
                                        "SAME", (DIM, 2, 2, 2, 1),
                                        data_format,
                                        filter_shape=[2, 2, 2],
                                        num_filters=1,
                                        f=lib)
            log_time(fname, 'tt1', time_at_start=True)

        write_times()

    append_to_file(fname, 'end of analysis')