diff --git a/projects/rocr-runtime/src/fmm.c b/projects/rocr-runtime/src/fmm.c index e89290bcd6..fcc234ee9c 100644 --- a/projects/rocr-runtime/src/fmm.c +++ b/projects/rocr-runtime/src/fmm.c @@ -40,7 +40,7 @@ #define INIT_MANAGEBLE_APERTURE(base_value, limit_value) { \ .base = (void *) base_value, \ .limit = (void *) limit_value, \ - .align = PAGE_SIZE, \ + .align = 0, \ .guard_pages = 1, \ .vm_ranges = NULL, \ .vm_objects = NULL, \ @@ -1392,11 +1392,14 @@ static int fmm_set_memory_policy(uint32_t gpu_id, int default_policy, int alt_po static uint32_t get_vm_alignment(uint32_t device_id) { + int page_size = 0; + if (device_id >= 0x6920 && device_id <= 0x6939) /* Tonga */ - return TONGA_PAGE_SIZE; - if (device_id >= 0x9870 && device_id <= 0x9877) /* Carrizo */ - return TONGA_PAGE_SIZE; - return PAGE_SIZE; + page_size = TONGA_PAGE_SIZE; + else if (device_id >= 0x9870 && device_id <= 0x9877) /* Carrizo */ + page_size = TONGA_PAGE_SIZE; + + return MAX(PAGE_SIZE, page_size); } HSAKMT_STATUS fmm_init_process_apertures(unsigned int NumNodes) diff --git a/projects/rocr-runtime/src/globals.c b/projects/rocr-runtime/src/globals.c index d055cecbde..15d6f11456 100644 --- a/projects/rocr-runtime/src/globals.c +++ b/projects/rocr-runtime/src/globals.c @@ -32,3 +32,5 @@ unsigned long kfd_open_count; unsigned long system_properties_count; pthread_mutex_t hsakmt_mutex = PTHREAD_MUTEX_INITIALIZER; bool is_dgpu = false; +int PAGE_SIZE; +int PAGE_SHIFT; diff --git a/projects/rocr-runtime/src/libhsakmt.h b/projects/rocr-runtime/src/libhsakmt.h index 437cf14582..be57fc59f1 100644 --- a/projects/rocr-runtime/src/libhsakmt.h +++ b/projects/rocr-runtime/src/libhsakmt.h @@ -49,8 +49,9 @@ extern bool is_dgpu; #define CHECK_KFD_OPEN() \ do { if (kfd_open_count == 0) return HSAKMT_STATUS_KERNEL_IO_CHANNEL_NOT_OPENED; } while (0) -#define PAGE_SIZE 4096 -#define PAGE_SHIFT 12 +extern int PAGE_SIZE; +extern int PAGE_SHIFT; + /* VI HW bug requires this virtual address alignment */ #define TONGA_PAGE_SIZE 0x8000 @@ -111,6 +112,14 @@ extern int kmtIoctl(int fd, unsigned long request, void *arg); #define VOID_PTR_SUB(ptr,n) (void*)((uint8_t*)(ptr) - n)/*ptr - offset*/ #define VOID_PTRS_SUB(ptr1,ptr2) (uint64_t)((uint8_t*)(ptr1) - (uint8_t*)(ptr2)) /*ptr1 - ptr2*/ +#define MIN(a, b) ({ \ + typeof(a) tmp1 = (a), tmp2 = (b); \ + tmp1 < tmp2 ? tmp1 : tmp2; }) + +#define MAX(a, b) ({ \ + typeof(a) tmp1 = (a), tmp2 = (b); \ + tmp1 > tmp2 ? tmp1 : tmp2; }) + void clear_events_page(void); void fmm_clear_all_mem(void); void clear_process_doorbells(void); diff --git a/projects/rocr-runtime/src/openclose.c b/projects/rocr-runtime/src/openclose.c index 3e0f5a8267..087fbdc36d 100644 --- a/projects/rocr-runtime/src/openclose.c +++ b/projects/rocr-runtime/src/openclose.c @@ -31,6 +31,7 @@ #include #include #include +#include #include "fmm.h" static const char kfd_device_name[] = "/dev/kfd"; @@ -69,6 +70,12 @@ static void clear_after_fork(void) kfd_open_count = 0; } +static inline void init_page_size(void) +{ + PAGE_SIZE = sysconf(_SC_PAGESIZE); + PAGE_SHIFT = ffs(PAGE_SIZE) - 1; +} + HSAKMT_STATUS HSAKMTAPI hsaKmtOpenKFD(void) @@ -99,6 +106,8 @@ hsaKmtOpenKFD(void) goto open_failed; } + init_page_size(); + result = topology_sysfs_get_system_props(&sys_props); if (result != HSAKMT_STATUS_SUCCESS) goto topology_sysfs_failed; diff --git a/projects/rocr-runtime/src/topology.c b/projects/rocr-runtime/src/topology.c index 99460f49ef..bcd25f91d6 100644 --- a/projects/rocr-runtime/src/topology.c +++ b/projects/rocr-runtime/src/topology.c @@ -38,8 +38,7 @@ #include "libhsakmt.h" #include "fmm.h" -#define PAGE_SIZE 4096 -#define MIN(X,Y) ((X) < (Y) ? (X) : (Y)) + /* Number of memory banks added by thunk on top of topology */ #define NUM_OF_IGPU_HEAPS 3 #define NUM_OF_DGPU_HEAPS 3