Ejemplo n.º 1
0
def test_profile_create_domain_dept():
    profiler.profiler_set_config(mode='symbolic', filename='temp.json')
    profiler.set_state('run')
    domain = profiler.Domain(name='PythonDomain')
    print("Domain created: {}".format(str(domain)))
    profiler.dump_profile()
    profiler.set_state('stop')
Ejemplo n.º 2
0
def test_profile_create_domain_dept():
    profiler.profiler_set_config(mode='symbolic', filename='temp.json')
    profiler.set_state('run')
    domain = profiler.Domain(name='PythonDomain')
    print("Domain created: {}".format(str(domain)))
    profiler.dump_profile()
    profiler.set_state('stop')
def test_profiler():
    profile_filename = "test_profile.json"
    iter_num = 5
    begin_profiling_iter = 2
    end_profiling_iter = 4

    profiler.profiler_set_config(mode='symbolic', filename=profile_filename)
    print('profile file save to {0}'.format(profile_filename))

    A = mx.sym.Variable('A')
    B = mx.sym.Variable('B')
    C = mx.symbol.dot(A, B)

    executor = C.simple_bind(mx.cpu(1), 'write', A=(4096, 4096), B=(4096, 4096))

    a = mx.random.uniform(-1.0, 1.0, shape=(4096, 4096))
    b = mx.random.uniform(-1.0, 1.0, shape=(4096, 4096))

    a.copyto(executor.arg_dict['A'])
    b.copyto(executor.arg_dict['B'])

    print("execution begin")
    for i in range(iter_num):
        print("Iteration {}/{}".format(i + 1, iter_num))
        if i == begin_profiling_iter:
            t0 = time.clock()
            profiler.profiler_set_state('run')
        if i == end_profiling_iter:
            t1 = time.clock()
            profiler.profiler_set_state('stop')
        executor.forward()
        c = executor.outputs[0]
        c.wait_to_read()
    print("execution end")
    duration = t1 - t0
    print('duration: {0}s'.format(duration))
    print('          {0}ms/operator'.format(duration*1000/iter_num))
    profiler.dump_profile()
Ejemplo n.º 4
0
 def switch_profiler(param):
     if param.epoch == 0 and param.nbatch == 100:
         profiler.profiler_set_state('run')
     if param.epoch == 0 and param.nbatch == 110:
         profiler.profiler_set_state('stop')
         profiler.dump_profile()
Ejemplo n.º 5
0
    profiler.profiler_set_state('run')
    # real run
    for i in range(iterations):
        mod.forward(batch, is_train=True)
        mod.backward()
        mod.update()
        for output in mod.get_outputs(merge_multi_context=False)[0]:
            output.wait_to_read()
    profiler.profiler_set_state('stop')

    t1 = time.clock()
    return (t1 - t0)*1000.0 / iterations


def executor(num_iteration):
    sym, provide_data, provide_label = get_symbol()
    ctx = [mx.cpu(0)]
    mod = get_module(ctx, sym, provide_data, provide_label, batch_size=128)
    return benchmark(mod, iterations=args.iter_num)


args = parse_args()

if __name__ == '__main__':
    mx.profiler.profiler_set_config(mode='symbolic', filename=args.profile_filename)
    print('profile file save to {0}'.format(args.profile_filename))
    print('executor num_iteration: {0}'.format(args.iter_num))
    executor_time = executor(args.iter_num)
    print("executor {0} ms / iteration".format(executor_time))
    profiler.dump_profile()