Best Python code snippet using autotest_python
kernelcode_gen.py
Source: kernelcode_gen.py
1#!/usr/bin/python2import os3import re4import math5def generateKernelConfigCode(port_width):6 kernel_config_file_name = 'krnl_config.h'7 kernel_config_file = []8 kernel_config_file.append('#include \"ap_int.h\"' + '\n')9 kernel_config_file.append('#include <inttypes.h>' + '\n')10 kernel_config_file.append('' + '\n')11 kernel_config_file.append('#include \"ap_axi_sdata.h\"' + '\n')12 kernel_config_file.append('#include \"hls_stream.h\"' + '\n')13 kernel_config_file.append('' + '\n')14 kernel_config_file.append('const int DWIDTH = ' + str(port_width) + ';' + '\n')15 kernel_config_file.append('#define INTERFACE_WIDTH ap_uint<DWIDTH>' + '\n')16 kernel_config_file.append('typedef ap_axiu<DWIDTH, 0, 0, 0> pkt;' + '\n')17 kernel_config_file.append('const int NUM_ITERATIONS = 10000;' + '\n')18 with open(kernel_config_file_name, 'w') as f:19 # go to start of file20 f.seek(0)21 # actually write the lines22 f.writelines(kernel_config_file)23def generateKernelWriteKernelCode(num_concurrent_port):24 kernel_file_name = 'krnl_streamWrite.cpp'25 kernel_file = []26 kernel_file.append('#include \"krnl_config.h\"' + '\n')27 kernel_file.append('' + '\n')28 kernel_file.append('extern "C" {' + '\n')29 kernel_file.append(' void krnl_streamWrite(' + '\n')30 kernel_file.append(' volatile INTERFACE_WIDTH* in0,' + '\n')31 kernel_file.append(' const int size,' + '\n')32 for port_index in range(num_concurrent_port-1):33 kernel_file.append(' hls::stream<pkt> &kout' + str(port_index+1) + ',' + '\n')34 kernel_file.append(' hls::stream<pkt> &kout' + str(num_concurrent_port) + '\n')35 kernel_file.append(' ) {' + '\n')36 kernel_file.append(' #pragma HLS INTERFACE m_axi port=in0 offset=slave bundle=gmem0' + '\n')37 kernel_file.append(' #pragma HLS INTERFACE s_axilite port=in0 bundle=control' + '\n')38 kernel_file.append('' + '\n')39 for port_index in range(num_concurrent_port):40 kernel_file.append(' #pragma HLS INTERFACE axis port = kout' + str(port_index+1) + '\n')41 kernel_file.append('' + '\n')42 kernel_file.append(' #pragma HLS INTERFACE s_axilite port=size bundle=control' + '\n')43 kernel_file.append(' #pragma HLS INTERFACE s_axilite port=return bundle=control' + '\n')44 kernel_file.append('' + '\n')45 for port_index in range(num_concurrent_port):46 kernel_file.append(' volatile INTERFACE_WIDTH temp_data_' + str(port_index+1) + ' = 100;' + '\n')47 kernel_file.append('' + '\n')48 kernel_file.append('#pragma HLS DATAFLOW' + '\n')49 kernel_file.append('' + '\n')50 for port_index in range(num_concurrent_port):51 kernel_file.append(' for (int i = 0; i < NUM_ITERATIONS; i++) {' + '\n')52 kernel_file.append(' for (int j = 0; j < size; j++) {' + '\n')53 kernel_file.append(' #pragma HLS PIPELINE II=1' + '\n')54 kernel_file.append(' pkt v' + str(port_index+1) + ';' + '\n')55 kernel_file.append(' v' + str(port_index+1) + '.data = temp_data_' + str(port_index+1) + ';' + '\n')56 kernel_file.append(' kout' + str(port_index+1) + '.write(v' + str(port_index+1) + ');' + '\n')57 kernel_file.append(' }' + '\n')58 kernel_file.append(' }' + '\n')59 kernel_file.append('' + '\n')60 kernel_file.append(' return;' + '\n')61 kernel_file.append(' }' + '\n')62 kernel_file.append('}' + '\n')63 with open(kernel_file_name, 'w') as f:64 # go to start of file65 f.seek(0)66 # actually write the lines67 f.writelines(kernel_file)68def generateKernelReadKernelCode(num_concurrent_port):69 kernel_file_name = 'krnl_streamRead.cpp'70 kernel_file = []71 kernel_file.append('#include \"krnl_config.h\"' + '\n')72 kernel_file.append('' + '\n')73 kernel_file.append('extern "C" {' + '\n')74 kernel_file.append(' void krnl_streamRead(' + '\n')75 kernel_file.append(' volatile INTERFACE_WIDTH* out0,' + '\n')76 kernel_file.append(' const int size,' + '\n')77 for port_index in range(num_concurrent_port-1):78 kernel_file.append(' hls::stream<pkt> &kin' + str(port_index+1) + ',' + '\n')79 kernel_file.append(' hls::stream<pkt> &kin' + str(num_concurrent_port) + '\n')80 kernel_file.append(' ) {' + '\n')81 kernel_file.append(' #pragma HLS INTERFACE m_axi port=out0 offset=slave bundle=gmem0' + '\n')82 kernel_file.append(' #pragma HLS INTERFACE s_axilite port=out0 bundle=control' + '\n')83 kernel_file.append('' + '\n')84 for port_index in range(num_concurrent_port):85 kernel_file.append(' #pragma HLS INTERFACE axis port = kin' + str(port_index+1) + '\n')86 kernel_file.append('' + '\n')87 kernel_file.append(' #pragma HLS INTERFACE s_axilite port=size bundle=control' + '\n')88 kernel_file.append(' #pragma HLS INTERFACE s_axilite port=return bundle=control' + '\n')89 kernel_file.append('' + '\n')90 for port_index in range(num_concurrent_port):91 kernel_file.append(' volatile INTERFACE_WIDTH temp_data_' + str(port_index+1) + ' = 100;' + '\n')92 kernel_file.append('' + '\n')93 kernel_file.append('#pragma HLS DATAFLOW' + '\n')94 kernel_file.append('' + '\n')95 for port_index in range(num_concurrent_port):96 kernel_file.append(' for (int i = 0; i < NUM_ITERATIONS; i++) {' + '\n')97 kernel_file.append(' for (int j = 0; j < size; j++) {' + '\n')98 kernel_file.append(' #pragma HLS PIPELINE II=1' + '\n')99 kernel_file.append(' pkt v' + str(port_index+1) + ' = kin' + str(port_index+1) + '.read();' + '\n')100 kernel_file.append(' temp_data_' + str(port_index+1) + ' = v' + str(port_index+1) + '.data;' + '\n')101 kernel_file.append(' }' + '\n')102 kernel_file.append(' }' + '\n')103 kernel_file.append('' + '\n')104 kernel_file.append(' return;' + '\n')105 kernel_file.append(' }' + '\n')106 kernel_file.append('}' + '\n')107 with open(kernel_file_name, 'w') as f:108 # go to start of file109 f.seek(0)110 # actually write the lines111 f.writelines(kernel_file)112def generateKernelCode(num_concurrent_port, port_width):113 generateKernelConfigCode(port_width)114 generateKernelWriteKernelCode(num_concurrent_port)...
Check out the latest blogs from LambdaTest on this topic:
Before we discuss Scala testing, let us understand the fundamentals of Scala and how this programming language is a preferred choice for your development requirements.The popularity and usage of Scala are rapidly rising, evident by the ever-increasing open positions for Scala developers.
So, now that the first installment of this two fold article has been published (hence you might have an idea of what Agile Testing is not in my opinion), I’ve started feeling the pressure to explain what Agile Testing actually means to me.
Did you know that according to Statista, the number of smartphone users will reach 18.22 billion by 2025? Let’s face it, digital transformation is skyrocketing and will continue to do so. This swamps the mobile app development market with various options and gives rise to the need for the best mobile app testing tools
As a developer, checking the cross browser compatibility of your CSS properties is of utmost importance when building your website. I have often found myself excited to use a CSS feature only to discover that it’s still not supported on all browsers. Even if it is supported, the feature might be experimental and not work consistently across all browsers. Ask any front-end developer about using a CSS feature whose support is still in the experimental phase in most prominent web browsers. ????
The count of mobile users is on a steep rise. According to the research, by 2025, it is expected to reach 7.49 billion users worldwide. 70% of all US digital media time comes from mobile apps, and to your surprise, the average smartphone owner uses ten apps per day and 30 apps each month.
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!