Skip to content

Instantly share code, notes, and snippets.

@KellenSunderland
Created February 2, 2018 14:19
Show Gist options
  • Save KellenSunderland/b325a5ba208001f0e4877464fefde155 to your computer and use it in GitHub Desktop.
Save KellenSunderland/b325a5ba208001f0e4877464fefde155 to your computer and use it in GitHub Desktop.
Autotune repro.
import mxnet as mx
from collections import namedtuple
import numpy as np
import cv2
Batch = namedtuple('Batch', ['data'])
from scipy.misc import imread, imresize
import time
import os
from mxnet.gluon.model_zoo import vision
for auto_tune in ("0","1"):
os.environ["MXNET_CUDNN_AUTOTUNE_DEFAULT"]=auto_tune
resnet50 = vision.resnet50_v1(pretrained=True,ctx=mx.gpu())
img = imread("/home/ubuntu/repos/mxnet-ssd/data/demo/dog.jpg")
img = imresize(img,[512,512])
img = np.swapaxes(img, 0, 2)
img = np.swapaxes(img, 1, 2)
img = mx.nd.array(img[np.newaxis, :],ctx=mx.gpu())
warmup=resnet50.forward(img).asnumpy()
start = time.time()
N = 50
for i in range(N):
a = resnet50.forward(img).asnumpy()
end = time.time()
dt = end-start
print("with autotune = " + str(os.environ["MXNET_CUDNN_AUTOTUNE_DEFAULT"]) + ", took " + str(dt) + " for " + str(N) + " runs, avg per image = " + str(dt/float(N)))
#with autotune = 0, took 2.5871667861938477 for 50 runs, avg per image = 0.05174333572387695
#with autotune = 1, took 0.810204029083252 for 50 runs, avg per image = 0.016204080581665038
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment