diff --git a/cifar10/cifar10_run.py b/cifar10/cifar10_run.py new file mode 100644 index 0000000..d5c049a --- /dev/null +++ b/cifar10/cifar10_run.py @@ -0,0 +1,129 @@ +import time + + + + +def run(point): + start = time.time() + try: + batch_size = point['batch_size'] + image_size = point['image_size'] + conv1_in_chan = point['conv1_in_chan'] + conv1_out_chan = point['conv1_out_chan'] + conv1_kern = point['conv1_kern'] + pool_size = point['pool_size'] + conv2_out_chan = point['conv2_out_chan'] + conv2_kern = point['conv2_kern'] + fc1_out = point['fc1_out'] + fc2_out = point['fc2_out'] + fc3_out = point['fc3_out'] + + omp_num_threads = point['omp_num_threads'] + + import os + os.environ['OMP_NUM_THREADS'] = str(omp_num_threads) + os.environ['MKL_NUM_THREADS'] = str(omp_num_threads) + os.environ['KMP_HW_SUBSET'] = '1s,%sc,2t' % str(omp_num_threads) + os.environ['KMP_AFFINITY'] = 'granularity=fine,verbose,compact,1,0' + os.environ['KMP_BLOCKTIME'] = str(0) + #os.environ['MKLDNN_VERBOSE'] = str(1) + import torch + + print('torch version: ',torch.__version__,' torch file: ',torch.__file__) + + class Net(torch.nn.Module): + def __init__(self, batch_size, + image_size, + conv1_in_chan,conv1_out_chan,conv1_kern, + pool_size, + conv2_out_chan,conv2_kern, + fc1_out, + fc2_out, + fc3_out, + ): + super(Net, self).__init__() + self.flop = 0 + self.conv1 = torch.nn.Conv2d(conv1_in_chan, conv1_out_chan, conv1_kern) + self.flop += conv1_kern**2 * conv1_in_chan * conv1_out_chan * image_size**2 * batch_size + print(self.flop) + self.pool = torch.nn.MaxPool2d(pool_size, pool_size) + self.flop += image_size**2 * conv1_out_chan * batch_size + self.conv2 = torch.nn.Conv2d(conv1_out_chan,conv2_out_chan,conv2_kern) + self.flop += conv2_kern**2 * conv1_out_chan * conv2_out_chan * int(image_size/pool_size)**2 * batch_size + print(self.flop) + self.view_size = conv2_out_chan * conv2_kern * conv2_kern + self.fc1 = torch.nn.Linear(conv2_out_chan * conv2_kern * conv2_kern, fc1_out) + self.flop += (2*self.view_size - 1) * fc1_out * batch_size + self.fc2 = torch.nn.Linear(fc1_out, fc2_out) + self.flop += (2*fc1_out - 1) * fc2_out * batch_size + self.fc3 = torch.nn.Linear(fc2_out, fc3_out) + self.flop += (2*fc2_out - 1) * fc3_out * batch_size + + def forward(self, x): + x = self.pool(torch.nn.functional.relu(self.conv1(x))) + x = self.pool(torch.nn.functional.relu(self.conv2(x))) + x = x.view(-1,self.view_size) + x = torch.nn.functional.relu(self.fc1(x)) + x = torch.nn.functional.relu(self.fc2(x)) + x = self.fc3(x) + return x + + + + inputs = torch.arange(batch_size * image_size**2 * conv1_in_chan,dtype=torch.float).view((batch_size,conv1_in_chan,image_size,image_size)) + net = Net(batch_size, + image_size, + conv1_in_chan,conv1_out_chan,conv1_kern, + pool_size, + conv2_out_chan,conv2_kern, + fc1_out, + fc2_out, + fc3_out) + outputs = net(inputs) + + + total_flop = net.flop + + runs = 5 + tot_time = 0. + tt = time.time() + for _ in range(runs): + outputs = net(inputs) + tot_time += time.time() - tt + tt = time.time() + + ave_time = tot_time / runs + + print('total_flop = ',total_flop,'ave_time = ',ave_time) + + ave_flops = total_flop / ave_time + runtime = time.time() - start + print('runtime=',runtime,'ave_flops=',ave_flops) + + return ave_flops + except Exception as e: + import traceback + print('received exception: ',str(e),'for point: ',point) + print(traceback.print_exc()) + print('runtime=',time.time() - start) + return 0. + + +if __name__ == '__main__': + point = { + 'batch_size': 10, + 'image_size': 32, + 'conv1_in_chan':3, + 'conv1_out_chan':6, + 'conv1_kern':5, + 'pool_size':2, + 'conv2_out_chan':16, + 'conv2_kern':5, + 'fc1_out':120, + 'fc2_out':84, + 'fc3_out': 10, + 'omp_num_threads':64, + } + + print('flops for this setting =',run(point)) + diff --git a/cifar10/problem.py b/cifar10/problem.py new file mode 100644 index 0000000..dee804a --- /dev/null +++ b/cifar10/problem.py @@ -0,0 +1,22 @@ +from deephyper.benchmark import HpProblem + +Problem = HpProblem() +Problem.add_dim('batch_size',(1,32)) +Problem.add_dim('image_size',[32]) +Problem.add_dim('conv1_in_chan',[3]) +Problem.add_dim('conv1_out_chan',(3,64)) +Problem.add_dim('conv1_kern',(3,8)) +Problem.add_dim('pool_size',[2]) +Problem.add_dim('conv2_out_chan',(3,64)) +Problem.add_dim('conv2_kern',(3,8)) +Problem.add_dim('fc1_out',(64,256)) +Problem.add_dim('fc2_out',(32,128)) +Problem.add_dim('fc3_out',[10]) +Problem.add_dim('omp_num_threads',[64]) + +Problem.add_starting_point(batch_size=10,image_size=32,conv1_in_chan=3,conv1_out_chan=16,conv1_kern=5, + pool_size=2,conv2_out_chan=16,conv2_kern=5,fc1_out=128,fc2_out=84, + fc3_out=10,omp_num_threads=64) + +if __name__ == '__main__': + print(Problem) diff --git a/conv1d/conv1d_run.py b/conv1d/conv1d_run.py new file mode 100644 index 0000000..6057b8b --- /dev/null +++ b/conv1d/conv1d_run.py @@ -0,0 +1,68 @@ +import time + +def run(point): + start = time.time() + try: + batch_size = point['batch_size'] + image_size = point['image_size'] + in_channels = point['in_channels'] + out_channels = point['out_channels'] + kernel_size = point['kernel_size'] + omp_num_threads = point['omp_num_threads'] + + import os + os.environ['OMP_NUM_THREADS'] = str(omp_num_threads) + os.environ['MKL_NUM_THREADS'] = str(omp_num_threads) + os.environ['KMP_HW_SUBSET'] = '1s,%sc,2t' % str(omp_num_threads) + os.environ['KMP_AFFINITY'] = 'granularity=fine,verbose,compact,1,0' + os.environ['KMP_BLOCKTIME'] = str(0) + #os.environ['MKLDNN_VERBOSE'] = str(1) + import torch + + print('torch version: ',torch.__version__,' torch file: ',torch.__file__) + + + inputs = torch.arange(batch_size * image_size * in_channels,dtype=torch.float).view((batch_size,in_channels,image_size)) + + layer = torch.nn.Conv1d(in_channels,out_channels,kernel_size,stride=1,padding=1) + outputs = layer(inputs) + + total_flop = kernel_size * in_channels * out_channels * outputs.shape[-1] * batch_size + + runs = 5 + tot_time = 0. + tt = time.time() + for _ in range(runs): + outputs = layer(inputs) + tot_time += time.time() - tt + tt = time.time() + + ave_time = tot_time / runs + + print('total_flop = ',total_flop,'ave_time = ',ave_time) + + ave_flops = total_flop / ave_time + runtime = time.time() - start + print('runtime=',runtime,'ave_flops=',ave_flops) + + return ave_flops + except Exception as e: + import traceback + print('received exception: ',str(e)) + print(traceback.print_exc()) + print('runtime=',time.time() - start) + return 0. + + +if __name__ == '__main__': + point = { + 'batch_size': 10, + 'image_size': 512, + 'in_channels': 3, + 'out_channels': 64, + 'kernel_size': 4, + 'omp_num_threads':64, + } + + print('flops for this setting =',run(point)) + diff --git a/conv1d/problem.py b/conv1d/problem.py new file mode 100644 index 0000000..801e0d6 --- /dev/null +++ b/conv1d/problem.py @@ -0,0 +1,14 @@ +from deephyper.benchmark import HpProblem + +Problem = HpProblem() +Problem.add_dim('batch_size',(1,4096)) +Problem.add_dim('image_size',(128,8192)) +Problem.add_dim('in_channels',(2,1024)) +Problem.add_dim('out_channels',(2,1024)) +Problem.add_dim('kernel_size',(2,64)) +Problem.add_dim('omp_num_threads',[64]) + +Problem.add_starting_point(batch_size=10,image_size=128,in_channels=2,out_channels=2,kernel_size=2,omp_num_threads=64) + +if __name__ == '__main__': + print(Problem) diff --git a/conv3d/conv3d_run.py b/conv3d/conv3d_run.py new file mode 100644 index 0000000..0fef6de --- /dev/null +++ b/conv3d/conv3d_run.py @@ -0,0 +1,68 @@ +import time + +def run(point): + start = time.time() + try: + batch_size = point['batch_size'] + image_size = point['image_size'] + in_channels = point['in_channels'] + out_channels = point['out_channels'] + kernel_size = point['kernel_size'] + omp_num_threads = point['omp_num_threads'] + + import os + os.environ['OMP_NUM_THREADS'] = str(omp_num_threads) + os.environ['MKL_NUM_THREADS'] = str(omp_num_threads) + os.environ['KMP_HW_SUBSET'] = '1s,%sc,2t' % str(omp_num_threads) + os.environ['KMP_AFFINITY'] = 'granularity=fine,verbose,compact,1,0' + os.environ['KMP_BLOCKTIME'] = str(0) + #os.environ['MKLDNN_VERBOSE'] = str(1) + import torch + + print('torch version: ',torch.__version__,' torch file: ',torch.__file__) + + + inputs = torch.arange(batch_size * image_size**3 * in_channels,dtype=torch.float).view((batch_size,in_channels,image_size,image_size,image_size)) + + layer = torch.nn.Conv3d(in_channels,out_channels,kernel_size,stride=1,padding=1) + outputs = layer(inputs) + + total_flop = kernel_size**3 * in_channels * out_channels * outputs.shape[-1] * outputs.shape[-2] * outputs.shape[-3] * batch_size + + runs = 5 + tot_time = 0. + tt = time.time() + for _ in range(runs): + outputs = layer(inputs) + tot_time += time.time() - tt + tt = time.time() + + ave_time = tot_time / runs + + print('total_flop = ',total_flop,'ave_time = ',ave_time) + + ave_flops = total_flop / ave_time + runtime = time.time() - start + print('runtime=',runtime,'ave_flops=',ave_flops) + + return ave_flops + except Exception as e: + import traceback + print('received exception: ',str(e),'for point: ',point) + print(traceback.print_exc()) + print('runtime=',time.time() - start) + return 0. + + +if __name__ == '__main__': + point = { + 'batch_size': 10, + 'image_size': 128, + 'in_channels': 3, + 'out_channels': 3, + 'kernel_size': 4, + 'omp_num_threads':64, + } + + print('flops for this setting =',run(point)) + diff --git a/conv3d/problem.py b/conv3d/problem.py new file mode 100644 index 0000000..bfefd15 --- /dev/null +++ b/conv3d/problem.py @@ -0,0 +1,14 @@ +from deephyper.benchmark import HpProblem + +Problem = HpProblem() +Problem.add_dim('batch_size',(1,32)) +Problem.add_dim('image_size',(16,128)) +Problem.add_dim('in_channels',(2,64)) +Problem.add_dim('out_channels',(2,64)) +Problem.add_dim('kernel_size',(2,10)) +Problem.add_dim('omp_num_threads',[64]) + +Problem.add_starting_point(batch_size=10,image_size=28,in_channels=2,out_channels=2,kernel_size=2,omp_num_threads=64) + +if __name__ == '__main__': + print(Problem) diff --git a/model_run.py b/model_run.py index 5f65b02..beba33d 100644 --- a/model_run.py +++ b/model_run.py @@ -64,11 +64,11 @@ def run(point): if __name__ == '__main__': point = { 'batch_size': 10, - 'height': 128, - 'width': 128, + 'height': 32, + 'width': 32, 'in_channels': 3, - 'out_channels': 32, - 'kernel_size': 4, + 'out_channels': 6, + 'kernel_size': 5, 'omp_num_threads':64, } diff --git a/square_images/problem.py b/square_images/problem.py index 63a63cf..d120c71 100644 --- a/square_images/problem.py +++ b/square_images/problem.py @@ -1,7 +1,7 @@ from deephyper.benchmark import HpProblem Problem = HpProblem() -Problem.add_dim('batch_size',(1,512)) +Problem.add_dim('batch_size',(1,1024)) Problem.add_dim('image_size',(128,1024)) Problem.add_dim('in_channels',(2,64)) Problem.add_dim('out_channels',(2,64))