Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ char *qb_find_path(char *filename);
char *qb_config_file(char *path);

size_t qb_find_type_size(char *type);
void *qb_string_to_void(char *type, char *value);

// String Manipulation
bool qb_is_space(char a);
Expand Down
3 changes: 3 additions & 0 deletions include/quibble_args.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ quibble_kwarg *qb_parse_kwargs(char *config, int num_entries);

int qb_find_arg_index(quibble_arg *arg, int n, char *variable);
int qb_find_kwarg_index(quibble_kwarg *qk, int n, char *variable);
int qb_find_any_index(quibble_arg *args, int n,
quibble_kwarg *kwargs, int k_n,
char *variable);

// prologue
char *qb_create_prologue(char *config, char *name,
Expand Down
2 changes: 2 additions & 0 deletions include/quibble_program.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ typedef struct{
typedef struct{
quibble_arg *args;
int num_args;
quibble_kwarg *kwargs;
int num_kwargs;
char *body;
char *name;
} quibble_poem;
Expand Down
3 changes: 3 additions & 0 deletions src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ quibble_pixel *qb_create_pixel_array(int height, int width){
return qpa;
}

void *qb_string_to_void(char *type, char *value){
}

size_t qb_find_type_size(char *type){

if (type == NULL){
Expand Down
32 changes: 31 additions & 1 deletion src/quibble_args.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,42 @@ int qb_find_number_of_kwargs(char *config){

}

int qb_find_any_index(quibble_arg *args, int n,
quibble_kwarg *kwargs, int k_n,
char *variable){

if (n <= 0 && k_n <= 0){
return -1;
}

for (int i = 0; i < n; ++i){
if (strcmp(args[i].variable, variable) == 0){
return i;
}
}

for (int i = 0; i < k_n; ++i){
if (strcmp(kwargs[i].variable, variable) == 0){
if (n > 0){
return i+n;
}
else{
return i;
}
}
}

fprintf(stderr, "%s is not an argument or keyword argument!\n", variable);
exit(1);


}

int qb_find_arg_index(quibble_arg *qa, int n, char *variable){
if (n <= 0){
return -1;
}


for (int i = 0; i < n; ++i){
if (strcmp(qa[i].variable, variable) == 0){
return i;
Expand Down
52 changes: 36 additions & 16 deletions src/quibble_poems.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,19 @@ quibble_poem qb_parse_poem(char *poem){
final_poem.args =
qb_parse_args(config, final_poem.num_args);

final_poem.num_kwargs = qb_find_number_of_kwargs(config);
final_poem.kwargs =
qb_parse_kwargs(config, final_poem.num_kwargs);

free(config);
}
else {
final_poem.args = NULL;
final_poem.num_args = 0;
final_poem.kwargs = NULL;
final_poem.num_kwargs = 0;
}


int body_start = qb_find_next_char(poem, offset, '{')+1;
int body_end = qb_find_matching_char(poem, poem_size, body_start-1, '{', '}');

Expand Down Expand Up @@ -108,24 +113,38 @@ char *qb_expand_poem(quibble_program qp, int poem_index){
strcat(tmp_body, "__kernel void ");
strcat(tmp_body, qp.poem_list[poem_index].name);
strcat(tmp_body, "(");
if (qp.poem_list[poem_index].num_args > 0){
//strcat(tmp_body, ", ");
for (int i = 0; i < qp.poem_list[poem_index].num_args; ++i){
for (int i = 0; i < qp.poem_list[poem_index].num_args; ++i){

if (qp.poem_list[poem_index].args[i].type != NULL){
strcat(tmp_body, qp.poem_list[poem_index].args[i].type);
strcat(tmp_body, " ");
}
strcat(tmp_body, qp.poem_list[poem_index].args[i].variable);
if (i == qp.poem_list[poem_index].num_args - 1){
strcat(tmp_body, "){\n");
}
else{
strcat(tmp_body, ", ");
}
if (qp.poem_list[poem_index].args[i].type != NULL){
strcat(tmp_body, qp.poem_list[poem_index].args[i].type);
strcat(tmp_body, " ");
}
strcat(tmp_body, qp.poem_list[poem_index].args[i].variable);
if (i == qp.poem_list[poem_index].num_args - 1 &&
qp.poem_list[poem_index].num_kwargs <= 0){
strcat(tmp_body, "){\n");
}
else{
strcat(tmp_body, ", ");
}
}
else {
for (int i = 0; i < qp.poem_list[poem_index].num_kwargs; ++i){

if (qp.poem_list[poem_index].kwargs[i].type != NULL){
strcat(tmp_body, qp.poem_list[poem_index].kwargs[i].type);
strcat(tmp_body, " ");
}
strcat(tmp_body, qp.poem_list[poem_index].kwargs[i].variable);
if (i == qp.poem_list[poem_index].num_kwargs - 1){
strcat(tmp_body, "){\n");
}
else{
strcat(tmp_body, ", ");
}
}

if (qp.poem_list[poem_index].num_kwargs <= 0 &&
qp.poem_list[poem_index].num_args <= 0){
strcat(tmp_body, "){\n");
}

Expand Down Expand Up @@ -276,6 +295,7 @@ void qb_free_poem(quibble_poem qp){
free(qp.body);
free(qp.name);
qb_free_arg_array(qp.args, qp.num_args);
qb_free_kwarg_array(qp.kwargs, qp.num_kwargs);
}

void qb_print_poem(quibble_poem qp){
Expand Down
15 changes: 14 additions & 1 deletion src/quibble_program.c
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,17 @@ void qb_configure_program(quibble_program *qp, int platform, int device){
for (int i = 0; i < qp->num_poems; ++i){

kernels[i] = clCreateKernel(qp->program, qp->poem_list[i].name, &err);
if (qp->poem_list[i].num_kwargs > 0){
for (int j = 0; j < qp->poem_list[i].num_kwargs; ++j){
void *data = qb_string_to_void(
qp->poem_list[i].kwargs[j].type,
qp->poem_list[i].kwargs[j].value
);
qb_set_arg(qp, qp->poem_list[i].name,
qp->poem_list[i].kwargs[j].variable,
data);
}
}
cl_check(err);
}

Expand Down Expand Up @@ -777,8 +788,10 @@ void qb_set_arg(quibble_program *qp, char *poem, char *arg, void *data){

qb_find_type_arg(arg, &type, &variable);

int arg_index = qb_find_arg_index(qp->poem_list[poem_index].args,
int arg_index = qb_find_any_index(qp->poem_list[poem_index].args,
qp->poem_list[poem_index].num_args,
qp->poem_list[poem_index].kwargs,
qp->poem_list[poem_index].num_kwargs,
variable);

size_t object_size = qb_find_type_size(type);
Expand Down