def next_step(self): os.chdir(os.path.expanduser(config.torch_rnn_path())) print("next step:", str(self)) num_samples = min(1000, self._samples_remaining()) samples = torch_rnn.opencl_samples(self.seed, num_samples=num_samples) ids = [smith.checksum_str(sample) for sample in samples] db = sqlite3.connect(self.db_path) c = db.cursor() for id,sample in zip(ids, samples): c.execute('INSERT OR IGNORE INTO ContentFiles VALUES(?,?)', (id,sample)) db.commit() c.close() db.close()
def content_db(db_path, in_db_path, table='PreprocessedFiles'): odb = sqlite3.connect(db_path) idb = sqlite3.connect(in_db_path) ic = idb.cursor() ic.execute('SELECT id,contents FROM {}'.format(table)) rows = ic.fetchall() for id,contents in rows: kernels = clutil.get_cl_kernels(contents) ids = [smith.checksum_str(kernel) for kernel in kernels] # print("{} kernels in {}".format(len(kernels), id)) for kid,kernel in zip(ids, kernels): oc = odb.cursor() oc.execute('INSERT OR IGNORE INTO ContentFiles VALUES(?,?)', (kid,kernel)) odb.commit()
def add_kernel(self, benchmark, contents, oracle=False): """ Add a kernel to the database. :param benchmark: Benchmark class instance. :param contents: OpenCL source code :param oracle: True if oracle implementation, else false """ contents = contents.strip() kernel_id = smith.checksum_str(contents) benchmark_id = benchmark.id oracle = 1 if oracle else 0 db = self.db() c = db.cursor() c.execute("INSERT OR IGNORE INTO Kernels VALUES(?,?,?,?)", (kernel_id, benchmark_id, oracle, contents)) db.commit()
def process_sample_file(db_path, sample_path, first_only=False): db = sqlite3.connect(db_path) c = db.cursor() with open(sample_path) as infile: sample = infile.read() i = 0 tail = 0 offset = len('__kernel void ') while True: print('\r\033[Kkernel', i, end='') sys.stdout.flush() # Find the starting index of the next kernel. tail = sample.find('__kernel void ', tail) # If we didn't find another kernel, stop. if tail == -1: break # Find the end index of this kernel. head = clutil.get_cl_kernel_end_idx(sample, start_idx=tail, max_len=MAX_KERNEL_LEN) # Look for other ends end = sample.find('__kernel void ', tail + offset, tail + offset + MAX_KERNEL_LEN) head = min(end, head) if end != -1 else head kernel = sample[tail:head] id = smith.checksum_str(kernel) c.execute('INSERT OR IGNORE INTO ContentFiles VALUES(?,?)', (id,kernel)) tail = head i += 1 if first_only: break print() db.commit() c.close() explore.explore(db_path)
def get_id(device, benchmark, kernel, dataset): return smith.checksum_str(repr(device) + repr(benchmark) + repr(kernel) + repr(dataset))