Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

Commit

Permalink
merge amd-stg-open into amd-mainline-open
Browse files Browse the repository at this point in the history
Change-Id: Ia4c19154ff566bbd95d249300a936d0f0afbcd78
  • Loading branch information
searlmc1 committed Apr 21, 2022
2 parents bd769ec + 4b1191a commit d999f17
Show file tree
Hide file tree
Showing 11 changed files with 545 additions and 172 deletions.
7 changes: 6 additions & 1 deletion ockl/src/cg.cl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*===------------------------------------------------------------------------*/

#include "irif.h"
#include "oclc.h"
#include "ockl.h"

#define AL(P) __opencl_atomic_load((__global atomic_uint *)P, memory_order_relaxed, memory_scope_all_svm_devices)
Expand All @@ -28,7 +29,11 @@ struct mg_info {
static inline size_t
get_mg_info_arg(void)
{
return ((__constant size_t *)__builtin_amdgcn_implicitarg_ptr())[6];
if (__oclc_ABI_version < 500) {
return ((__constant size_t *)__builtin_amdgcn_implicitarg_ptr())[6];
} else {
return ((__constant size_t *)__builtin_amdgcn_implicitarg_ptr())[11];
}
}

static inline bool
Expand Down
28 changes: 17 additions & 11 deletions ockl/src/dm.cl
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,6 @@ typedef struct heap_s {
#endif
} heap_t;

// TODO: get the heap pointer from the language runtime
static __global heap_t heap;
#define HEAP_POINTER &heap


// Inhibit control flow optimizations
#define O0(X) X = o0(X)
__attribute__((overloadable)) static int o0(int x) { int y; __asm__ volatile("; O0 %0" : "=v"(y) : "0"(x)); return y; }
Expand All @@ -190,8 +185,19 @@ __attribute__((overloadable)) static ulong o0(ulong x) { ulong y; __asm__ volati
#define AFO(P, V, O) __opencl_atomic_fetch_or (P, V, O, memory_scope_device)
#define ACE(P, E, V, O) __opencl_atomic_compare_exchange_strong(P, E, V, O, O, memory_scope_device)

// get the heap pointer
static __global heap_t *
get_heap_ptr(void) {
if (__oclc_ABI_version < 500) {
static __global heap_t heap;
return &heap;
} else {
return (__global heap_t *)((__constant size_t *)__builtin_amdgcn_implicitarg_ptr())[12];
}
}

// realtime
__attribute__((target("s-memrealtime")))static ulong
__attribute__((target("s-memrealtime"))) static ulong
realtime(void)
{
return __builtin_amdgcn_s_memrealtime();
Expand Down Expand Up @@ -382,7 +388,7 @@ non_slab_free(ulong addr)
uint nactive = active_lane_count();

if (aid == 0) {
__global heap_t *hp = HEAP_POINTER;
__global heap_t *hp = get_heap_ptr();
AFS(&hp->num_nonslab_allocations, nactive, memory_order_relaxed);
}
#endif
Expand All @@ -404,7 +410,7 @@ __ockl_dm_dealloc(ulong addr)
kind_t my_k = sptr->k;
sid_t my_i = sptr->i;

__global heap_t *hp = HEAP_POINTER;
__global heap_t *hp = get_heap_ptr();
int go = 1;
do {
o0(go);
Expand Down Expand Up @@ -446,7 +452,7 @@ non_slab_malloc(size_t sz)
uint nactive = active_lane_count();

if (aid == 0) {
__global heap_t *hp = HEAP_POINTER;
__global heap_t *hp = get_heap_ptr();
AFA(&hp->num_nonslab_allocations, nactive, memory_order_relaxed);
}
}
Expand Down Expand Up @@ -898,7 +904,7 @@ slab_malloc(int sz)
{
kind_t my_k = size_to_kind(sz);
__global void *ret = (__global void *)0;
__global heap_t *hp = HEAP_POINTER;
__global heap_t *hp = get_heap_ptr();

int k_go = 1;
do {
Expand Down Expand Up @@ -949,7 +955,7 @@ __ockl_dm_alloc(ulong sz)
ulong
__ockl_dm_nna(void)
{
__global heap_t *hp = HEAP_POINTER;
__global heap_t *hp = get_heap_ptr();
return AL(&hp->num_nonslab_allocations, memory_order_relaxed);
}
#endif
Expand Down
14 changes: 8 additions & 6 deletions ockl/src/hostcall.cl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* License. See LICENSE.TXT for details.
*===------------------------------------------------------------------------*/

#include "oclc.h"

/** \brief Internal implementation of hostcall.
*
* *** INTERNAL USE ONLY ***
Expand Down Expand Up @@ -42,12 +44,12 @@ __ockl_hostcall_preview(uint service_id,
ulong arg0, ulong arg1, ulong arg2, ulong arg3,
ulong arg4, ulong arg5, ulong arg6, ulong arg7)
{
// Retrieve the buffer pointer passed as an implicit kernel
// argument. This is at offset 3, which is the same as the OpenCL
// printf buffer.
__constant size_t *argptr =
(__constant size_t *)__builtin_amdgcn_implicitarg_ptr();
void *buffer = (void *)argptr[3];
void *buffer;
if (__oclc_ABI_version < 500) {
buffer = (__global void *)((__constant size_t *)__builtin_amdgcn_implicitarg_ptr())[3];
} else {
buffer = (__global void *)((__constant size_t *)__builtin_amdgcn_implicitarg_ptr())[10];
}

return __ockl_hostcall_internal(buffer, service_id, arg0, arg1, arg2, arg3,
arg4, arg5, arg6, arg7);
Expand Down
6 changes: 4 additions & 2 deletions ockl/src/wfbc.cl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ ulong
OCKL_MANGLE_U64(wfbcast)(ulong a, uint i)
{
uint j = __builtin_amdgcn_readfirstlane(i);
return ((ulong)__builtin_amdgcn_readlane((uint)(a >> 32), j) << 32) |
(ulong)__builtin_amdgcn_readlane((uint)a, j);
uint2 aa = __builtin_astype(a, uint2);
aa.x = __builtin_amdgcn_readlane(aa.x, j);
aa.y = __builtin_amdgcn_readlane(aa.y, j);
return __builtin_astype(aa, ulong);
}

Loading

0 comments on commit d999f17

Please sign in to comment.