def test_pthread_getcpuclockid(self): clk_id = time.pthread_getcpuclockid(threading.get_ident()) self.assertTrue(type(clk_id) is int) self.assertNotEqual(clk_id, time.CLOCK_THREAD_CPUTIME_ID) t1 = time.clock_gettime(clk_id) t2 = time.clock_gettime(clk_id) self.assertLessEqual(t1, t2)
def test_pthread_getcpuclockid(self): clk_id = time.pthread_getcpuclockid(threading.get_ident()) self.assertTrue(type(clk_id) is int) self.assertNotEqual(clk_id, time.CLOCK_THREAD_CPUTIME_ID) # This should suffice to show that both calls are measuring the same clock. t1 = time.clock_gettime(clk_id) t2 = time.clock_gettime(time.CLOCK_THREAD_CPUTIME_ID) t3 = time.clock_gettime(clk_id) t4 = time.clock_gettime(time.CLOCK_THREAD_CPUTIME_ID) self.assertLessEqual(t1, t2) self.assertLessEqual(t2, t3) self.assertLessEqual(t3, t4)
def test_pthread_getcpuclockid(self): clk_id = time.pthread_getcpuclockid(threading.get_ident()) self.assertTrue(type(clk_id) is int) # when in 32-bit mode AIX only returns the predefined constant if not platform.system() == "AIX": self.assertNotEqual(clk_id, time.CLOCK_THREAD_CPUTIME_ID) elif (sys.maxsize.bit_length() > 32): self.assertNotEqual(clk_id, time.CLOCK_THREAD_CPUTIME_ID) else: self.assertEqual(clk_id, time.CLOCK_THREAD_CPUTIME_ID) t1 = time.clock_gettime(clk_id) t2 = time.clock_gettime(clk_id) self.assertLessEqual(t1, t2)
def send_thread_cpu_memory_info(self): # getting the performance info performance_dict = {}; # gives a single float value data_thread = Thread(target=self.sized_rotating_filehandler) data_thread.start() thread_id = data_thread.ident clk_id = time.pthread_getcpuclockid(thread_id) print(data_thread, type(data_thread), time.clock_gettime(clk_id)) performance_dict['cpu_used'] = time.clock_gettime(clk_id) self.logger.info(performance_dict) self.send_data_to_server(performance_dict) threading.Timer(10, self.send_thread_cpu_memory_info).start()
def test_pthread_getcpuclockid(self): clk_id = time.pthread_getcpuclockid(threading.get_ident()) self.assertTrue(type(clk_id) is int) # when in 32-bit mode AIX only returns the predefined constant if platform.system() == "AIX" and (sys.maxsize.bit_length() <= 32): self.assertEqual(clk_id, time.CLOCK_THREAD_CPUTIME_ID) # Solaris returns CLOCK_THREAD_CPUTIME_ID when current thread is given elif sys.platform.startswith("sunos"): self.assertEqual(clk_id, time.CLOCK_THREAD_CPUTIME_ID) else: self.assertNotEqual(clk_id, time.CLOCK_THREAD_CPUTIME_ID) t1 = time.clock_gettime(clk_id) t2 = time.clock_gettime(clk_id) self.assertLessEqual(t1, t2)
def main(): path = '' fname = '' if len(sys.argv) < 2: print('syntax is: ./src/load_andrei_DCTvDFT.py <datafile>') return m = re.match('^(.+)/(.+)$', sys.argv[1]) if m: path = m.group(1) fname = m.group(2) else: print('Failed the filename match') return sizeoftrace = getAndreiSize('%s/%s_HEADER.txt' % (path, fname)) sz = sizeoftrace // 8 ninstances = 32 nbatches = 4 tstep_ns = 1. / 40 tid = get_ident() clkID = time.pthread_getcpuclockid(tid) timeslist = [] dft_timeslist = [] for batch in range(nbatches): print('Processing batch %i of %i instances' % (batch, ninstances)) raw = np.fromfile('%s/%s' % (path, fname), count=sz * ninstances, offset=batch * ninstances * sizeoftrace, dtype=float) data = raw.reshape(ninstances, sz).T slim = 2**int(np.log2(data.shape[0])) lim = int(2**12) print(slim, lim) d = np.row_stack((data[:slim, :], np.flipud(data[:slim, :]))) freqs = np.fft.fftfreq(d.shape[0]) freqsmat = np.tile(freqs, (d.shape[1], 1)).T frq = np.arange(lim, dtype=float) flt1d = frq * (1. + np.cos(frq * np.pi / frq.shape[0])) filt = np.tile(flt1d, (d.shape[1], 1)).T t_0 = time.clock_gettime_ns(clkID) DC = fft.dct(d, axis=0) #DC[lim:2*lim,:] = 0 DC[lim:, :] = 0 DC[:lim, :] *= filt #DS[5000:,:] = 0 dcc = fft.idct(DC[:2 * lim, :], axis=0) dsc = fft.idst(DC[:2 * lim, :], axis=0) #dcc = fft.idct(DC,axis=0) #dsc = fft.idst(DC,axis=0) timeslist += [time.clock_gettime_ns(clkID) - t_0] logic = dsc * dcc np.savetxt('%s/%s_b%i_sample.dat' % (path, fname, batch), d * 1e5, fmt='%i') np.savetxt('%s/%s_b%i_dct.dat' % (path, fname, batch), DC, fmt='%.3f') #np.savetxt('%s/%s_b%i_dst.dat'%(path,fname,batch),DS,fmt='%.3f') np.savetxt('%s/%s_b%i_idct.dat' % (path, fname, batch), dcc, fmt='%.3f') np.savetxt('%s/%s_b%i_idst.dat' % (path, fname, batch), dsc, fmt='%.3f') np.savetxt('%s/%s_b%i_logic.dat' % (path, fname, batch), logic[:lim, :], fmt='%.3f') t_0 = time.clock_gettime_ns(clkID) D = np.fft.fft(d, axis=0) DD = 1j * freqsmat * D logic = np.fft.ifft(D * DD, axis=0).real dft_timeslist += [time.clock_gettime_ns(clkID) - t_0] np.savetxt('%s/%s_b%i_dft_logic.dat' % (path, fname, batch), logic, fmt='%.3f') print(timeslist) print(dft_timeslist) return
class TFv2_FullyConnected(FullyConnected): def generate(self): activation = '' if self._last else 'relu' return tf.keras.layers.Dense(units=self.w_out, activation=activation, input_shape=(self.w_in, )) class NotFoundError(ValueError): pass NAMES = ('conv', 'pool', 'fc') validators = {name: LinearRegression() for name in NAMES} cid = time.pthread_getcpuclockid(threading.get_ident()) # different possible function for benchmarking get_time1 = lambda: time.clock_gettime_ns(cid) get_time2 = lambda: rdtsc.get_cycles() # =========================== SEARCH SPACE ===================================== POSSIBLE_FILTER_WIDTHS = [3, 5, 7, 9, 11, 13, 15, 17] POSSIBLE_STRIDES = [2, 3, 4] POSSIBLE_FILTERS_AMOUNT = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048] POSSIBLE_PADDINGS = ['same', 'valid'] POSSIBLE_UNITS = [8, 16, 32, 64, 128, 256, 512] # ==============================================================================