Coder Social home page Coder Social logo

About deploying to the board about dpu-pynq HOT 8 CLOSED

CheungBH avatar CheungBH commented on July 25, 2024
About deploying to the board

from dpu-pynq.

Comments (8)

skalade avatar skalade commented on July 25, 2024

Hi there,

If you have a supported board like a ZCU104 or Ultra96, you do not have to rebuild the designs. Simply download the latest PYNQ image for your board, and once you have that set up you can pip install the dpu-pynq package, which will have the bitstreams and models pre-compiled.

For rebuilding the hardware designs you will need Xilinx development tools (these are not part of this repository), such as Vitis, which you can read more about and download here. XRT is a runtime library which a lot of packages in PYNQ and Vitis AI use, you can read more about it here. Once you install them on your machine, you usually have to source some bash scripts (such as settings64.sh) from their install locations in order to be able to launch them and build your designs.

Thanks
Shawn

from dpu-pynq.

CheungBH avatar CheungBH commented on July 25, 2024

Thank you for your reply! I have generated the target files successfully.

from dpu-pynq.

CheungBH avatar CheungBH commented on July 25, 2024

I obtained the hardware design file ".bit, .hwh, and .xclbin". Also, I got the AI model ".xmodel".
And I think the next step is to run build the model into the hardware. Are there any references or tutorials about it? I am not very clear about how to integrate them.

from dpu-pynq.

skalade avatar skalade commented on July 25, 2024

Well that's what the example notebooks are for https://github.com/Xilinx/DPU-PYNQ/tree/master/pynq_dpu/notebooks

Other than that you can find plenty of examples in Vitis AI tutorials and Vitis AI github repo.

from dpu-pynq.

CheungBH avatar CheungBH commented on July 25, 2024

Thank you. I am trying to install pynq-dpu.
The command of "pip3 install pynq-dpu --no-build-isolation" is executed successfully. However, when I want to use pynq_dpu library, an error occurs showing in the figure.
Screenshot 2022-01-20 at 13 55 04

P.S. I searched the problem and I found that gcc version matters.
My current gcc version is 7.3.0. It also doesn't work even with GCC 8.0, which only generates version 3.4.25.

Screenshot 2022-01-20 at 15 20 56

Is gcc >= 9.0 required? But I found it can not locate gcc-9 with my current system. Here's my system information.

DISTRIB_ID=pynqlinux
DISTRIB_RELEASE=v2.6
DISTRIB_CODENAME=WFH
DISTRIB_DESCRIPTION="PYNQ Linux, based on Ubuntu 18.04"

And I also tried to update the package using
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
, but failed:
Screenshot 2022-01-20 at 15 24 19

Maybe it is just for Ubuntu? And what is the corresponding command in pynqliunux?

from dpu-pynq.

skalade avatar skalade commented on July 25, 2024

Looks like you're using a pynq v2.6 image. The current release of dpu-pynq is supported for v2.7. You can download the latest one from here if you are using a supported board.

from dpu-pynq.

CheungBH avatar CheungBH commented on July 25, 2024

Thank you for your reminder, and I successfully ran the demo code for MNIST, yolov3, and inception by downgrading the pynq-dpu to 1.1.1.
But there is an error when I am running resnet50 when executing C++ code, which cannot find C++:

FileNotFoundError Traceback (most recent call last)
in ()
----> 1 get_ipython().run_cell_magic('pybind11', 'resnet50;{cflags};{ldflags}', '\n#include <dirent.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <sys/stat.h>\n#include <unistd.h>\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include <opencv2/opencv.hpp>\n#include <dnndk/dnndk.h>\n#include <opencv2/opencv.hpp>\n#include <dnndk/n2cube.h>\n\nusing namespace std;\nusing namespace cv;\n\n#define N2CUBE_SUCCESS 0\n#define USE_NEON_OPT\n#define RESNET50_WORKLOAD (7.71f)\n#define KERNEL_RESNET50 "resnet50_0"\n#define INPUT_NODE "conv1"\n#define OUTPUT_NODE "fc1000"\n\nint dpuSetInputImageWithScale(void* task_v, const char* nodeName, \n const cv::Mat &image, float mean, \n float scale, int idx){\n int value;\n int8_t inputAddr;\n unsigned char resized_data;\n cv::Mat newImage;\n float scaleFix;\n int height, width, channel;\n DPUTask task = (DPUTask)task_v;\n height = dpuGetInputTensorHeight(task, nodeName, idx);\n width = dpuGetInputTensorWidth(task, nodeName, idx);\n channel = dpuGetInputTensorChannel(task, nodeName, idx);\n\n if (height == image.rows && width == image.cols) {\n newImage = image;\n } else {\n newImage = cv::Mat (height, width, CV_8SC3,\n (void)dpuGetInputTensorAddress(task, nodeName, idx));\n cv::resize(image, newImage, newImage.size(), 0, 0, cv::INTER_LINEAR);\n }\n resized_data = newImage.data;\n\n inputAddr = dpuGetInputTensorAddress(task, nodeName, idx);\n scaleFix = dpuGetInputTensorScale(task, nodeName, idx);\n\n scaleFix = scaleFixscale;\n\n if (newImage.channels() == 1) {\n for (int idx_h=0; idx_h<height; idx_h++) {\n for (int idx_w=0; idx_w<width; idx_w++) {\n for (int idx_c=0; idx_c<channel; idx_c++) {\n value = (resized_data+idx_hwidthchannel+\\n idx_wchannel+idx_c);\n value = (int)((value - (mean+idx_c)) * scaleFix);\n inputAddr[idx_hnewImage.cols+idx_w] = (char)value;\n }\n }\n }\n } else {\n#ifdef USE_NEON_OPT\n dpuProcessNormalizion(inputAddr, newImage.data, newImage.rows, \n newImage.cols, mean, scaleFix, \n newImage.step1());\n#else\n for (int idx_h=0; idx_h<newImage.rows; idx_h++) {\n for (int idx_w=0; idx_w<newImage.cols; idx_w++) {\n for (int idx_c=0; idx_c<3; idx_c++) {\n value = (int)((newImage.at(idx_h, idx_w)[idx_c] -\\n mean[idx_c]) * scaleFix);\n inputAddr[idx_hnewImage.cols3+idx_w3+idx_c] = \\n (char)value;\n }\n }\n }\n#endif\n }\n return N2CUBE_SUCCESS;\n}\n\n\nint dpuSetInputImage2(void* task_v, const char* nodeName, \n const cv::Mat &image, int idx){\n float mean[3];\n DPUTask* task = (DPUTask*)task_v;\n dpuGetKernelMean(task,mean,image.channels());\n return dpuSetInputImageWithScale(task_v, nodeName, \n image, mean, 1.0f, idx);\n}\n\n\nvoid ListImages(string const &path, vector &images) {\n images.clear();\n struct dirent entry;\n\n struct stat s;\n lstat(path.c_str(), &s);\n if (!S_ISDIR(s.st_mode)) {\n fprintf(stderr, "Error: %s is not a valid directory!\n", \n path.c_str());\n exit(1);\n }\n\n DIR dir = opendir(path.c_str());\n if (dir == nullptr) {\n fprintf(stderr, "Error: Open %s path failed.\n", path.c_str());\n exit(1);\n }\n\n while ((entry = readdir(dir)) != nullptr) {\n if (entry->d_type == DT_REG || entry->d_type == DT_UNKNOWN) {\n string name = entry->d_name;\n string ext = name.substr(name.find_last_of(".") + 1);\n if ((ext == "JPEG") || (ext == "jpeg") || (ext == "JPG") ||\n (ext == "jpg") || (ext == "PNG") || (ext == "png")) {\n images.push_back(name);\n }\n }\n }\n\n closedir(dir);\n sort(images.begin(), images.end());\n}\n\n\nvoid LoadWords(string const &path, vector &kinds) {\n kinds.clear();\n fstream fkinds(path);\n if (fkinds.fail()) {\n fprintf(stderr, "Error : Open %s failed.\n", path.c_str());\n exit(1);\n }\n string kind;\n while (getline(fkinds, kind)) {\n kinds.push_back(kind);\n }\n\n fkinds.close();\n}\n\n\nvoid TopK(const float d, int size, int k, vector &vkinds) {\n assert(d && size > 0 && k > 0);\n priority_queue<pair<float, int>> q;\n\n for (auto i = 0; i < size; ++i) {\n q.push(pair<float, int>(d[i], i));\n }\n\n for (auto i = 0; i < k; ++i) {\n pair<float, int> ki = q.top();\n printf("top[%d] prob = %-8f name = %s\n", i, d[ki.second],\n vkinds[ki.second].c_str());\n q.pop();\n }\n}\n\n\nvoid runResnet50(void task_v, string baseImagePath) {\n DPUTask taskResnet50 = (DPUTask)task_v;\n vector kinds, images;\n ListImages(baseImagePath, images);\n if (images.size() == 0) {\n cerr << "\nError: No images existing under " << baseImagePath << endl;\n return;\n }\n\n LoadWords(baseImagePath + "words.txt", kinds);\n if (kinds.size() == 0) {\n cerr << "\nError: No words exist in file words.txt." << endl;\n return;\n }\n\n int8_t *outAddr = (int8_t *)dpuGetOutputTensorAddress(\n taskResnet50, OUTPUT_NODE);\n int size = dpuGetOutputTensorSize(taskResnet50, OUTPUT_NODE);\n int channel = dpuGetOutputTensorChannel(taskResnet50, OUTPUT_NODE);\n float out_scale = dpuGetOutputTensorScale(taskResnet50, OUTPUT_NODE);\n float *softmax = new float[size];\n\n for (auto &imageName : images) {\n cout << "\nLoad image : " << imageName << endl;\n Mat image = imread(baseImagePath + imageName);\n dpuSetInputImage2(task_v, INPUT_NODE, image, 0);\n\n cout << "\nRun DPU Task for ResNet50 ..." << endl;\n dpuRunTask(taskResnet50);\n\n long long timeProf = dpuGetTaskProfile(taskResnet50);\n cout << " DPU Task Execution time: " << (timeProf * 1.0f) << "us\n";\n float prof = (RESNET50_WORKLOAD / timeProf) * 1000000.0f;\n cout << " DPU Task Performance: " << prof << "GOPS\n";\n\n dpuRunSoftmax(outAddr, softmax, channel, size/channel, out_scale);\n TopK(softmax, channel, 5, kinds);\n }\n\n delete[] softmax;\n}\n\n\nint run(string baseImagePath) {\n DPUKernel *kernelResnet50;\n DPUTask taskResnet50;\n\n dpuOpen();\n kernelResnet50 = dpuLoadKernel(KERNEL_RESNET50);\n taskResnet50 = dpuCreateTask(kernelResnet50, 0);\n runResnet50((void)taskResnet50, baseImagePath);\n dpuDestroyTask(taskResnet50);\n dpuDestroyKernel(kernelResnet50);\n\n return 0;\n}')

/usr/lib/python3/dist-packages/IPython/core/interactiveshell.py in run_cell_magic(self, magic_name, line, cell)
2115 magic_arg_s = self.var_expand(line, stack_depth)
2116 with self.builtin_trap:
-> 2117 result = fn(magic_arg_s, cell)
2118 return result
2119

in pybind11(self, line, cell)

/usr/lib/python3/dist-packages/IPython/core/magic.py in (f, *a, **k)
186 # but it's overkill for just that one bit of state.
187 def magic_deco(arg):
--> 188 call = lambda f, *a, **k: f(*a, **k)
189
190 if callable(arg):

/usr/local/lib/python3.6/dist-packages/pynq/lib/pybind11/magic.py in pybind11(self, line, cell)
62 'ldflags': ldflags}
63 try:
---> 64 _ = Pybind11Processor(module_name, flags, cell)
65 except RuntimeError as r:
66 return HTML("

Compile FAILED\n" + r.args[0] + "
")

/usr/local/lib/python3.6/dist-packages/pynq/lib/pybind11/proc.py in init(self, module_name, flags, program_text)
210 raise RuntimeError("Error parsing code.\n" + str(e))
211
--> 212 _ = Pybind11Compile(module_name, flags, "{}.cpp".format(module_name))
213 os.remove("temp.c")
214 os.remove("{}.cpp".format(module_name))

/usr/local/lib/python3.6/dist-packages/pynq/lib/pybind11/compile.py in init(self, module_name, flags, file_name)
73 self.file_name = file_name
74
---> 75 result = self.compile_cpp()
76 if result.returncode:
77 raise RuntimeError(

/usr/local/lib/python3.6/dist-packages/pynq/lib/pybind11/compile.py in compile_cpp(self)
112 cmd = 'c++ {0} {1} {2}.cpp -o {2}{3} {4}'.format(
113 cflags, include, self.module_name, extension, ldflags)
--> 114 return run(cmd.split(' '), stdout=PIPE, stderr=PIPE)

/usr/lib/python3.6/subprocess.py in run(input, timeout, check, *popenargs, **kwargs)
401 kwargs['stdin'] = PIPE
402
--> 403 with Popen(*popenargs, **kwargs) as process:
404 try:
405 stdout, stderr = process.communicate(input, timeout=timeout)

/usr/lib/python3.6/subprocess.py in init(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors)
707 c2pread, c2pwrite,
708 errread, errwrite,
--> 709 restore_signals, start_new_session)
710 except:
711 # Cleanup if the child failed starting.

/usr/lib/python3.6/subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, start_new_session)
1342 if errno_num == errno.ENOENT:
1343 err_msg += ': ' + repr(err_filename)
-> 1344 raise child_exception_type(errno_num, err_msg, err_filename)
1345 raise child_exception_type(err_msg)
1346

FileNotFoundError: [Errno 2] No such file or directory: 'c++': 'c++'

from dpu-pynq.

skalade avatar skalade commented on July 25, 2024

I will close this out as this seems to be an old example not running on a newer image which might be incompatible. Please do reply if you have found a solution.

from dpu-pynq.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.