summaryrefslogtreecommitdiff
path: root/src/codegen
diff options
context:
space:
mode:
authorZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-18 19:54:32 +0000
committerZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-18 19:54:32 +0000
commit8401c970ece366592dcbfaa0affe1a1a1bc18ac8 (patch)
treea83b2864e51782ae9a186b27fa6124eae8422357 /src/codegen
parentfc4abb77ecab8fe3c497e13d7f7d6d8f832514b2 (diff)
CUDA Interop, baby.
Diffstat (limited to 'src/codegen')
-rw-r--r--src/codegen/codegen.c64
-rw-r--r--src/codegen/codegen_utils.c17
2 files changed, 81 insertions, 0 deletions
diff --git a/src/codegen/codegen.c b/src/codegen/codegen.c
index 644e9f5..a371548 100644
--- a/src/codegen/codegen.c
+++ b/src/codegen/codegen.c
@@ -2252,6 +2252,70 @@ void codegen_node_single(ParserContext *ctx, ASTNode *node, FILE *out)
fprintf(out, ";\n");
}
break;
+ case NODE_CUDA_LAUNCH:
+ {
+ // Emit CUDA kernel launch: kernel<<<grid, block, shared, stream>>>(args);
+ ASTNode *call = node->cuda_launch.call;
+
+ // Get kernel name from callee
+ if (call->call.callee->type == NODE_EXPR_VAR)
+ {
+ fprintf(out, " %s<<<", call->call.callee->var_ref.name);
+ }
+ else
+ {
+ fprintf(out, " ");
+ codegen_expression(ctx, call->call.callee, out);
+ fprintf(out, "<<<");
+ }
+
+ // Grid dimension
+ codegen_expression(ctx, node->cuda_launch.grid, out);
+ fprintf(out, ", ");
+
+ // Block dimension
+ codegen_expression(ctx, node->cuda_launch.block, out);
+
+ // Optional shared memory size
+ if (node->cuda_launch.shared_mem || node->cuda_launch.stream)
+ {
+ fprintf(out, ", ");
+ if (node->cuda_launch.shared_mem)
+ {
+ codegen_expression(ctx, node->cuda_launch.shared_mem, out);
+ }
+ else
+ {
+ fprintf(out, "0");
+ }
+ }
+
+ // Optional CUDA stream
+ if (node->cuda_launch.stream)
+ {
+ fprintf(out, ", ");
+ codegen_expression(ctx, node->cuda_launch.stream, out);
+ }
+
+ fprintf(out, ">>>(");
+
+ // Arguments
+ ASTNode *arg = call->call.args;
+ int first = 1;
+ while (arg)
+ {
+ if (!first)
+ {
+ fprintf(out, ", ");
+ }
+ codegen_expression(ctx, arg, out);
+ first = 0;
+ arg = arg->next;
+ }
+
+ fprintf(out, ");\n");
+ break;
+ }
default:
codegen_expression(ctx, node, out);
fprintf(out, ";\n");
diff --git a/src/codegen/codegen_utils.c b/src/codegen/codegen_utils.c
index b1fcf4c..af1c862 100644
--- a/src/codegen/codegen_utils.c
+++ b/src/codegen/codegen_utils.c
@@ -535,6 +535,23 @@ void emit_func_signature(FILE *out, ASTNode *func, const char *name_override)
return;
}
+ // Emit CUDA qualifiers (for both forward declarations and definitions)
+ if (g_config.use_cuda)
+ {
+ if (func->func.cuda_global)
+ {
+ fprintf(out, "__global__ ");
+ }
+ if (func->func.cuda_device)
+ {
+ fprintf(out, "__device__ ");
+ }
+ if (func->func.cuda_host)
+ {
+ fprintf(out, "__host__ ");
+ }
+ }
+
// Return type
char *ret_str;
if (func->func.ret_type_info)