码迷,mamicode.com
首页 > Web开发 > 详细

mxnet-等待后台任务完成,后台完成自动并行化

时间:2018-11-14 19:47:46      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:com   load   engine   until   finish   rip   def   任务   one   

n = 10 a = mx.nd.ones((1000,1000)) b = mx.nd.ones((6000,6000), gpu_device) tic = time.time() c = do(a, n) wait(c) print(‘Time to finish the CPU workload: %f sec‘ % (time.time() - tic)) d = do(b, n) wait(d) print(‘Time to finish both CPU/GPU workloads: %f sec‘ % (time.time() - tic))
# -*- coding: utf-8 -*-
"""
Spyder Editor

This is a temporary script file.
"""
import mxnet as mx
import numpy as np

import pickle as pkl
import time
def do(x, n):
    """push computation into the backend engine"""
    return [mx.nd.dot(x,x) for i in range(n)]
def wait(x):
    """wait until all results are available"""
    for y in x:
        y.wait_to_read()

tic = time.time()
a = mx.nd.ones((1000,1000))
b = do(a, 50)
print(‘time for all computations are pushed into the backend engine:\n %f sec‘ % (time.time() - tic))
wait(b)
print(‘time for all computations are finished:\n %f sec‘ % (time.time() - tic))

mxnet-等待后台任务完成,后台完成自动并行化

标签:com   load   engine   until   finish   rip   def   任务   one   

原文地址:http://blog.51cto.com/13959448/2316997

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!