Skip to content

Commit 943bc46

Browse files
committed
Add cli-tool to readme
1 parent 0fcad02 commit 943bc46

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed

README.md

+94
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,100 @@ ToDo
3232

3333
ToDo
3434

35+
## Tools
36+
37+
### glkernel-cli
38+
39+
The glkernel-cli tool provides a convenient way to generate and manipulate kernels using the command line.
40+
The usage is as follows:
41+
42+
```sh
43+
glkernel-cli [--force] [--beautify] [--output <outputFileName>] [--format <outputFileFormat>] <inputFileName>
44+
45+
Options:
46+
-b, --beautify Beautify the output (only applies to json output format)
47+
--force Override the output file, if it exists
48+
-f, --format File format for the generated / converted kernel (e.g., json, png, h)
49+
-o, --output File that the generated / converted kernel will be written to (defaults: <inputFileName>.json for generation, <inputFileName>.png for conversion)
50+
```
51+
52+
- The default output format for kernel generation is JSON
53+
- The default output format for kernel conversion is PNG
54+
- If not output file name is given, the output file name will be deduced from the input file name (here, it would be `kernel.json`)
55+
- If no output format is given, the output format will be deduced from the output file name (explicitly given or deduced)
56+
57+
#### Generating a kernel using JavaScript
58+
59+
Kernels can be generated from JavaScript by simply passing a `.js` file as input to the command line tool.
60+
Examples:
61+
62+
```sh
63+
glkernel-cli kernel.js
64+
65+
glkernel-cli kernel.js -o random_noise_kernel.json --force --beautify
66+
67+
glkernel-cli kernel.js -o sorted_kernel -f png
68+
```
69+
70+
A JavaScript interface (`JSInterface.h`, `JSInterface.cpp`, `glkernel.js`) allows calling glkernel functionality from user scripts.
71+
It is included in the tool's sources (C++ files), and in the `data/` directory (JavaScript file).
72+
The interface is automatically generated from the existing glkernel API.
73+
74+
__If you extend or change the glkernel API, please [re-generate the JavaScript interface](#generating-the-javascript-interface)!__
75+
76+
##### Writing kernel generation instructions in JavaScript
77+
78+
While the glkernel library uses free functions, the JavaScript API provides manipulation of kernels via object methods on kernel objects.
79+
The API method names are taken from the library.
80+
81+
The following script shows the usage of the JavaScript API by example (it can be found in `scripts/kernel.js`):
82+
83+
```javascript
84+
// create new Kernel2 object (i.e., a 3D kernel of dimensions 10x5x2, holding vec2's as values
85+
var kernel = new Kernel2(10, 5, 2);
86+
87+
// translates to glkernel::sequence::uniform(kernel, 0.0, 1.0)
88+
kernel.sequence.uniform(0.0, 1.0);
89+
90+
// examples for other kernel methods
91+
kernel.shuffle.random();
92+
kernel.scale.range(-1.0, 1.0);
93+
94+
// glkernel::sort::distance for a Kernel2 requires a vec2 as parameter
95+
// vec parameters can be passed as JavaScript arrays
96+
kernel.sort.distance([0.0, 0.0]);
97+
```
98+
99+
#### Converting an existing kernel
100+
101+
After generating a kernel in JSON format, that kernel can be read by the tool to be converted into another representation (e.g., PNG).
102+
This is achieved by simply passing a `.json` file as input to the command line tool.
103+
Examples:
104+
105+
```sh
106+
glkernel-cli kernel.json
107+
108+
glkernel-cli kernel.json -o sorted_kernel -f png --force
109+
```
110+
111+
If no output file or format is given, the default output format is PNG.
112+
113+
#### Generating the JavaScript interface
114+
115+
The JavaScript interface files can simply be re-generated using the CMake `generate` target, either from your IDE, or from the project's root folder using the following CMake command:
116+
117+
```sh
118+
cmake --build ./build --target generate
119+
```
120+
121+
This requires Python 2 or 3 to be installed on the system.
122+
Alternatively, the Python script can be executed manually (also from the root folder):
123+
124+
TODO: update this if the destination of JS and C++ files are different
125+
```sh
126+
python scripts/generate.py -t scripts/templates -d source/tools/glkernel-cli
127+
```
128+
35129
##### glkernel-cmd
36130
37131
Additionally to using glkernel as a library, there is a standalone command line tool to generate kernels from JSON descriptions.

0 commit comments

Comments
 (0)