Skip to content

Commit a2f66fe

Browse files
authored
Merge pull request #45 from OpenBioSim/fix_42
2 parents a6c9e9a + d1af54a commit a2f66fe

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Changelog
55
---------------------------------------------------------------------------------
66

77
* Please add an item to this CHANGELOG for any new features or bug fixes when creating a PR.
8+
* Fix OpenCL kernel address-space errors on AMD GPUs by placing program-scope constants in `__constant` memory and copying the GCMC target into private memory before calling `distance2` [#45](https://github.com/OpenBioSim/loch/pull/45).
89

910
[2026.2.0](https://github.com/openbiosim/loch/compare/2026.1.0...2026.2.0) - Sep 2026
1011
--------------------------------------------------------------------------------------

‎src/loch/_kernels.py‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#define KERNEL __kernel
3030
#define DEVICE
3131
#define GLOBAL __global
32+
#define CONSTANT __constant
3233
#define LOCAL __local
3334
#define GET_GLOBAL_ID(dim) get_global_id(dim)
3435
#define BLOCK_ID_Y get_group_id(1) // OpenCL: work-group ID in dimension 1
@@ -48,14 +49,15 @@
4849
#define KERNEL extern "C" __global__
4950
#define DEVICE __device__
5051
#define GLOBAL
52+
#define CONSTANT const
5153
#define LOCAL __shared__
5254
#define GET_GLOBAL_ID(dim) (threadIdx.x + blockIdx.x * blockDim.x)
5355
#define BLOCK_ID_Y blockIdx.y // CUDA: block index in y dimension
5456
#endif
5557
5658
// Constants.
57-
const float pi = 3.14159265359f;
58-
const float prefactor = 332.0637090025476f;
59+
CONSTANT float pi = 3.14159265359f;
60+
CONSTANT float prefactor = 332.0637090025476f;
5961
6062
// Maximum number of atoms per water molecule (for stack array sizing).
6163
#define MAX_POINTS 5
@@ -708,9 +710,16 @@
708710
v[1] = position[3 * idx + 1];
709711
v[2] = position[3 * idx + 2];
710712
713+
// Copy the target into private memory so the pointer address space
714+
// matches the distance2 signature on OpenCL.
715+
float tgt[3];
716+
tgt[0] = target[0];
717+
tgt[1] = target[1];
718+
tgt[2] = target[2];
719+
711720
// Calculate the distance between the water and the target.
712721
float r2;
713-
distance2(v, target, &r2, cell_matrix_inverse, metric_matrix);
722+
distance2(v, tgt, &r2, cell_matrix_inverse, metric_matrix);
714723
715724
// The water is within the GCMC sphere. Flag it as a candidate.
716725
if (r2 < radius * radius)

0 commit comments

Comments
 (0)