Adding a Scripting Language to CodeXL

One of the goals of the LPGPU2 project is to provide an application to enable developers to target non AMD low power devices running open standard APIs like Vulkan or OpenCL to analyse GPU performance versus efficiency with their applications in order to allow them to write code is efficient manner extending battery life.

CodeXL was chosen as the base tool for the LPGPU2 project for many reasons, but we can highlight a few important ones:

  • It is open source
  • It has a wide range of functionality already implemented
  • It is cross-platform
  • It is already familiar to developers as a profiling tool

CodeXL has a quite large code base. It can be considered a mature and established tool with many features but one key feature is missing in its architecture is a component to perform scripting. Adding a scripting component would allow an easy extension to existing functionality while also opening up the possibility to query CodeXL profiling sessions and the data with.

In this post, we are going to explore the process of adding Lua as a scripting language for LPGPU2 CodeXL in order to facilitate the advanced analysis of power profiling sessions is in quick customisable manner.

The choice of Lua as a scripting language

From the Lua website we read:

Lua is a powerful, efficient, lightweight, embeddable scripting language. It supports procedural programming, object-oriented programming, functional programming, data-driven programming, and data description.

Compared to other scripting languages, Lua is very compact with no external dependencies. It was designed to be embedded in applications and it has a simple but powerful C interface. With this in mind, we can easily expose CodeXL API to Lua scripts. In the summary table below you can see a breakdown by lines of code of the Lua component:

Language Files Blank lines Comment lines Code lines
C 35 2787 2481 14585
C/C++ Headers 26 1111 1132 2010
Make 1 39 10 148
Sum 62 3937 3623 16743

This data was obtained using CLOC 1.72 (http://cloc.sourceforge.net/), and the Lua version is 5.3.4.

As you can see not much to add a new language and open up the possibility for automation or other capabilities.

What will Lua developers have access to inside CodeXL

Currently, the Lua component has been embedded in the CodeXL project to expose the LPGPU2 extended CodeXL database layer to Lua so that it can have access to the power profiling session data. The database layer of CodeXL provides the abstraction of an SQLite database used to store data for profiling sessions. Lua scripts will have access to the database allowing it to read and write the data collected during a profiling session. Figure 1 has a diagram showing how the Feedback Engine was positioned inside CodeXL.

Figure1: Diagram showing where the Feedback Engine was inserted into CodeXL.

What the LPGPU2 project is doing with Lua

Samsung, a LPGPU2 consortium partner, is developing a Lua Feedback Engine. The goal of the Feedback Engine is to provide an in-depth analysis of an application’s power profile session that came from running on a remote device’s profile such as a standard Samsung Galaxy S7 phone. The user performs a power profile analysis session after which the user can ask the Feedback Engine to analyse the data and suggest optimisations. In real time, the profile data displayed and stored in an LPGPU2 modified CodeXL database (it remains standard CodeXL compatible) which the Feedback Engine has access too. This is one of the many achievements of the work carried out by the LPGPU2 project shown in the following video. In order to provide a more detailed analysis of an application, we extended CodeXL’s Power Profiling mode to allow the capture of different GPU API calls with the objective to associate power consumption data with their respective function calls. With this data in their hands assisted by the Feedback Engine, developers can easily find hotspots regarding power consumption and quickly iterate to lower power consumption, therefore delivering a polished application to their users that will last longer on battery powered devices.

https://www.youtube.com/watch?v=7ZDQWUQiTI0

Compiling Lua

The compilation process of Lua is straightforward. On Visual Studio, just create a new project inside your solution, add all the files from the source folder and you are done. In order to modularize the code, we decided to build Lua as a DLL on Windows. For this one just need to define the preprocessor macro LUA_BUILD_AS_DLL on both the project that generates the DLL and the projects that are going to use the DLL.

On Linux, there is the possibility to use the provided Makefile to build Lua with a simple make command, but CodeXL uses the SCons build system. Like Visual Studio, it was just a matter of creating a custom SConscript file to generate the Lua library to be used across CodeXL modules.

Conclusion

Scripting is powerful tool anyone can add to an application in order to provide easy extension and development. Scripts don’t require compilation and linking, therefore they allow for a very fast iteration cycle with a rapid prototype of new functionality. In the case of LPGPU2 CodeXL, the ability to have scripted behaviour has allowed the LPGPU2 project to provide rapid development of advanced features within the tool, in particular, we are enabling advanced analysis of an application power profiling data in order to allow developers to extract maximum performance whilst keeping the battery of mobile devices alive.

 

 

Comments are closed.

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close