<jupyter_start><jupyter_text>Download the MD5 IP bitstream<jupyter_code>MD5_Design = Overlay("./bitstream/MD5VIVADO.bit")<jupyter_output><empty_output><jupyter_text>Create DMA and MD5 IP objects.<jupyter_code>DMA = MD5_Design.axi_dma_0
MD5 = MD5_Design.MD5_0
sendstatus = DMA.sendchannel.running
recvstatus = DMA.recvchannel.running
print("DMA Channel status: Send: ", sendstatus, " Recv: ", recvstatus)<jupyter_output>DMA Channel status: Send:  True  Recv:  True<jupyter_text>Load DataLoad a string or a file<jupyter_code>#string
#test_string = b"lpz7DrML70FVrHqv96NctqSMexImCCv4eozUEQvapLqvQGsEdtHDrUYz"
#data_length = np.dtype(np.uint64)
#data_length = len(test_string)
#data_in = np.frombuffer(test_string,dtype = np.uint8)

#file
file_path = "./testdata/testdata1" 
data_length = np.dtype(np.uint64)
data_length = os.path.getsize(file_path)
data_in = np.fromfile(file_path,dtype = np.uint8)<jupyter_output><empty_output><jupyter_text>Write data length to MD5 module.<jupyter_code>len0 = np.dtype(np.uint32)
len1 = np.dtype(np.uint32)
len0 = data_length & 0x00000000FFFFFFFF
len1 = (data_length>>32)& 0x00000000FFFFFFFF
MD5.write(0x14, len0) #rows
MD5.write(0x1c, len1) #cols<jupyter_output><empty_output><jupyter_text>Allocate memory to process data on PL.Data is provided as contiguous memory blocks.<jupyter_code>xlnk = Xlnk()
in_buffer = xlnk.cma_array(shape=(data_length,),dtype=np.uint8)
out_buffer = xlnk.cma_array(shape=(4,),dtype=np.uint32)
np.copyto(in_buffer,data_in)<jupyter_output><empty_output><jupyter_text>Start the MD5 process and wait to complete.<jupyter_code>DMA.sendchannel.transfer(in_buffer)
DMA.recvchannel.transfer(out_buffer)
start1 = time.time()
MD5.write(0x00,0x81) # start
DMA.sendchannel.wait()
DMA.recvchannel.wait()
end1 = time.time()<jupyter_output><empty_output><jupyter_text>Print MD5 Value and elapsed time: FPGA vs ARM CPU FPGA: calculated MD5 value and the elapsed time<jupyter_code>print("MD5 FPGA:")
print('MD5:%08x%08x%08x%08x' % (out_buffer[0],out_buffer[1],out_buffer[2],out_buffer[3]))
print("Time elapsed:%.8f ms." % ((end1-start1)*1000))<jupyter_output>MD5 FPGA:
MD5:370bd846600edab7a81b61552c17c1e7
Time elapsed:55.73892593 ms.<jupyter_text>ARM CPU: calculated MD5 value and the elapsed time<jupyter_code>hash_md5 = hashlib.md5()
#string
#start2 = time.time()
#hash_md5.update(test_string)
#end2 = time.time()

#file
start2 = time.time()
with open(file_path,'rb') as f:
    for chunk in iter(lambda: f.read(4096), b""):
            hash_md5.update(chunk)
end2 = time.time()

print("MD5 ARM:")
print("MD5:{}".format(hash_md5.hexdigest()))
print("Time elapsed:%.8f ms." % ((end2-start2)*1000))<jupyter_output>MD5 ARM:
MD5:370bd846600edab7a81b61552c17c1e7
Time elapsed:163.37370872 ms.<jupyter_text>Close and reset<jupyter_code>in_buffer.close()
out_buffer.close()
xlnk.xlnk_reset()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1346153846153846, 'fraction_numerical': 0.06573426573426573, 'mean_word_length': 7.968652037617555, 'pattern_counts': {'":': 0, '<': 34, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '307457', 'license': 'Apache-2.0', 'n_tokens_mistral': 1254, 'n_tokens_neox': 1167, 'n_words': 186, 'path': 'Sourcecode/MD5_PYNQ/Jupyter/MD5.ipynb', 'repo_name': 'Gatsby253/HLS-MD5', 'size': '2860'}