예제 #1
0
def test_unstack():

    fname = os.path.join(this_file_dir,
                         'runtime_analysis/{}/general/unstack.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)

        ivy_gen.unstack(x0, 0, num_outputs=1, f=lib)
        ivy_gen_w_time.unstack(x0, 0, num_outputs=1, f=time_lib)
        TIMES_DICT.clear()

        for _ in range(100):

            log_time(fname, 'tb0')
            ivy_gen_w_time.unstack(x0, 0, num_outputs=1, f=time_lib)
            log_time(fname, 'tb4', time_at_start=True)

            log_time(fname, 'tt0')
            ivy_gen.unstack(x0, 0, num_outputs=1, f=lib)
            log_time(fname, 'tt1', time_at_start=True)

        write_times()

    append_to_file(fname, 'end of analysis')
예제 #2
0
def test_randint():

    fname = os.path.join(this_file_dir,
                         'runtime_analysis/{}/random/randint.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))

        ivy_rand.randint(0, 10, (DIM, ), f=lib)
        ivy_rand_w_time.randint(0, 10, (DIM, ), f=time_lib)
        TIMES_DICT.clear()

        for _ in range(100):

            log_time(fname, 'tb0')
            ivy_rand_w_time.randint(0, 10, (DIM, ), f=time_lib)
            log_time(fname, 'tb4', time_at_start=True)

            log_time(fname, 'tt0')
            ivy_rand.randint(0, 10, (DIM, ), f=lib)
            log_time(fname, 'tt1', time_at_start=True)

        write_times()

    append_to_file(fname, 'end of analysis')
예제 #3
0
def test_reduce_prod():

    fname = os.path.join(
        this_file_dir,
        'runtime_analysis/{}/reductions/reduce_prod.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.array([random.uniform(0, 1) for _ in range(DIM)], f=lib)

        ivy_red.reduce_prod(x0, f=lib)
        ivy_red_w_time.reduce_prod(x0, -1, f=time_lib)
        TIMES_DICT.clear()

        for _ in range(100):

            log_time(fname, 'tb0')
            ivy_red_w_time.reduce_prod(x0, -1, f=time_lib)
            log_time(fname, 'tb4', time_at_start=True)

            log_time(fname, 'tt0')
            ivy_red.reduce_prod(x0, -1, f=lib)
            log_time(fname, 'tt1', time_at_start=True)

        write_times()

    append_to_file(fname, 'end of analysis')
예제 #4
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.array([[random.uniform(0, 1) for _ in range(DIM)]], f=lib)
        weight = ivy_gen.array([[random.uniform(0, 1) for _ in range(DIM)],
                                [random.uniform(0, 1) for _ in range(DIM)]], f=lib)
        bias = ivy_gen.array([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')
예제 #5
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.array([[[[[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.array([[[[[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')
예제 #6
0
def test_where():

    fname = os.path.join(this_file_dir,
                         'runtime_analysis/{}/general/where.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.array([random.uniform(0, 1)
                            for _ in range(DIM)], f=lib) > 0
        x1 = ivy_gen.array([random.uniform(0, 1) for _ in range(DIM)], f=lib)
        x2 = ivy_gen.array([random.uniform(0, 1) for _ in range(DIM)], f=lib)

        ivy_gen.where(x0, x1, x2, condition_shape=[DIM], x_shape=[DIM], f=lib)
        ivy_gen_w_time.where(x0, x1, x2, f=time_lib)
        TIMES_DICT.clear()

        for _ in range(100):

            log_time(fname, 'tb0')
            ivy_gen_w_time.where(x0,
                                 x1,
                                 x2,
                                 condition_shape=[DIM],
                                 x_shape=[DIM],
                                 f=time_lib)
            log_time(fname, 'tb4', time_at_start=True)

            log_time(fname, 'tt0')
            ivy_gen.where(x0,
                          x1,
                          x2,
                          condition_shape=[DIM],
                          x_shape=[DIM],
                          f=lib)
            log_time(fname, 'tt1', time_at_start=True)

        write_times()

    append_to_file(fname, 'end of analysis')
예제 #7
0
def test_bilinear_resample():

    fname = os.path.join(
        this_file_dir,
        'runtime_analysis/{}/image/bilinear_resample.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.array([[[[random.uniform(0, 1)], [random.uniform(0, 1)]],
                             [[random.uniform(0, 1)], [random.uniform(0, 1)]]]
                            for _ in range(DIM)],
                           f=lib)
        x1 = ivy_gen.array([[
            [[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)

        ivy_image.bilinear_resample(x0, x1, f=lib)
        ivy_image_w_time.bilinear_resample(x0, x1, f=time_lib)
        TIMES_DICT.clear()

        for _ in range(100):

            log_time(fname, 'tb0')
            ivy_image_w_time.bilinear_resample(x0, x1, f=time_lib)
            log_time(fname, 'tb4', time_at_start=True)

            log_time(fname, 'tt0')
            ivy_image.bilinear_resample(x0, x1, f=lib)
            log_time(fname, 'tt1', time_at_start=True)

        write_times()

    append_to_file(fname, 'end of analysis')
예제 #8
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.array([[
            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')
예제 #9
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.array([random.uniform(0, 1) for _ in range(DIM)], f=lib)
        x1 = ivy_gen.array([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')
예제 #10
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.array([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')
예제 #11
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.array([
                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')
예제 #12
0
def test_gather_nd():

    fname = os.path.join(
        this_file_dir, 'runtime_analysis/{}/general/gather_nd.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.randint(0, DIM - 1)] for _ in range(DIM)],
                            f=lib)

        ivy_gen.gather_nd(x0, x1, indices_shape=[DIM, 1], f=lib)
        ivy_gen_w_time.gather_nd(x0, x1, indices_shape=[DIM, 1], f=time_lib)
        TIMES_DICT.clear()

        for _ in range(100):

            log_time(fname, 'tb0')
            ivy_gen_w_time.gather_nd(x0,
                                     x1,
                                     indices_shape=[DIM, 1],
                                     f=time_lib)
            log_time(fname, 'tb4', time_at_start=True)

            log_time(fname, 'tt0')
            ivy_gen.gather_nd(x0, x1, indices_shape=[DIM, 1], f=lib)
            log_time(fname, 'tt1', time_at_start=True)

        write_times()

    append_to_file(fname, 'end of analysis')
예제 #13
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.array([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')