Skip to content

Commit 37289f9

Browse files
committed
work in progress
1 parent f3911d5 commit 37289f9

File tree

4 files changed

+56
-2
lines changed

4 files changed

+56
-2
lines changed

pyccel/codegen/compiling/compilers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ def _get_exec(self, accelerators):
137137
os.environ['PATH'] = current_path
138138

139139

140-
errors.report(f"Could not find compiler ({exec_cmd})",
141-
severity='fatal')
140+
# errors.report(f"Could not find compiler ({exec_cmd})",
141+
# severity='fatal')
142142

143143
return exec_loc
144144

pyccel/codegen/printing/cucode.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,17 @@
1515
from pyccel.ast.literals import Nil
1616

1717
from pyccel.errors.errors import Errors
18+
from pyccel.ast.core import Allocate, Deallocate
19+
1820

1921

2022
errors = Errors()
2123

2224
__all__ = ["CudaCodePrinter"]
2325

26+
c_imports = {n : Import(n, Module(n, (), ())) for n in
27+
['cuda_ndarrays',]}
28+
2429
class CudaCodePrinter(CCodePrinter):
2530
"""
2631
Print code in CUDA format.
@@ -133,4 +138,21 @@ def _print_ModuleHeader(self, expr):
133138
global_variables,
134139
function_declaration,
135140
"#endif // {name.upper()}_H\n"))
141+
def _print_Allocate(self, expr):
142+
self.add_import('cuda_ndarrays')
143+
free_code = ''
144+
145+
146+
#free the array if its already allocated and checking if its not null if the status is unknown
147+
# if (expr.status == 'unknown'):
148+
# free_code = 'if (%s.shape != NULL)\n' % self._print(expr.variable.name)
149+
# free_code += "{{\n{}}}\n".format(self._print(Deallocate(expr.variable)))
150+
# elif (expr.status == 'allocated'):
151+
# free_code += self._print(Deallocate(expr.variable))
152+
153+
alloc_code = f"{self._print(expr.variable)} = cuda_array_create();\n"
154+
return f'{alloc_code}'
155+
# print(shape)
156+
157+
# return "hjsjkahsjkajskasjkasj"
136158

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include "cuda_ndarrays.h"
2+
3+
void *cuda_array_create(int shape[])
4+
{
5+
size_t i = 0;
6+
size_t alloc_size = 1;
7+
8+
while (shape[i] != 0)
9+
{
10+
alloc_size *= shape[i];
11+
i++;
12+
}
13+
14+
void *array_ptr = malloc(alloc_size);
15+
if (array_ptr == NULL)
16+
{
17+
cout << "Error allocating memory" << endl;
18+
return NULL;
19+
}
20+
21+
return array_ptr;
22+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef CUDA_NDARRAYS_H
2+
# define CUDA_NDARRAYS_H
3+
4+
# include <cuda_runtime.h>
5+
# include <iostream>
6+
7+
using namespace std;
8+
9+
10+
#endif

0 commit comments

Comments
 (0)