Generate Cuda code from a pretrained rlDDPGAgent object for NVIDIA board

I want to use a pretrained rlDDPGAgent for my NVIDIA Jetson Nano.
With this Agent i want to steer a model car, so the actor net ends with a hyperbolic tangent layer.
Is there a way to use for example the GPU Coder to do the transformation or another suggested possibility?
Due to my account at university i have access to all of the matlab content.
Greetings
Oliver

 Réponse acceptée

If you see here, tha tanhLayer support code generation with GPU Coder starting in R2019b.

5 commentaires

Sure the layer is supported, but the GPU Coder can only support series and directed acyclic graph (DAG) or convolutional neural networks (CNNs or ConvNets). In my case i have a rlDDPGAgent object wich is none of them i think, correct me if i am wrong. I tried to rebuild the actor net as an DAG with all given information in the rlDDPG object and it worked but when i created a function of the actor net, the GPU Coder told me that he needs an output layer. The tanhLayer is not defined as a layer of this type.
You shouldn't need to recreate the network yourself. If you look at the doc here, there is an automated process that takes the agent object and creates a function that does inference that should be compatible with GPU coder (the link has an example as well). Can you try this and let me know what errors you are seeing?
The site of the doc helped a lot and i implemented the following code lines:
generatePolicyFunction(Car_Agent);
cfg = coder.gpuConfig('mex');
cfg.TargetLang = 'C++';
cfg.DeepLearningConfig = coder.DeepLearningConfig('cudnn');
%% Observationinfo
obsInfo = getObservationInfo(Car_Agent);
argstr = '{ones(obsInfo.Dimension(1),obsInfo.Dimension(2))}';
%% Code-Generation
codegen('-config','cfg','evaluatePolicy','-args',argstr,'-report');
For the compilation i selected the Visual C++ 2019 Compiler.
Then the process started and i received a build error with following failures:
  • build/win64/MWTanhLayerImpl.obj step [1/19]
  • build/win64/MWTanhLayer.obj step [2/19]
  • build/win64/cnn_api.obj step [3/19]
  • build/win64/MWCNNLayerImpl.obj step [5/19]
  • build/win64/predict.obj step [6/19]
  • build/win64/_coder_evaluatePolicy_api.obj step [7/19]
  • build/win64/MWTargetNetworkImpl.obj step [8/19]
  • build/win64/DeepLearningNetwork.obj step [9/19]
  • ninja: build stopped: subcommand failed step [10/19]
If it is necessary i can give you the complete build log.
This page has a list with prerequisites you need to have before generating GPU code. Specifically, you need the GPU Coder interface for Deep Learning libraries and the cudnn/tensorrt libraries installed. The env paths should be properly set up as well. Do you have these installed?
Finally i got it! All Matlab content was already installed, and the libraries were added to the CUDA Toolkit file, but i forgot to implement the environment variables and i forgot to add them to my Matlab workaround. After i did this the code generation was succesful. Thanks a lot for the good advices.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Get Started with GPU Coder dans Centre d'aide et File Exchange

Produits

Version

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by