Analyze Your Own Code

If you went through our Getting Started guide already, you probably want to use your own code within SLX.cloud. This guide will tell you how to do that. We will use the demo project slx_demo-HOG-usermake, but the steps are exactly the same for your own code. You of course need to know what dependencies your code has and what commands are necessary to build it.

Table of Content

Import Your Code

SLX.cloud currently offers to ways to import your own code:

SLX.cloud allows you to import your code via git, github and SVN. You can start with a workspace using the usermake or usercmake template projects:

Start the workspace and afterwards go to Workspace -> Import Project within the IDE.

It will then open the Import project dialog. In this example we will specify the repository https://github.com/Silexica/slx_demo-HOG-usermake.git as a source to import.

NOTE: It is also possible to import private repositories via Github. For that just go to Preferences -> VCS and click the github button to set up the SSH key. You can find more details at Git and SVN.

2. Using ZIP files

You can upload your source code as a ZIP file into the workspace via Project -> Import ZIP.
NOTE: The files will persist if you stop the workspace, but not if you delete it. Make sure to download your changes via Export ZIP.

NOTE: If you plan on sharing your workspace with coworkers and friends via factories, you will need to use version control to import the source code.

Set Up The Project

After importing your code, you need to select the project type. Silexica supports C and C++ code, therefore you should select one of those, but a Blank project type also works. The Sequential C/C++ Project project type is only used for the usermake project to show the necessary GUI features.

File Structure

You now should have two projects within the project explorer, slx_demo-HOG-usermake is the code we want to analyze and usermake is helper project to import your code into the tooling.

Lets look at the file structure in detail:

LocationDescription
slx_demo-HOG-usermakeProject containing your code.
/src/MakefileMakefile used to build and run your code. In this case, the command would be make -C ./src hog run
usermakeHelper project to set up your project. If you run it as it is, it will analyze the code within the myapp folder.
/specDirectory containing the necessary configuration.
/spec/MakefileThis file includes the SLX tooling into the build process.
/spec/defines.mkThis is only file you need to edit.

The last file on the list is the most important one, as it sets the parameters necessary to run your application. In its default configuration, it will build and run the application within the myapp subfolder, but we want to change it to run your application.

Adapt to your application

To do so, you need to specify two parameters:

ParameterDesired value
USER_BUILD_AND_RUN $(MAKE) -C ./../../slx_demo-HOG-usermake/src hog run
USER_CLEAN$(MAKE) -C ./../../slx_demo-HOG-usermake/src hog clean

The first command will build the sample application, the second command cleans the output folder. These commands are specific to your application, but the general concept is simple: We start in the usermake/spec folder and therefore need to move up to the root ./../../ and into the source code directory slx_demo-HOG-usermake/src. There we will call the MAKE command by using the environment variable $(MAKE) and adding the path via the -C parameter. hog run and hog clean are specific make commands defined in the Makefile at slx_demo-HOG-usermake/src/Makefile. Again, these will probably be different for your application.
NOTE: You don’t need to specify a make command here, a shell script doing the build and run would be fine as well. The SLX tools will take care of specifying the right compiler through environment variables (e.g. CC, CXX and so on).

Test your build setup

Now it is time to test the setup. To do that, select the usermake project in the IDE and click the Run Sequential Code button.

 run Run application Compiles and runs the demo project or your application based on the current configuration. This step is optional but recommended.

The result should like this:

You will see a green popup notifying you that the application ran successfully. This is the case if the script you specified in USER_BUILD_AND_RUN exited successfully without an error (return code 0). In this case, the terminal output will also tell you that [Test on host finished ].

NOTE: If you were not able to set the environment properly, you can take a look at the resulting defines.mk here: https://github.com/Silexica/slx_demo-HOG-usermake-configuration/blob/master/spec/defines.mk.

Install dependencies

This example does not require any additional dependencies. If your software does, you can just install them temporarily via the terminal. Our stack is based on Ubuntu, so you can use apt-get install to add additional software:

NOTE: Your workspace is based on a docker image, therefore it will not save installed dependencies after stopping the workspace. To permanently install dependencies into the workspace, you need to create your own stack. You can find more details under Runtime Stacks.

Test your clean command

To test the clean functionality, click the Clean Project button. It should reset your project folder into a clean state.

 clean Clean Project Removes all auto-generated files from your project folder.

You will be notified by a Project Cleaned! message, if the command ran successfully.

Start Analyzing

After you have validated that your build and clean scripts run successfully, you can finally start analyzing your code!

Tracing

The first relevant command now is Trace Source. This will compile your code with our SLX compiler to generate analysis information.

 trace Trace Source Compiles and executes an instrumented version of the application. This is obtains detailed information for the application, such as the execution paths and accesses to variables and memory. Trace Files are generated in your project folder.

NOTE: Tracing takes significantly longer than just running your application. For the HOG application, this takes about 5 minutes.

After a successful trace, the Application Hints View will open:

These hints already show you information about your application, for example which part of the code takes the most time to execute.

Call Graph Visualization

 Open Call Graph Open Call Graph Visualize the dynamic call graph of the application.

The Call Graph visualization helps you analyze the functional structure of your application. It will also show you Hotspots of your application, by the percentage and shade of a node. (You might need click the usermake/output/usermake.cg file to activate the Call Graph button). Hovering over nodes and graphs will give you additional information.

Find Parallelism

The find parallelism functionality will analyse your code for DLP (data-level paralellism), TLP (task-level parallelism) and PLP (pipeline-level parallelism). You can find more information on this topic in our advanced guide.
The results of the analysis are presented as hints in the Hints View:

 find_Parallism Find Parallelism Runs the partitioning algorithms of the SLX.cloud tools for allocating code into parallel tasks. For more information on the underlying technology, please refer to our advanced guide

OpenMP Code Generation

The final and probably most interesting step is OpenMP Code Generation. This feature will automatically annotate your code with OpenMP annotations at the right locations to optimize it. To get more details regarding OpenMP annotation, see Code Generation Hints.

 openMP OpenMP Code Generation Runs the source-to-source code rewriter to automatically insert OpenMP (Open Multi-Processing) pragmas to the user’s application. The rewritten files are located under output/codegen/openmp.

This is an example of an annotated for loop:

Going forward

Now it’s time to try with your own code! The steps are the same, you just need to adapt the USER_BUILD_AND_RUN and USER_CLEAN commands to your needs. If you get stuck at any point, feel free to contact us at info@slx.cloud, we are more than happy to hear from you and help you. Any feedback is appreciated!