Skip to content

Commit

Permalink
Fix indexing with GPU backends.
Browse files Browse the repository at this point in the history
  • Loading branch information
athas committed Aug 15, 2024
1 parent e82244f commit b745206
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

* Interpreter no longer crashes on attributes in patterns.

* Fixes to array indexing through C API when using GPU backends.

## [0.25.19]

### Added
Expand Down
4 changes: 2 additions & 2 deletions src/Futhark/CodeGen/Backends/GenericC/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ recordArrayIndexFunctions space _types desc rank elemtype vds = do
-- variable.
copy
CopyNoBarrier
[C.cexp|&v->$id:(tupleField j)|]
[C.cexp|(unsigned char*)&v->$id:(tupleField j)|]
[C.cexp|0|]
DefaultSpace
[C.cexp|arr->$id:(tupleField j)->mem.mem|]
Expand All @@ -571,7 +571,7 @@ recordArrayIndexFunctions space _types desc rank elemtype vds = do
CopyNoBarrier
[C.cexp|v->$id:(tupleField j)->mem.mem|]
[C.cexp|0|]
DefaultSpace
space
[C.cexp|arr->$id:(tupleField j)->mem.mem|]
(indexExp pt r [C.cexp|arr->$id:(tupleField j)->shape|])
space
Expand Down
1 change: 1 addition & 0 deletions tests_lib/c/test_opaque_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ void test1(struct futhark_context *ctx) {

float out1_host[2];
assert(futhark_values_f32_1d(ctx, out1, out1_host) == 0);
assert(futhark_context_sync(ctx) == 0);
assert(memcmp(out1_host, b, sizeof(float)*2) == 0);

assert(futhark_free_opaque_7e1a81531cc3c23bb9093ed822aec320(ctx, out) == 0);
Expand Down
4 changes: 4 additions & 0 deletions tests_lib/c/test_record_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,25 @@ void test1(struct futhark_context *ctx) {
// Test indexing: in bounds.
struct futhark_opaque_tup2_i32_tup2_f32_f32* trip_fut;
assert(futhark_index_opaque_arr1d_tup2_i32_tup2_f32_f32(ctx, &trip_fut, a_b_b_fut, 1) == 0);
assert(futhark_context_sync(ctx) == 0); // XXX, would be nice if this was not required.
struct futhark_opaque_tup2_f32_f32* pair_fut;
assert(futhark_project_opaque_tup2_i32_tup2_f32_f32_1(ctx, &pair_fut, trip_fut) == 0);
{
int x;
assert(futhark_project_opaque_tup2_i32_tup2_f32_f32_0(ctx, &x, trip_fut) == 0);
assert(futhark_context_sync(ctx) == 0);
assert(x == a[1]);
}
{
float x;
assert(futhark_project_opaque_tup2_f32_f32_0(ctx, &x, pair_fut) == 0);
assert(futhark_context_sync(ctx) == 0);
assert(x == b[1]);
}
{
float x;
assert(futhark_project_opaque_tup2_f32_f32_1(ctx, &x, pair_fut) == 0);
assert(futhark_context_sync(ctx) == 0);
assert(x == b[1]);
}

Expand Down

0 comments on commit b745206

Please sign in to comment.