def testMySecondMul(self, bits, func): # do cuda arithmetic f_gpu = GF2nStub.GF2nStub("Cuda", bits) a_gpu = f_gpu() b_gpu = f_gpu() res_gpu = GF2nStub.run(func, a_gpu, b_gpu) rand_a = GF2nStub.getRandomNumber(bits, 42) rand_b = GF2nStub.getRandomNumber(bits, 84) print "a = ", rand_a print "b = ", rand_b f_ref = GF2n.GF2n(bits) a_ref = f_ref(rand_a) b_ref = f_ref(rand_b) res_ref = a_ref * b_ref print "res_ref = ", res_ref # compare results self.assertEqual(res_gpu, res_ref)
def testConvertStringToArrayToStringCPU( self, bits ): value = random.getrandbits(bits) res_array = GF2nStub.convertStringToArray(value, BITS_PER_CHUNK) res_string = GF2nStub.convertArrayToString(res_array, BITS_PER_CHUNK) self.assertEqual(value, res_string)
def testCopyHostToDevicePerformance(self, bits): # do cuda arithmetic f_gpu = GF2nStub.GF2nStub("Cuda", bits, -1) a_gpu = f_gpu() b_gpu = f_gpu() GF2nStub.run("measureKernelLaunchOverhead", a_gpu, b_gpu) metrics = GF2nStub.getMetrics("bn_a") PerformanceDataLogger().addPerfResult("copy host -> device", bits, "Cuda", metrics["copyToDevice_time"])
def testCopyDeviceToHostPerformance(self, bits): # do cuda arithmetic f_gpu = GF2nStub.GF2nStub("Cuda", bits, -1) a_gpu = f_gpu() b_gpu = f_gpu() res = GF2nStub.run("parAdd", a_gpu, b_gpu) res_value = res._value metrics = GF2nStub.getMetrics("res") PerformanceDataLogger().addPerfResult("copy device -> host", bits, "Cuda", metrics["copyToHost_time"])
def testConvertStringToArray( self, bits ): value = random.getrandbits(bits) res_cpu = GF2nStub.convertStringToArray(value, BITS_PER_CHUNK) res_ref = GF2n.convertStringToArray(value, BITS_PER_CHUNK) self.assertEqual(res_cpu, res_ref)
def testInvWithExpElementPerformance(self, bits, function, framework): runs = 1 f = GF2nStub.GF2nStub(framework, bits) a = f() if framework == "OpenSSL": res = GF2nStub.run("inverse", a, 0, 0, runs) else: res = GF2nStub.run(function, a, 0, 0, runs) times = GF2nStub.getEllapsedTime_ms() for time in times: PerformanceDataLogger().addPerfResult(function, bits, framework, time)
def testExpPerformance(self, bits, k, function, framework): runs = 10 rand_irred_poly = GF2nStub.getRandomNumber(bits + 1, 23) f = GF2nStub.GF2nStub(framework, bits, rand_irred_poly | 1) a = f() if framework == "OpenSSL": res = GF2nStub.run("exp", a, k, 0, runs) else: res = GF2nStub.run(function, a, k, 0, runs) times = GF2nStub.getEllapsedTime_ms() for time in times: PerformanceDataLogger().addPerfResult(function + ", k=" + str(k), bits, framework, time)
def testFrameworkOverhead(self, bits): # do cuda arithmetic f_gpu = GF2nStub.GF2nStub("Cuda", bits, -1) a_gpu = f_gpu() b_gpu = f_gpu() # measure test run with python framework and prng start_stub_run = timeit.default_timer() GF2nStub.run("measureKernelLaunchOverhead", a_gpu, b_gpu) PerformanceDataLogger().addPerfResult( "FrameworkOverhead - All", bits, "Cuda", timeit.default_timer() - start_stub_run) # measure test run without python framwork and without prng times = GF2nStub.getEllapsedTime_ms() PerformanceDataLogger().addPerfResult("FrameworkOverhead - OnlyFunc", bits, "Cuda", times[0])
def testOpenSSLExponentiation(self, bits, exp): # do cuda arithmetic f_gpu = GF2nStub.GF2nStub("OpenSSL", bits) a_gpu = f_gpu() res_gpu = GF2nStub.run("exp", a_gpu, exp) # calcualte reference rand_a = GF2nStub.getRandomNumber(bits, 42) f_ref = GF2n.GF2n(bits) a_ref = f_ref(rand_a) res_ref = a_ref**exp # compare results self.assertEqual(res_gpu, res_ref)
def testOpenSSLInverseElement(self, bits): # do cuda arithmetic f_gpu = GF2nStub.GF2nStub("OpenSSL", bits) a_gpu = f_gpu() res_gpu = GF2nStub.run("inverse", a_gpu, 0) # calcualte reference rand_a = GF2nStub.getRandomNumber(bits, 42) f_ref = GF2n.GF2n(bits) a_ref = f_ref(rand_a) res_ref = a_ref.inverse() # compare results self.assertEqual(res_gpu, res_ref)
def testCudaExponentiation(self, bits, k, func): # do cuda arithmetic f_gpu = GF2nStub.GF2nStub("Cuda", bits) a_gpu = f_gpu() res_gpu = GF2nStub.run(func, a_gpu, k) # calcualte reference rand_a = GF2nStub.getRandomNumber(bits, 42) f_ref = GF2n.GF2n(bits) a_ref = f_ref(rand_a) res_ref = a_ref**k # compare results self.assertEqual(res_gpu, res_ref)
def testAddPerformance(self, bits, framework, func): runs = 100 # do cuda arithmetic f_gpu = GF2nStub.GF2nStub(framework, bits, -1) a_gpu = f_gpu() b_gpu = f_gpu() flags = 0 if (func == "parAddOwnStream" or func == "parAdd2OwnStream" or func == "parAdd4OwnStream" or func == "parAdd8OwnStream" or func == 'parAddOwnStream1024Threads' or func == 'parAddOwnStream512Threads' or func == 'parAddOwnStream256Threads' or func == 'parAddOwnStream128Threads') \ and \ framework == "Cuda": flags = flags | 2 if framework == "Cuda": GF2nStub.run(func, a_gpu, b_gpu, flags, runs) else: GF2nStub.run("add", a_gpu, b_gpu, flags, runs) times = GF2nStub.getEllapsedTime_ms() for time in times: PerformanceDataLogger().addPerfResult( func, bits, framework, time)
def testOpenSSLMultiplication(self, bits): # do OpenSSL arithmetic f_cpu = GF2nStub.GF2nStub("OpenSSL", bits) a_cpu = f_cpu() b_cpu = f_cpu() res_cpu = a_cpu * b_cpu # calcualte reference rand_a = GF2nStub.getRandomNumber(bits, 42) rand_b = GF2nStub.getRandomNumber(bits, 84) f_ref = GF2n.GF2n(bits) a_ref = f_ref(rand_a) b_ref = f_ref(rand_b) res_ref = a_ref * b_ref # compare results self.assertEqual(res_cpu, res_ref)
def testCudaMultiplication(self, bits, func): # do cuda arithmetic f_gpu = GF2nStub.GF2nStub("Cuda", bits) a_gpu = f_gpu() b_gpu = f_gpu() res_gpu = GF2nStub.run(func, a_gpu, b_gpu) # calcualte reference rand_a = GF2nStub.getRandomNumber(bits, 42) rand_b = GF2nStub.getRandomNumber(bits, 84) f_ref = GF2n.GF2n(bits) a_ref = f_ref(rand_a) b_ref = f_ref(rand_b) res_ref = a_ref * b_ref # compare results self.assertEqual(res_gpu, res_ref)
def testOpenSSLAddition(self, bits): # do OpenSSL arithmetic f_cpu = GF2nStub.GF2nStub("OpenSSL", bits, -1) a_cpu = f_cpu() b_cpu = f_cpu() res_cpu = a_cpu + b_cpu # calcualte reference rand_irred_poly = GF2nStub.getRandomNumber(bits + 1, 23) rand_a = GF2nStub.getRandomNumber(bits, 42) rand_b = GF2nStub.getRandomNumber(bits, 84) f_ref = GF2n.GF2n(bits, rand_irred_poly) a_ref = f_ref(rand_a) b_ref = f_ref(rand_b) res_ref = a_ref + b_ref # compare results self.assertEqual(res_cpu, res_ref)
def testBigKernelPerformance( self, bits, framework ): runs = 10 # do cuda arithmetic f_gpu = GF2nStub.GF2nStub(framework, bits, -1) a_gpu = f_gpu() b_gpu = f_gpu() flags = 0 GF2nStub.run("parAdd", a_gpu, b_gpu, flags, runs) times = GF2nStub.getEllapsedTime_ms() for time in times: PerformanceDataLogger().addPerfResult("parAdd small", bits, framework, time) flags = 1 chunk_size = 32 if GF2nStub.getRegisterSize() == 64: chunk_size = 64 for num_grids in [2**n for n in range(0,5)]: for num_threads in [1024, 512, 256, 128]: num_blocks = (bits+1)/chunk_size/num_grids/num_threads GF2nStub.setProperty("bn_a", "num_threads", str(num_threads)) GF2nStub.setProperty("bn_a", "num_blocks", str(num_blocks)) GF2nStub.run("parAddLoop", a_gpu, b_gpu, flags, runs) times = GF2nStub.getEllapsedTime_ms() for time in times: PerformanceDataLogger().addPerfResult("parAdd big " + str(num_threads) + " " + str(num_grids), bits, framework, time)