mn416 / QPULib

Language and compiler for the Raspberry Pi GPU
Other
430 stars 63 forks source link

Add command line parameter handling to 'Rot3DLib' #51

Closed wimrijnders closed 4 years ago

wimrijnders commented 6 years ago

This adds a more sophisticated handling of the command line to Rot3DLib.

The reason for this is that I'm expecting many more options to be added to Rot3DLib, and I want solid handling in place before I continue enhancing this application.

I started out by adding code of mine to Rot3DLib, but this quickly escalated in complexity[1]. I therefore decided to make a separate project (CmdParameter) for the full version, and include a 'lite' version within Rot3DLib.


The command line now works like this:

> ./Rot3DLib -h
Rot3DLib - A testbed for QPULib functionality

This application serves as a platform for new and extended functionality for `QPULib`
It uses the kernels of the `Rot3D` example.

Usage:
    Rot3DLib {options}

options:
    (Can appear in any position on the command line after the program name)
    -h            - Show this information. Overrides all other parameters.
    -kernel=<num> - The index of the kernel to run. Index zero is the scalar kernel, which runs on the CPU.
                    Valid values: 0,1,2,3; default '3'.

> ./Rot3DLib -kernel=foo
Error(s) on command line:
  The value for field 'Kernel index' is not a number.

  Use switch '-h' to view options

> ./Rot3DLib -kernel=2
Running kernel 2
0.061022s

> ./Rot3DLib
Running kernel 3
0.005249s

[1] This is mainly due to me wanting to do things right. Otherwise, why bother?

wimrijnders commented 6 years ago

I fully understand that adding so much code in one go can be daunting. I believe, however, that this is worthwhile. It's going to make adding command line parameters much easier.

wimrijnders commented 6 years ago

The important file here is Examples/Rot3DLib/Parameters.cpp. This contains the definitions of the command line parameters. My efforts are directed to making the defintions straightforward and intuitive ('as simple as is feasible').

wimrijnders commented 6 years ago

@mn416 A thought I'm having: I'm beginning to dislike the addition of external project code CmdParameter as a part of Rot3DLib. I think it would be better to have external libraries separate from the QPULib code.

Suggestion: add a directory Vendor to the root directory of QPULib and put 3rd party code there. The build of these tools should be as separate as possible from QPULib, i.e. no 'pollution' in the Makefile.

This is how I approach external code in my own projects. Tell me what you think.