Skip to content

Commit cfa9a77

Browse files
committed
added cli parsing for runtime options
1 parent 853af24 commit cfa9a77

File tree

11 files changed

+92
-38
lines changed

11 files changed

+92
-38
lines changed

include/shady/driver.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ typedef enum {
3939

4040
CodegenTarget guess_target(const char* filename);
4141

42-
void cli_pack_remaining_args(int* pargc, char** argv);
43-
4442
// parses 'common' arguments such as log level etc
4543
void cli_parse_common_args(int* pargc, char** argv);
4644
// parses compiler pipeline options

include/shady/runtime.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ typedef struct {
1111
bool allow_no_devices;
1212
} RuntimeConfig;
1313

14+
RuntimeConfig default_runtime_config();
15+
void cli_parse_runtime_config(RuntimeConfig* config, int* pargc, char** argv);
16+
1417
typedef struct Runtime_ Runtime;
1518
typedef struct Device_ Device;
1619
typedef struct Program_ Program;

samples/aobench/ao_main.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,16 +159,14 @@ int main(int argc, char **argv) {
159159
set_log_level(INFO);
160160
Args args = {
161161
.compiler_config = default_compiler_config(),
162-
.runtime_config = {
163-
.use_validation = true,
164-
.dump_spv = true,
165-
}
162+
.runtime_config = default_runtime_config(),
166163
};
167164

168165
args.compiler_config.hacks.restructure_everything = true;
169166

170167
cli_parse_common_args(&argc, argv);
171168
cli_parse_compiler_config_args(&args.compiler_config, &argc, argv);
169+
cli_parse_runtime_config(&args.runtime_config, &argc, argv);
172170
cli_parse_common_app_arguments(&args.common_app_args, &argc, argv);
173171

174172
bool do_host = false, do_ispc = false, do_device = false, do_all = true;

samples/checkerboard/checkerboard.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,11 @@ int main(int argc, char **argv)
4343
set_log_level(INFO);
4444
CompilerConfig compiler_config = default_compiler_config();
4545

46-
RuntimeConfig runtime_config = (RuntimeConfig) {
47-
.use_validation = true,
48-
.dump_spv = true,
49-
};
46+
RuntimeConfig runtime_config = default_runtime_config();
5047

5148
cli_parse_common_args(&argc, argv);
5249
cli_parse_compiler_config_args(&compiler_config, &argc, argv);
50+
cli_parse_runtime_config(&runtime_config, &argc, argv);
5351

5452
info_print("Shady checkerboard test starting...\n");
5553

src/driver/cli.c

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
#include "cli.h"
2+
13
#include "shady/driver.h"
24
#include "shady/ir.h"
35

46
#include <stdlib.h>
57
#include <stdbool.h>
6-
#include <string.h>
78

89
#include "log.h"
910
#include "portability.h"
@@ -81,25 +82,18 @@ void cli_parse_common_args(int* pargc, char** argv) {
8182
cli_pack_remaining_args(pargc, argv);
8283
}
8384

84-
#define PARSE_TOGGLE_OPTION(f, name) \
85-
if (strcmp(argv[i], "--no-"#name) == 0) { \
86-
config->f = false; argv[i] = NULL; continue; \
87-
} else if (strcmp(argv[i], "--"#name) == 0) { \
88-
config->f = true; argv[i] = NULL; continue; \
89-
}
90-
91-
#define TOGGLE_OPTIONS(F) \
92-
F(lower.emulate_physical_memory, emulate-physical-memory) \
93-
F(lower.emulate_generic_ptrs, emulate-generic-pointers) \
94-
F(dynamic_scheduling, dynamic-scheduling) \
95-
F(hacks.force_join_point_lifting, lift-join-points) \
96-
F(logging.print_internal, print-internal) \
97-
F(logging.print_generated, print-builtin) \
98-
F(logging.print_generated, print-generated) \
99-
F(lower.simt_to_explicit_simd, lower-simt-to-simd) \
100-
F(optimisations.inline_everything, inline-everything) \
101-
F(hacks.restructure_everything, restructure-everything) \
102-
F(hacks.recover_structure, recover-structure) \
85+
#define COMPILER_CONFIG_TOGGLE_OPTIONS(F) \
86+
F(config->lower.emulate_physical_memory, emulate-physical-memory) \
87+
F(config->lower.emulate_generic_ptrs, emulate-generic-pointers) \
88+
F(config->dynamic_scheduling, dynamic-scheduling) \
89+
F(config->hacks.force_join_point_lifting, lift-join-points) \
90+
F(config->logging.print_internal, print-internal) \
91+
F(config->logging.print_generated, print-builtin) \
92+
F(config->logging.print_generated, print-generated) \
93+
F(config->lower.simt_to_explicit_simd, lower-simt-to-simd) \
94+
F(config->optimisations.inline_everything, inline-everything) \
95+
F(config->hacks.restructure_everything, restructure-everything) \
96+
F(config->hacks.recover_structure, recover-structure) \
10397

10498
void cli_parse_compiler_config_args(CompilerConfig* config, int* pargc, char** argv) {
10599
int argc = *pargc;
@@ -109,7 +103,7 @@ void cli_parse_compiler_config_args(CompilerConfig* config, int* pargc, char** a
109103
if (argv[i] == NULL)
110104
continue;
111105

112-
TOGGLE_OPTIONS(PARSE_TOGGLE_OPTION)
106+
COMPILER_CONFIG_TOGGLE_OPTIONS(PARSE_TOGGLE_OPTION)
113107

114108
if (strcmp(argv[i], "--entry-point") == 0) {
115109
argv[i] = NULL;

src/driver/cli.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#ifndef CLI_H
2+
#define CLI_H
3+
4+
#include <string.h>
5+
6+
#define PARSE_TOGGLE_OPTION(f, name) \
7+
if (strcmp(argv[i], "--no-"#name) == 0) { \
8+
f = false; argv[i] = NULL; continue; \
9+
} else if (strcmp(argv[i], "--"#name) == 0) { \
10+
f = true; argv[i] = NULL; continue; \
11+
}
12+
13+
void cli_pack_remaining_args(int* pargc, char** argv);
14+
15+
#endif CLI_H

src/runtime/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
add_library(runtime runtime.c runtime_program.c)
1+
add_library(runtime runtime.c runtime_program.c runtime_cli.c)
22
target_link_libraries(runtime PUBLIC driver)
33
set_target_properties(runtime PROPERTIES OUTPUT_NAME "shady_runtime")
44

src/runtime/runtime_cli.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include "runtime_private.h"
2+
#include "driver/cli.h"
3+
4+
#include "common/log.h"
5+
6+
RuntimeConfig default_runtime_config() {
7+
return (RuntimeConfig) {
8+
#ifndef NDEBUG
9+
.dump_spv = true,
10+
.use_validation = true,
11+
#endif
12+
};
13+
}
14+
15+
#define DRIVER_CONFIG_OPTIONS(F) \
16+
F(config->use_validation, api-validation) \
17+
F(config->dump_spv, dump-spv) \
18+
19+
void cli_parse_runtime_config(RuntimeConfig* config, int* pargc, char** argv) {
20+
int argc = *pargc;
21+
22+
bool help = false;
23+
for (int i = 1; i < argc; i++) {
24+
25+
DRIVER_CONFIG_OPTIONS(PARSE_TOGGLE_OPTION)
26+
27+
if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0) {
28+
help = true;
29+
continue;
30+
} else {
31+
continue;
32+
}
33+
argv[i] = NULL;
34+
}
35+
36+
if (help) {
37+
// error_print("Usage: slim source.slim\n");
38+
// error_print("Available arguments: \n");
39+
error_print(" --target <c, glsl, ispc, spirv> \n");
40+
error_print(" --output <filename>, -o <filename> \n");
41+
error_print(" --dump-cfg <filename> Dumps the control flow graph of the final IR\n");
42+
error_print(" --dump-loop-tree <filename>\n");
43+
error_print(" --dump-ir <filename> Dumps the final IR\n");
44+
}
45+
46+
cli_pack_remaining_args(pargc, argv);
47+
}

src/runtime/runtime_test.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,11 @@ int main(int argc, char* argv[]) {
3232
set_log_level(INFO);
3333
Args args = {
3434
.driver_config = default_driver_config(),
35-
};
36-
args.runtime_config = (RuntimeConfig) {
37-
.use_validation = true,
38-
.dump_spv = true,
35+
.runtime_config = default_runtime_config(),
3936
};
4037
cli_parse_common_app_arguments(&args.common_app_args, &argc, argv);
4138
cli_parse_common_args(&argc, argv);
39+
cli_parse_runtime_config(&args.runtime_config, &argc, argv);
4240
cli_parse_compiler_config_args(&args.driver_config.config, &argc, argv);
4341
cli_parse_input_files(args.driver_config.input_filenames, &argc, argv);
4442

src/shady/passes/lower_tailcalls.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ void generate_top_level_dispatch_fn(Context* ctx) {
357357
BodyBuilder* if_builder = begin_body(a);
358358
if (ctx->config->printf_trace.god_function) {
359359
const Node* sid = gen_builtin_load(ctx->rewriter.dst_module, loop_body_builder, BuiltinSubgroupId);
360-
bind_instruction(if_builder, prim_op(a, (PrimOp) { .op = debug_printf_op, .operands = mk_nodes(a, string_lit(a, (StringLiteral) { .string = "trace: thread %d:%d will run fn %d with mask = %lx\n" }), sid, local_id, fn_lit, next_mask) }));
360+
bind_instruction(if_builder, prim_op(a, (PrimOp) { .op = debug_printf_op, .operands = mk_nodes(a, string_lit(a, (StringLiteral) { .string = "trace: thread %d:%d will run fn %ul with mask = %lx\n" }), sid, local_id, fn_lit, next_mask) }));
361361
}
362362
bind_instruction(if_builder, call(a, (Call) {
363363
.callee = fn_addr_helper(a, find_processed(&ctx->rewriter, decl)),

0 commit comments

Comments
 (0)