You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2020/07/29 17:43:41 UTC

[GitHub] [incubator-mxnet] Hao-Tju commented on issue #14220: Qestion bout nd.waitall()

Hao-Tju commented on issue #14220:
URL: https://github.com/apache/incubator-mxnet/issues/14220#issuecomment-665633172


   > > You'll want to start 'time_loadimage' after the load and context change has finished: remember that MXNet operations are asynchronous. And it's better to use `wait_to_read()` instead of `waitall()` if you're wanting to time certain operations. And even better still you should check out the [MXNet Profiler](https://mxnet.incubator.apache.org/versions/master/tutorials/python/profiler.html) instead of writing your own profiling code.
   > > ```
   > > path = os.path.join(read_dir, '000204.jpg')
   > > tic = time.time()
   > > img_path = os.path.join(read_dir, path)
   > > x, img = data.transforms.presets.yolo.load_test(img_path, short=shape,max_size=shape)
   > > x = x.as_in_context(ctx)
   > > # block until data load and context switch have completed
   > > x.wait_to_read()
   > > time_loadimage = time.time() - tic
   > > 
   > > class_IDs, scores, bounding_boxs = net(x)
   > > # block until net has completed
   > > bounding_boxs.wait_to_read()
   > > all = time.time() - tic
   > > 
   > > print("every picture time cost:", (all - time_loadimage))
   > > print("FPS:", 1.0 / (all - time_loadimage))
   > > ```
   > 
   > > You'll want to start 'time_loadimage' after the load and context change has finished: remember that MXNet operations are asynchronous. And it's better to use `wait_to_read()` instead of `waitall()` if you're wanting to time certain operations. And even better still you should check out the [MXNet Profiler](https://mxnet.incubator.apache.org/versions/master/tutorials/python/profiler.html) instead of writing your own profiling code.
   > > ```
   > > path = os.path.join(read_dir, '000204.jpg')
   > > tic = time.time()
   > > img_path = os.path.join(read_dir, path)
   > > x, img = data.transforms.presets.yolo.load_test(img_path, short=shape,max_size=shape)
   > > x = x.as_in_context(ctx)
   > > # block until data load and context switch have completed
   > > x.wait_to_read()
   > > time_loadimage = time.time() - tic
   > > 
   > > class_IDs, scores, bounding_boxs = net(x)
   > > # block until net has completed
   > > bounding_boxs.wait_to_read()
   > > all = time.time() - tic
   > > 
   > > print("every picture time cost:", (all - time_loadimage))
   > > print("FPS:", 1.0 / (all - time_loadimage))
   > > ```
   > 
   > I followed your advice and tried to use **profile**. Still some confusion about some places.
   > 
   > **code:**
   > profiler.set_state('run')
   > tic = time.time()
   > 
   > x, img = data.transforms.presets.yolo.load_test(img_path, short=shape)
   > x = x.as_in_context(ctx)
   > class_IDs, scores, bounding_boxs = net(x)
   > 
   > bounding_boxs.wait_to_read()
   > all = time.time() - tic
   > profiler.set_state('stop')
   > print("time:", all)
   > print(profiler.dumps())`
   > 
   > **Result:**
   > 
   > 1. time: 5.4537177085876465
   > 2. [profile result:](https://github.com/Jessespace/MXNet-Learning/blob/master/profile.png)
   > 
   > I add all the **MXNET_C_API time** ,it is about the 5.4s which similar to 5.45s using **tic toc**. But I can't understand **Device Storage time** and **operator time** ,they take too long.
   
   I recommend that you should not use both the mxnet profiler and the time function at the same time. MXNet profiler will incur additional overhead and result in a wrong time result.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org