Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[math] Fix taichi custom operator on gpu backend #655

Merged
merged 1 commit into from
Mar 22, 2024
Merged
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
30 changes: 15 additions & 15 deletions brainpy/_src/math/op_register/taichi_aot_based.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,11 @@ def _preprocess_kernel_call_cpu(

def _preprocess_kernel_call_gpu(
source_md5_encode: str,
ins: dict,
outs: dict,
ins: Sequence,
outs: Sequence,
) -> bytes:
if len(ins) + len(outs) > 8:
raise ValueError('The number of ins and outs must be less than 8!')
# if len(ins) + len(outs) > 8:
# raise ValueError('The number of ins and outs must be less than 8!')
kernel_path = os.path.join(kernels_aot_path, source_md5_encode)

# other args
Expand All @@ -331,18 +331,18 @@ def _preprocess_kernel_call_gpu(
in_out_elem_count_list = [0] * param_total_num
in_out_shape_list = [0] * param_total_num * 8

for i, value in enumerate(ins.values()):
in_out_type_list[i] = type_number_map[value[0]]
in_out_dim_count_list[i] = len(value[1])
in_out_elem_count_list[i] = reduce(lambda x, y: x * y, value[1])
for j, dim in enumerate(value[1]):
for i, value in enumerate(ins):
in_out_type_list[i] = type_number_map[value.dtype]
in_out_dim_count_list[i] = value.ndim
in_out_elem_count_list[i] = value.size
for j, dim in enumerate(value.shape):
in_out_shape_list[i * 8 + j] = dim

for i, value in enumerate(outs.values()):
in_out_type_list[i + len(ins)] = type_number_map[value[0]]
in_out_dim_count_list[i + len(ins)] = len(value[1])
in_out_elem_count_list[i + len(ins)] = reduce(lambda x, y: x * y, value[1])
for j, dim in enumerate(value[1]):
for i, value in enumerate(outs):
in_out_type_list[i + len(ins)] = type_number_map[value.dtype]
in_out_dim_count_list[i + len(ins)] = value.ndim
in_out_elem_count_list[i + len(ins)] = value.size
for j, dim in enumerate(value.shape):
in_out_shape_list[(i + len(ins)) * 8 + j] = dim

# covert to string
Expand Down Expand Up @@ -407,7 +407,7 @@ def _compile_kernel(abs_ins, kernel, platform: str, **kwargs):
# returns
if platform in ['gpu', 'cuda']:
import_brainpylib_gpu_ops()
opaque = _preprocess_kernel_call_gpu(source_md5_encode, ins_dict, outs_dict)
opaque = _preprocess_kernel_call_gpu(source_md5_encode, abs_ins, abs_outs)
return opaque
elif platform == 'cpu':
import_brainpylib_cpu_ops()
Expand Down
Loading