Skip to content

Instantly share code, notes, and snippets.

@surya00060
Last active February 23, 2022 17:28
Show Gist options
  • Select an option

  • Save surya00060/a374db0862b3d3581a68565961e12079 to your computer and use it in GitHub Desktop.

Select an option

Save surya00060/a374db0862b3d3581a68565961e12079 to your computer and use it in GitHub Desktop.
import time
import torch
print(f"Number of Threads = {torch.get_num_threads()}")
#######
## I have added parameters which can be controllable.
## But on setting them to the minimum we won't be able to notice any difference under different number of threads
numChannels = 32 ## Can be reducible till 1
inputSize = 14 ## Can be reducible till 3
kernelSize = 3 ## Can be reducible till 1
x = torch.rand([1,numChannels,inputSize,inputSize])
model = torch.nn.Conv2d(numChannels, numChannels, kernelSize)
### Just measure time.
start = time.time()
#for i in range(5): Measuring only once for simulation
model(x)
end = time.time()
print(f"Execution Time:{(end-start)*1000} ms")
#### Instructions to execute this program
'''Open the terminal and run
IF package was compiled with OpenMP, otherwise this won't exactly work.
To Check if the package is pre-compiled with OpenMP,
1. In terminal type "python3"
2. >>> import torch
3. >>> print(torch.__config__.show())
OMP_NUM_THREADS=1 python3 demo.py
OMP_NUM_THREADS=2 python3 demo.py
OMP_NUM_THREADS=4 python3 demo.py and so on..
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment