Пример #1
0
	def gen_simulation(self, selfp):
		for data0, data1 in zip(self.data_to_recv[::2], self.data_to_recv[1::2]):
			words = yield from riffa.channel_read(selfp.simulator, self.channel)
			print(words)
			if data0 != words[0] or data1 != words[1]:
				print("Expected: {}".format((hex(data0),hex(data1))))
		yield
Пример #2
0
        def run_matmul(run):
            # send arguments to DUT
            yield from riffa.channel_write(selfp.simulator, self.rx,
                                           arg_struct)

            # wait for return value
            ret = yield from riffa.channel_read(selfp.simulator, self.tx)

            yield from self.tbmem.send_flush_command(selfp)

            print("MatMul run " + str(run) + " finished. Reports " +
                  str(riffa.pack(ret)) + " cycles taken.")

            # verify result matrix
            num_errors = 0
            for i in range(dim_i):
                for j in range(dim_j):
                    # address "i"th word in range
                    addr = baseC + (
                        (i * dim_j + j) << log2_int(self.wordsize // 8))
                    # compare to expected
                    if self.tbmem.read_mem(addr) != expectedC[i][j]:
                        num_errors += 1
                        # print a few errors but not too many
                        if num_errors <= 10:
                            print(
                                hex(addr) + ": " +
                                str(self.tbmem.read_mem(addr)) +
                                " (expected " + str(expectedC[i][j]) + ")")
            if num_errors > 10:
                print(str(num_errors) + " errors total.")

            yield
Пример #3
0
	def gen_simulation(self, selfp):
		# memory area to work on
		baseaddr = ?? ## TODO
		size = ?? ## TODO
		# function argument to send (as list of 32 bit words)
		arg_struct = [baseaddr, size, ??] ## TODO
		# expected return value (as list of 32 bit words)
		expected_ret = [??] ## TODO 
		# expected memory modifications (in memory words of size 'wordsize')
		expected_results = [??] ## TODO

		# send arguments to DUT
		yield from riffa.channel_write(selfp.simulator, self.rx, arg_struct)

		# wait for return value
		ret = yield from riffa.channel_read(selfp.simulator, self.tx)

		# check return value
		if ret != expected_ret:
			## TODO
			print("Wrong return value! Expected " + str(expected_ret) + ", received " + str(ret))

		# check memory modifications
		num_errors = 0
		for i in range(size):
			# address "i"th word in range
			addr = baseaddr + i << log2_int(self.wordsize//8)
			# compare to expected
			if self.tbmem.read_mem(addr) != expected_results[i]:
				num_errors += 1
				# print a few errors but not too many
				if num_errors <= 10:
					print(hex(addr) + ": " + str(self.tbmem.read_mem(addr)) + " (expected " + str(expected_results[i]) + ")")
		if num_errors > 10:
			print("And " + str(num_errors-10) + " more.")
Пример #4
0
		def run_matmul(run):
			# send arguments to DUT
			yield from riffa.channel_write(selfp.simulator, self.rx, arg_struct)

			# wait for return value
			ret = yield from riffa.channel_read(selfp.simulator, self.tx)

			yield from self.tbmem.send_flush_command(selfp)

			print("MatMul run " + str(run) + " finished. Reports " + str(riffa.pack(ret)) + " cycles taken.")

			# verify result matrix
			num_errors = 0
			for i in range(dim_i):
				for j in range(dim_j):
					# address "i"th word in range
					addr = baseC + ((i * dim_j + j) << log2_int(self.wordsize//8))
					# compare to expected
					if self.tbmem.read_mem(addr) != expectedC[i][j]:
						num_errors += 1
						# print a few errors but not too many
						if num_errors <= 10:
							print(hex(addr) + ": " + str(self.tbmem.read_mem(addr)) + " (expected " + str(expectedC[i][j]) + ")")
			if num_errors > 10:
				print(str(num_errors) + " errors total.")

			yield
Пример #5
0
	def gen_simulation(self, selfp):
		errors = 0
		for data in self.data_to_recv:
			words = yield from riffa.channel_read(selfp.simulator, self.channel)
			print(words)
			if data != words[0]:
				errors += 1
				print("Expected: {}".format(hex(data)))
		yield
		print(str(errors) + " error(s) in received data.")
		self.done = 1
Пример #6
0
 def gen_simulation(self, selfp):
     errors = 0
     for data in self.data_to_recv:
         words = yield from riffa.channel_read(selfp.simulator,
                                               self.channel)
         print(words)
         if data != words[0]:
             errors += 1
             print("Expected: {}".format(hex(data)))
     yield
     print(str(errors) + " error(s) in received data.")
     self.done = 1
Пример #7
0
    def gen_simulation(self, selfp):
        # memory area to work on
        baseaddr = 0x222000  ## TODO
        size = 64  ## TODO
        # function argument to send (as list of 32 bit words)
        arg_struct = []
        arg_struct.extend(riffa.unpack(baseaddr, 2))
        arg_struct.extend(riffa.unpack(size, 2))
        # expected return value (as list of 32 bit words)
        expected_ret = [size]  ## TODO
        # expected memory modifications (in memory words of size 'wordsize')
        expected_results = [i for i in range(size)]  ## TODO

        # send arguments to DUT
        yield from riffa.channel_write(selfp.simulator, self.rx, arg_struct)

        # wait for return value
        ret = yield from riffa.channel_read(selfp.simulator, self.tx)

        # check return value
        if ret != expected_ret:
            ## TODO
            print("Wrong return value! Expected " + str(expected_ret) +
                  ", received " + str(ret))

        yield from self.tbmem.send_flush_command(selfp)

        # check memory modifications
        num_errors = 0
        for i in range(size):
            # address "i"th word in range
            addr = baseaddr + (i << log2_int(self.wordsize // 8))
            # compare to expected
            # print(hex(addr) + ": " + str(self.tbmem.read_mem(addr)))
            if self.tbmem.read_mem(addr) != expected_results[i]:
                num_errors += 1
                # print a few errors but not too many
                if num_errors <= 10:
                    print(
                        hex(addr) + ": " + str(self.tbmem.read_mem(addr)) +
                        " (expected " + str(expected_results[i]) + ")")
        if num_errors > 10:
            print(str(num_errors) + " errors total.")
        if num_errors == 0:
            print("Test passed.")
Пример #8
0
	def gen_simulation(self, selfp):
		# memory area to work on
		baseaddr = 0x222000 ## TODO
		size = 64 ## TODO
		# function argument to send (as list of 32 bit words)
		arg_struct = []
		arg_struct.extend(riffa.unpack(baseaddr, 2))
		arg_struct.extend(riffa.unpack(size, 2))
		# expected return value (as list of 32 bit words)
		expected_ret = [size] ## TODO 
		# expected memory modifications (in memory words of size 'wordsize')
		expected_results = [i for i in range(size)] ## TODO

		# send arguments to DUT
		yield from riffa.channel_write(selfp.simulator, self.rx, arg_struct)

		# wait for return value
		ret = yield from riffa.channel_read(selfp.simulator, self.tx)

		# check return value
		if ret != expected_ret:
			## TODO
			print("Wrong return value! Expected " + str(expected_ret) + ", received " + str(ret))

		yield from self.tbmem.send_flush_command(selfp)

		# check memory modifications
		num_errors = 0
		for i in range(size):
			# address "i"th word in range
			addr = baseaddr + (i << log2_int(self.wordsize//8))
			# compare to expected
			# print(hex(addr) + ": " + str(self.tbmem.read_mem(addr)))
			if self.tbmem.read_mem(addr) != expected_results[i]:
				num_errors += 1
				# print a few errors but not too many
				if num_errors <= 10:
					print(hex(addr) + ": " + str(self.tbmem.read_mem(addr)) + " (expected " + str(expected_results[i]) + ")")
		if num_errors > 10:
			print(str(num_errors) + " errors total.")
		if num_errors == 0:
			print("Test passed.")
Пример #9
0
	def gen_simulation(self, selfp):
		while True:
			words = yield from riffa.channel_read(selfp.simulator, self.channel)
			print(words)
Пример #10
0
 def gen_simulation(self, selfp):
     ret = []
     while True:
         if selfp.cmd_rx.start:
             # print("Receiving command...")
             cmd = yield from riffa.channel_read(selfp.simulator,
                                                 self.cmd_rx)
             addr = (cmd[1] << 32) | cmd[0] if self.ptrsize > 32 else cmd[0]
             pg_addr = (addr >> log2_int(self.pagesize)) << log2_int(
                 self.pagesize)
             assert (addr == pg_addr)
             if cmd[2] == 0x6e706e70:
                 print("Fetching page " + hex(addr))
                 data = []
                 if self.wordsize < 32:
                     mask = 1
                     for i in range(self.wordsize):
                         mask = mask | (1 << i)
                     for i in range(pg_addr, pg_addr + self.pagesize, 4):
                         d = 0
                         for j in range(0, 32 // self.wordsize):
                             d = d | ((self.read_mem(i + j *
                                                     (self.wordsize // 8))
                                       & mask) << j * self.wordsize)
                         data.append(d)
                 else:
                     for i in range(pg_addr, pg_addr + self.pagesize,
                                    (self.wordsize // 8)):
                         data.extend(
                             riffa.unpack(self.read_mem(i),
                                          self.wordsize // 32))
                 if len(data) != self.pagesize // 4:
                     print("Wrong page length: " + str(len(data)))
                 yield from riffa.channel_write(selfp.simulator,
                                                self.data_tx, data)
                 # print("Finished fetching page.")
             if cmd[2] == 0x61B061B0:
                 print("Writeback page " + hex(addr))
                 # print(ret)
                 if len(ret) < self.pagesize // 4:
                     print("Incomplete writeback: received only " +
                           str(len(ret)) + " words")
                 if self.wordsize >= 32:
                     words = [
                         riffa.pack(x) for x in zip(*[
                             ret[i::self.wordsize // 32]
                             for i in range(self.wordsize // 32)
                         ])
                     ]
                 else:
                     words = []
                     mask = 1
                     for i in range(self.wordsize):
                         mask = mask | (1 << i)
                     for i in range(len(ret)):
                         for j in range(32 // self.wordsize):
                             words.append((ret[i] >> j * self.wordsize)
                                          & mask)
                 print("Modified:")
                 num_modified = 0
                 for i in range(len(words)):
                     if words[i] != self.read_mem(addr + i *
                                                  (self.wordsize // 8)):
                         num_modified += 1
                         self.modified[addr + i *
                                       (self.wordsize // 8)] = words[i]
                         if num_modified < 10:
                             print(
                                 hex(addr + i * (self.wordsize // 8)) +
                                 ": " + hex(words[i]))
                 if num_modified >= 10:
                     print("and more... " + str(num_modified) + " total.")
                 ret = []
                 # print("Finished writing back page.")
             if cmd[2] == 0xD1DF1005:
                 self.flushack = 1
                 print("Cache finished flushing.")
         elif selfp.data_rx.start:
             # print("Receiving data...")
             ret = yield from riffa.channel_read(selfp.simulator,
                                                 self.data_rx)
             # print("Finished receiving data.")
         else:
             # print("Nothing")
             yield
Пример #11
0
	def gen_simulation(self, selfp):
		ret = []
		while True:
			if selfp.cmd_rx.start :
				# print("Receiving command...")
				cmd = yield from riffa.channel_read(selfp.simulator, self.cmd_rx)
				addr = (cmd[1] << 32) | cmd[0] if self.ptrsize > 32 else cmd[0]
				pg_addr = (addr >> log2_int(self.pagesize)) << log2_int(self.pagesize) 
				assert(addr == pg_addr)
				if cmd[2] == 0x6e706e70:
					print("Fetching page " + hex(addr))
					data = []
					if self.wordsize < 32:
						mask = 1
						for i in range(self.wordsize):
							mask = mask | (1 << i)
						for i in range(pg_addr, pg_addr+self.pagesize, 4):
							d = 0
							for j in range(0,32//self.wordsize):
								d = d | ((self.read_mem(i+ j*(self.wordsize//8)) & mask) << j*self.wordsize)
							data.append(d)
					else:
						for i in range(pg_addr, pg_addr+self.pagesize, (self.wordsize//8)):
							data.extend(riffa.unpack(self.read_mem(i), self.wordsize//32))
					if len(data) != self.pagesize//4:
						print("Wrong page length: " + str(len(data)))
					yield from riffa.channel_write(selfp.simulator, self.data_tx, data)
					# print("Finished fetching page.")
				if cmd[2] == 0x61B061B0:
					print("Writeback page " + hex(addr))
					# print(ret)
					if len(ret) < self.pagesize//4:
						print("Incomplete writeback: received only " + str(len(ret)) + " words")
					if self.wordsize >= 32:
						words = [riffa.pack(x) for x in zip(*[ret[i::self.wordsize//32] for i in range(self.wordsize//32)])]
					else:
						words = []
						mask = 1
						for i in range(self.wordsize):
							mask = mask | (1 << i)
						for i in range(len(ret)):
							for j in range(32//self.wordsize):
								words.append((ret[i] >> j*self.wordsize) & mask)
					print("Modified:")
					num_modified = 0
					for i in range(len(words)):
						if words[i] != self.read_mem(addr+i*(self.wordsize//8)):
							num_modified += 1
							self.modified[addr+i*(self.wordsize//8)] = words[i]
							if num_modified < 10:
								print(hex(addr+i*(self.wordsize//8)) + ": " + hex(words[i]))
					if num_modified >= 10:
						print("and more... " + str(num_modified) + " total.")
					ret = []
					# print("Finished writing back page.")
				if cmd[2] == 0xD1DF1005:
					self.flushack = 1
					print("Cache finished flushing.")
			elif selfp.data_rx.start:
				# print("Receiving data...")
				ret = yield from riffa.channel_read(selfp.simulator, self.data_rx)
				# print("Finished receiving data.")
			else:
				# print("Nothing")
				yield