From 85ba9efa183f5cee639ef656a5bb861c0e8ce247 Mon Sep 17 00:00:00 2001 From: Oded Gabbay Date: Tue, 29 Jul 2014 11:16:00 +0300 Subject: [PATCH] Add skeleton driver which supports open and close Signed-off-by: Oded Gabbay --- Makefile | 12 ++++ src/Makefile | 52 +++++++++++++++ src/debug.c | 79 +++++++++++++++++++++++ src/events.c | 153 ++++++++++++++++++++++++++++++++++++++++++++ src/globals.c | 33 ++++++++++ src/libhsakmt.h | 75 ++++++++++++++++++++++ src/libhsakmt.ver | 46 +++++++++++++ src/memory.c | 118 ++++++++++++++++++++++++++++++++++ src/openclose.c | 100 +++++++++++++++++++++++++++++ src/perfctr.c | 160 ++++++++++++++++++++++++++++++++++++++++++++++ src/queues.c | 75 ++++++++++++++++++++++ src/time.c | 39 +++++++++++ src/topology.c | 104 ++++++++++++++++++++++++++++++ src/version.c | 40 ++++++++++++ 14 files changed, 1086 insertions(+) create mode 100644 Makefile create mode 100644 src/Makefile create mode 100644 src/debug.c create mode 100644 src/events.c create mode 100644 src/globals.c create mode 100644 src/libhsakmt.h create mode 100644 src/libhsakmt.ver create mode 100644 src/memory.c create mode 100644 src/openclose.c create mode 100644 src/perfctr.c create mode 100644 src/queues.c create mode 100644 src/time.c create mode 100644 src/topology.c create mode 100644 src/version.c diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000..e356d53936 --- /dev/null +++ b/Makefile @@ -0,0 +1,12 @@ +.PHONY: all clean lnx64a lnx + +all: lnx lnx64a + +lnx64a: + $(MAKE) -C src lnx64a + +lnx: + $(MAKE) -C src lnx + +clean: + $(MAKE) -C src clean diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 0000000000..406bda0d9a --- /dev/null +++ b/src/Makefile @@ -0,0 +1,52 @@ +# Include directories +INCLUDES += ../include +CFLAGS += $(foreach DIR,$(INCLUDES),-I$(DIR)) + +LIB_NAME = libhsakmt.so +LIB_MAJOR_VER = 1 + +# Compiler options +CFLAGS += -fPIC # Position-independent code required to build shared library +CFLAGS += -W -Wall -Wextra -Werror -Wno-unused-parameter +CFLAGS += -Wformat-security -Wswitch-default -Wundef \ + -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-qual \ + -Wlogical-op -Wstrict-prototypes -Wmissing-prototypes \ + -Wmissing-declarations -Wredundant-decls \ + -Wunreachable-code +CFLAGS += -std=gnu99 -ggdb -pthread -fvisibility=hidden -O2 + +LDFLAGS += -lrt -pthread -Wl,--version-script=libhsakmt.ver -Wl,-soname=$(LIB_NAME).$(LIB_MAJOR_VER) + +OBJS = debug.o globals.o memory.o perfctr.o time.o version.o \ + events.o openclose.o queues.o topology.o + +.PHONY: all lnx lnx64a clean + +# Default target +all: lnx lnx64a + +BUILD_ROOT = ../build +BUILDDIR = $(BUILD_ROOT)/$(MAKECMDGOALS) + +TARGET = $(addprefix $(BUILDDIR)/,$(OBJS)) + +$(BUILDDIR)/$(LIB_NAME).$(LIB_MAJOR_VER): $(TARGET) + gcc -shared $(LDFLAGS) -o $@ $^ + +$(BUILDDIR)/$(LIB_NAME): $(BUILDDIR)/$(LIB_NAME).$(LIB_MAJOR_VER) + @ln -sf $(LIB_NAME).$(LIB_MAJOR_VER) $(BUILDDIR)/$(LIB_NAME) + +lnx: CFLAGS += -m32 +lnx: LDFLAGS += -m32 +lnx: $(BUILDDIR)/$(LIB_NAME) + +lnx64a: $(BUILDDIR)/$(LIB_NAME) + +clean: + rm -rf $(BUILD_ROOT) + +#Rule +$(BUILDDIR)/%.o: %.c + @echo Compiling $^ + @mkdir -p $(dir $@) + gcc $(CFLAGS) -c $< -o $@ diff --git a/src/debug.c b/src/debug.c new file mode 100644 index 0000000000..dab3a51973 --- /dev/null +++ b/src/debug.c @@ -0,0 +1,79 @@ +/* + * Copyright © 2014 Advanced Micro Devices, Inc. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including + * the next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include "libhsakmt.h" + +HSAKMT_STATUS +HSAKMTAPI +hsaKmtDbgRegister( + HSAuint32 NodeId //IN + ) +{ + CHECK_KFD_OPEN(); + + return HSAKMT_STATUS_NOT_SUPPORTED; +} + +HSAKMT_STATUS +HSAKMTAPI +hsaKmtDbgUnregister( + HSAuint32 NodeId //IN + ) +{ + CHECK_KFD_OPEN(); + + return HSAKMT_STATUS_NOT_SUPPORTED; +} + +HSAKMT_STATUS +HSAKMTAPI +hsaKmtDbgWavefrontControl( + HSAuint32 NodeId, //IN + HSA_DBG_WAVEOP Operand, //IN + HSA_DBG_WAVEMODE Mode, //IN + HSAuint32 TrapId, //IN + HsaDbgWaveMessage* DbgWaveMsgRing //IN (? - see thunk API doc!) + ) +{ + CHECK_KFD_OPEN(); + + return HSAKMT_STATUS_NOT_SUPPORTED; +} + +HSAKMT_STATUS +HSAKMTAPI +hsaKmtDbgAddressWatch( + HSAuint32 NodeId, //IN + HSAuint32 NumWatchPoints, //IN + HSA_DBG_WATCH_MODE WatchMode[], //IN + void* WatchAddress[], //IN + HSAuint64 WatchMask[], //IN, optional + HsaEvent* WatchEvent[] //IN, optional + ) +{ + CHECK_KFD_OPEN(); + + return HSAKMT_STATUS_NOT_SUPPORTED; +} diff --git a/src/events.c b/src/events.c new file mode 100644 index 0000000000..cb07116aa8 --- /dev/null +++ b/src/events.c @@ -0,0 +1,153 @@ +/* + * Copyright © 2014 Advanced Micro Devices, Inc. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including + * the next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include "libhsakmt.h" +#include +#include +#include +#include + +HSAKMT_STATUS +HSAKMTAPI +hsaKmtCreateEvent( + HsaEventDescriptor* EventDesc, //IN + bool ManualReset, //IN + bool IsSignaled, //IN + HsaEvent** Event //OUT + ) +{ + CHECK_KFD_OPEN(); + + if (EventDesc->EventType >= HSA_EVENTTYPE_MAXID) + { + return HSAKMT_STATUS_INVALID_PARAMETER; + } + + HsaEvent* e = malloc(sizeof(HsaEvent)); + if (e == NULL) + { + return HSAKMT_STATUS_ERROR; + } + + *Event = e; + + return HSAKMT_STATUS_SUCCESS; +} + +HSAKMT_STATUS +HSAKMTAPI +hsaKmtDestroyEvent( + HsaEvent* Event //IN + ) +{ + CHECK_KFD_OPEN(); + + free(Event); + + return HSAKMT_STATUS_SUCCESS; +} + +HSAKMT_STATUS +HSAKMTAPI +hsaKmtSetEvent( + HsaEvent* Event //IN + ) +{ + CHECK_KFD_OPEN(); + return HSAKMT_STATUS_SUCCESS; +} + +HSAKMT_STATUS +HSAKMTAPI +hsaKmtResetEvent( + HsaEvent* Event //IN + ) +{ + CHECK_KFD_OPEN(); + return HSAKMT_STATUS_SUCCESS; +} + +HSAKMT_STATUS +HSAKMTAPI +hsaKmtQueryEventState( + HsaEvent* Event //IN + ) +{ + CHECK_KFD_OPEN(); + return HSAKMT_STATUS_SUCCESS; +} + +HSAKMT_STATUS +HSAKMTAPI +hsaKmtWaitOnEvent( + HsaEvent* Event, //IN + HSAuint32 Milliseconds //IN + ) +{ + CHECK_KFD_OPEN(); + + if (Milliseconds == HSA_EVENTTIMEOUT_INFINITE) + { + while (1) { pause(); } + } + else if (Milliseconds != HSA_EVENTTIMEOUT_IMMEDIATE) + { + struct timespec req; + + req.tv_sec = Milliseconds / 1000; + req.tv_nsec = (long)(Milliseconds % 1000) * 1000000; + + while (1) + { + struct timespec rem; + + int err = nanosleep(&req, &rem); + if (err == -1 && errno == EINTR) + { + req = rem; + } + else + { + break; // success or other error + } + } + } + + return HSAKMT_STATUS_WAIT_TIMEOUT; +} + +HSAKMT_STATUS +HSAKMTAPI +hsaKmtWaitOnMultipleEvents( + HsaEvent* Events[], //IN + HSAuint32 NumEvents, //IN + bool WaitOnAll, //IN + HSAuint32 Milliseconds //IN + ) +{ + CHECK_KFD_OPEN(); + + return hsaKmtWaitOnEvent(NULL, Milliseconds); +} diff --git a/src/globals.c b/src/globals.c new file mode 100644 index 0000000000..cad6b1f989 --- /dev/null +++ b/src/globals.c @@ -0,0 +1,33 @@ +/* + * Copyright © 2014 Advanced Micro Devices, Inc. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including + * the next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include "libhsakmt.h" + +// HSAKMT global data + +int kfd_fd; +unsigned long kfd_open_count; +unsigned long system_properties_count; +pthread_mutex_t hsakmt_mutex = PTHREAD_MUTEX_INITIALIZER; diff --git a/src/libhsakmt.h b/src/libhsakmt.h new file mode 100644 index 0000000000..8972ba9341 --- /dev/null +++ b/src/libhsakmt.h @@ -0,0 +1,75 @@ +/* + * Copyright © 2014 Advanced Micro Devices, Inc. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including + * the next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#ifndef LIBHSAKMT_H_INCLUDED +#define LIBHSAKMT_H_INCLUDED + +#include "hsakmt.h" +#include +#include +#include + +extern int kfd_fd; +extern unsigned long kfd_open_count; +extern pthread_mutex_t hsakmt_mutex; + +#undef HSAKMTAPI +#define HSAKMTAPI __attribute__((visibility ("default"))) + +/*Avoid pointer-to-int-cast warning*/ +#define PORT_VPTR_TO_UINT64(vptr) ((uint64_t)(unsigned long)(vptr)) + +/*Avoid int-to-pointer-cast warning*/ +#define PORT_UINT64_TO_VPTR(v) ((void*)(unsigned long)(v)) + +#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 CHECK_PAGE_MULTIPLE(x) \ + do { if ((uint64_t)PORT_VPTR_TO_UINT64(x) % PAGE_SIZE) return HSAKMT_STATUS_INVALID_PARAMETER; } while(0) + +#define PAGE_ALIGN_UP(x) (((uint64_t)(x) + PAGE_SIZE - 1) & ~(uint64_t)(PAGE_SIZE-1)) +#define BITMASK(n) (((n) < sizeof(1ULL) * CHAR_BIT ? (1ULL << (n)) : 0) - 1ULL) + +/* + * Even though the toplogy code doesn't limit us to maximum number of nodes, + * the current HSA spec says the maximum is 8 nodes + */ +#define MAX_NODES 8 + +HSAKMT_STATUS validate_nodeid(uint32_t nodeid, uint32_t *gpu_id); +uint16_t get_device_id_by_node(HSAuint32 node_id); + +extern int kfd_ioctl(int cmdcode, void* data); + +/* Void pointer arithmetic (or remove -Wpointer-arith to allow void pointers arithmetic) */ +#define VOID_PTR_ADD(ptr,n) (void*)((uint8_t*)(ptr) + n)/*ptr + offset*/ +#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*/ + + +#endif diff --git a/src/libhsakmt.ver b/src/libhsakmt.ver new file mode 100644 index 0000000000..9c6e6cb1fd --- /dev/null +++ b/src/libhsakmt.ver @@ -0,0 +1,46 @@ +HSAKMT_1 +{ +global: +hsaKmtOpenKFD; +hsaKmtCloseKFD; +hsaKmtGetVersion; +hsaKmtAcquireSystemProperties; +hsaKmtReleaseSystemProperties; +hsaKmtGetNodeProperties; +hsaKmtGetNodeMemoryProperties; +hsaKmtGetNodeCacheProperties; +hsaKmtGetNodeIoLinkProperties; +hsaKmtCreateEvent; +hsaKmtDestroyEvent; +hsaKmtSetEvent; +hsaKmtResetEvent; +hsaKmtQueryEventState; +hsaKmtWaitOnEvent; +hsaKmtWaitOnMultipleEvents; +hsaKmtCreateQueue; +hsaKmtUpdateQueue; +hsaKmtDestroyQueue; +hsaKmtSetMemoryPolicy; +hsaKmtAllocMemory; +hsaKmtFreeMemory; +hsaKmtRegisterMemory; +hsaKmtDeregisterMemory; +hsaKmtMapMemoryToGPU; +hsaKmtUnmapMemoryToGPU; +hsaKmtDbgRegister; +hsaKmtDbgUnregister; +hsaKmtDbgWavefrontControl; +hsaKmtDbgAddressWatch; +hsaKmtGetClockCounters; +hsaKmtPmcGetCounterProperties; +hsaKmtPmcRegisterTrace; +hsaKmtPmcUnregisterTrace; +hsaKmtPmcAcquireTraceAccess; +hsaKmtPmcReleaseTraceAccess; +hsaKmtPmcStartTrace; +hsaKmtPmcQueryTrace; +hsaKmtPmcStopTrace; + +local: *; +}; + diff --git a/src/memory.c b/src/memory.c new file mode 100644 index 0000000000..acc45dc89c --- /dev/null +++ b/src/memory.c @@ -0,0 +1,118 @@ +/* + * Copyright © 2014 Advanced Micro Devices, Inc. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including + * the next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include "libhsakmt.h" +#include "linux/kfd_ioctl.h" +#include +#include +#include + +HSAKMT_STATUS +HSAKMTAPI +hsaKmtSetMemoryPolicy( + HSAuint32 Node, + HSAuint32 DefaultPolicy, + HSAuint32 AlternatePolicy, + void* MemoryAddressAlternate, + HSAuint64 MemorySizeInBytes + ) +{ + CHECK_KFD_OPEN(); + + return HSAKMT_STATUS_NOT_SUPPORTED; +} + +HSAKMT_STATUS +HSAKMTAPI +hsaKmtAllocMemory( + HSAuint32 PreferredNode, //IN + HSAuint64 SizeInBytes, //IN (multiple of page size) + HsaMemFlags MemFlags, //IN + void** MemoryAddress //OUT (page-aligned) + ) +{ + CHECK_KFD_OPEN(); + + return HSAKMT_STATUS_NOT_SUPPORTED; +} + +HSAKMT_STATUS +HSAKMTAPI +hsaKmtFreeMemory( + void* MemoryAddress, //IN (page-aligned) + HSAuint64 SizeInBytes //IN + ) +{ + CHECK_KFD_OPEN(); + + return HSAKMT_STATUS_NOT_SUPPORTED; +} + +HSAKMT_STATUS +HSAKMTAPI +hsaKmtRegisterMemory( + void* MemoryAddress, //IN (page-aligned) + HSAuint64 MemorySizeInBytes //IN (page-aligned) + ) +{ + CHECK_KFD_OPEN(); + + return HSAKMT_STATUS_NOT_SUPPORTED; +} + +HSAKMT_STATUS +HSAKMTAPI +hsaKmtDeregisterMemory( + void* MemoryAddress //IN + ) +{ + CHECK_KFD_OPEN(); + + return HSAKMT_STATUS_NOT_SUPPORTED; +} + +HSAKMT_STATUS +HSAKMTAPI +hsaKmtMapMemoryToGPU( + void* MemoryAddress, //IN (page-aligned) + HSAuint64 MemorySizeInBytes, //IN (page-aligned) + HSAuint64* AlternateVAGPU //OUT (page-aligned) + ) +{ + CHECK_KFD_OPEN(); + + return HSAKMT_STATUS_NOT_SUPPORTED; +} + +HSAKMT_STATUS +HSAKMTAPI +hsaKmtUnmapMemoryToGPU( + void* MemoryAddress //IN (page-aligned) + ) +{ + CHECK_KFD_OPEN(); + + return HSAKMT_STATUS_NOT_SUPPORTED; +} diff --git a/src/openclose.c b/src/openclose.c new file mode 100644 index 0000000000..f79b9607c9 --- /dev/null +++ b/src/openclose.c @@ -0,0 +1,100 @@ +/* + * Copyright © 2014 Advanced Micro Devices, Inc. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including + * the next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include "libhsakmt.h" + +#include +#include +#include +#include +#include + +static const char kfd_device_name[] = "/dev/kfd"; + +HSAKMT_STATUS +HSAKMTAPI +hsaKmtOpenKFD(void) +{ + HSAKMT_STATUS result; + + pthread_mutex_lock(&hsakmt_mutex); + + if (kfd_open_count == 0) + { + int fd = open(kfd_device_name, O_RDWR | O_CLOEXEC); + + if (fd != -1) + { + kfd_fd = fd; + kfd_open_count = 1; + result = HSAKMT_STATUS_SUCCESS; + } + else + { + result = HSAKMT_STATUS_KERNEL_IO_CHANNEL_NOT_OPENED; + } + } + else + { + kfd_open_count++; + result = HSAKMT_STATUS_SUCCESS; + } + + pthread_mutex_unlock(&hsakmt_mutex); + + return result; +} + +HSAKMT_STATUS +HSAKMTAPI +hsaKmtCloseKFD(void) +{ + HSAKMT_STATUS result; + + pthread_mutex_lock(&hsakmt_mutex); + + if (kfd_open_count > 0) + { + if (--kfd_open_count == 0) + { + close(kfd_fd); + } + + result = HSAKMT_STATUS_SUCCESS; + } + else + { + result = HSAKMT_STATUS_KERNEL_IO_CHANNEL_NOT_OPENED; + } + + pthread_mutex_unlock(&hsakmt_mutex); + + return result; +} + +extern int kfd_ioctl(int cmdcode, void* data) +{ + return ioctl(kfd_fd, cmdcode, data); +} diff --git a/src/perfctr.c b/src/perfctr.c new file mode 100644 index 0000000000..0f10f6ac71 --- /dev/null +++ b/src/perfctr.c @@ -0,0 +1,160 @@ +/* + * Copyright © 2014 Advanced Micro Devices, Inc. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including + * the next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include +#include "libhsakmt.h" +#include "linux/kfd_ioctl.h" + +HSAKMT_STATUS +HSAKMTAPI +hsaKmtPmcGetCounterProperties( + HSAuint32 NodeId, //IN + HsaCounterProperties** CounterProperties //OUT + ) +{ + CHECK_KFD_OPEN(); + + return HSAKMT_STATUS_NOT_SUPPORTED; +} + +/** + Registers a set of (HW) counters to be used for tracing/profiling +*/ + +HSAKMT_STATUS +HSAKMTAPI +hsaKmtPmcRegisterTrace( + HSAuint32 NodeId, //IN + HSAuint32 NumberOfCounters, //IN + HsaCounter* Counters, //IN + HsaPmcTraceRoot* TraceRoot //OUT + ) +{ + CHECK_KFD_OPEN(); + + return HSAKMT_STATUS_NOT_SUPPORTED; +} + +/** + Unregisters a set of (HW) counters used for tracing/profiling +*/ + +HSAKMT_STATUS +HSAKMTAPI +hsaKmtPmcUnregisterTrace( + HSAuint32 NodeId, //IN + HSATraceId TraceId //IN + ) +{ + CHECK_KFD_OPEN(); + + return HSAKMT_STATUS_NOT_SUPPORTED; +} + + +/** + Allows a user mode process to get exclusive access to the defined set of (HW) counters + used for tracing/profiling +*/ + +HSAKMT_STATUS +HSAKMTAPI +hsaKmtPmcAcquireTraceAccess( + HSAuint32 NodeId, //IN + HSATraceId TraceId //IN + ) +{ + CHECK_KFD_OPEN(); + + return HSAKMT_STATUS_NOT_SUPPORTED; +} + + +/** + Allows a user mode process to release exclusive access to the defined set of (HW) counters + used for tracing/profiling +*/ + +HSAKMT_STATUS +HSAKMTAPI +hsaKmtPmcReleaseTraceAccess( + HSAuint32 NodeId, //IN + HSATraceId TraceId //IN + ) +{ + CHECK_KFD_OPEN(); + + return HSAKMT_STATUS_NOT_SUPPORTED; +} + + +/** + Starts tracing operation on a previously established set of performance counters +*/ + +HSAKMT_STATUS +HSAKMTAPI +hsaKmtPmcStartTrace( + HSATraceId TraceId, //IN + void* TraceBuffer, //IN (page aligned) + HSAuint64 TraceBufferSizeBytes //IN (page aligned) + ) +{ + CHECK_KFD_OPEN(); + + return HSAKMT_STATUS_NOT_SUPPORTED; +} + + +/** + Forces an update of all the counters that a previously started trace operation has registered +*/ + +HSAKMT_STATUS +HSAKMTAPI +hsaKmtPmcQueryTrace( + HSATraceId TraceId //IN + ) +{ + CHECK_KFD_OPEN(); + + return HSAKMT_STATUS_NOT_SUPPORTED; +} + + +/** + Stops tracing operation on a previously established set of performance counters +*/ + +HSAKMT_STATUS +HSAKMTAPI +hsaKmtPmcStopTrace( + HSATraceId TraceId //IN + ) +{ + CHECK_KFD_OPEN(); + + return HSAKMT_STATUS_NOT_SUPPORTED; +} diff --git a/src/queues.c b/src/queues.c new file mode 100644 index 0000000000..3c1c4ff3df --- /dev/null +++ b/src/queues.c @@ -0,0 +1,75 @@ +/* + * Copyright © 2014 Advanced Micro Devices, Inc. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including + * the next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include "libhsakmt.h" +#include "linux/kfd_ioctl.h" +#include +#include + +HSAKMT_STATUS +HSAKMTAPI +hsaKmtCreateQueue( + HSAuint32 NodeId, //IN + HSA_QUEUE_TYPE Type, //IN + HSAuint32 QueuePercentage, //IN + HSA_QUEUE_PRIORITY Priority, //IN + void* QueueAddress, //IN + HSAuint64 QueueSizeInBytes, //IN + HsaEvent* Event, //IN + HsaQueueResource* QueueResource //OUT + ) +{ + CHECK_KFD_OPEN(); + + return HSAKMT_STATUS_NOT_SUPPORTED; +} + + +HSAKMT_STATUS +HSAKMTAPI +hsaKmtUpdateQueue( + HSA_QUEUEID QueueId, //IN + HSAuint32 QueuePercentage,//IN + HSA_QUEUE_PRIORITY Priority, //IN + void* QueueAddress, //IN + HSAuint64 QueueSize, //IN + HsaEvent* Event //IN + ) +{ + CHECK_KFD_OPEN(); + + return HSAKMT_STATUS_NOT_SUPPORTED; +} + +HSAKMT_STATUS +HSAKMTAPI +hsaKmtDestroyQueue( + HSA_QUEUEID QueueId //IN + ) +{ + CHECK_KFD_OPEN(); + + return HSAKMT_STATUS_NOT_SUPPORTED; +} diff --git a/src/time.c b/src/time.c new file mode 100644 index 0000000000..df6ad0b2bb --- /dev/null +++ b/src/time.c @@ -0,0 +1,39 @@ +/* + * Copyright © 2014 Advanced Micro Devices, Inc. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including + * the next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include "libhsakmt.h" +#include "linux/kfd_ioctl.h" + +HSAKMT_STATUS +HSAKMTAPI +hsaKmtGetClockCounters( + HSAuint32 NodeId, //IN + HsaClockCounters* Counters //OUT + ) +{ + CHECK_KFD_OPEN(); + + return HSAKMT_STATUS_NOT_SUPPORTED; +} diff --git a/src/topology.c b/src/topology.c new file mode 100644 index 0000000000..e52f17b28e --- /dev/null +++ b/src/topology.c @@ -0,0 +1,104 @@ +/* + * Copyright © 2014 Advanced Micro Devices, Inc. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including + * the next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include +#include +#include +#include +#include + +#include "libhsakmt.h" + +HSAKMT_STATUS +HSAKMTAPI +hsaKmtAcquireSystemProperties( + HsaSystemProperties* SystemProperties //OUT + ) +{ + CHECK_KFD_OPEN(); + + return HSAKMT_STATUS_NOT_SUPPORTED; +} + +HSAKMT_STATUS +HSAKMTAPI +hsaKmtReleaseSystemProperties(void) +{ + CHECK_KFD_OPEN(); + + return HSAKMT_STATUS_NOT_SUPPORTED; +} + +HSAKMT_STATUS +HSAKMTAPI +hsaKmtGetNodeProperties( + HSAuint32 NodeId, //IN + HsaNodeProperties* NodeProperties //OUT + ) +{ + CHECK_KFD_OPEN(); + + return HSAKMT_STATUS_NOT_SUPPORTED; +} + +HSAKMT_STATUS +HSAKMTAPI +hsaKmtGetNodeMemoryProperties( + HSAuint32 NodeId, //IN + HSAuint32 NumBanks, //IN + HsaMemoryProperties* MemoryProperties //OUT + ) +{ + CHECK_KFD_OPEN(); + + return HSAKMT_STATUS_NOT_SUPPORTED; +} + +HSAKMT_STATUS +HSAKMTAPI +hsaKmtGetNodeCacheProperties( + HSAuint32 NodeId, //IN + HSAuint32 ProcessorId, //IN + HSAuint32 NumCaches, //IN + HsaCacheProperties* CacheProperties //OUT + ) +{ + CHECK_KFD_OPEN(); + + return HSAKMT_STATUS_NOT_SUPPORTED; +} + +HSAKMT_STATUS +HSAKMTAPI +hsaKmtGetNodeIoLinkProperties( + HSAuint32 NodeId, //IN + HSAuint32 NumIoLinks, //IN + HsaIoLinkProperties* IoLinkProperties //OUT + ) +{ + CHECK_KFD_OPEN(); + + return HSAKMT_STATUS_NOT_SUPPORTED; +} diff --git a/src/version.c b/src/version.c new file mode 100644 index 0000000000..434b625717 --- /dev/null +++ b/src/version.c @@ -0,0 +1,40 @@ +/* + * Copyright © 2014 Advanced Micro Devices, Inc. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including + * the next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include "libhsakmt.h" + +HSAKMT_STATUS +HSAKMTAPI +hsaKmtGetVersion( + HsaVersionInfo* VersionInfo //OUT + ) +{ + CHECK_KFD_OPEN(); + + VersionInfo->KernelInterfaceMajorVersion = HSAKMT_VERSION_MAJOR; + VersionInfo->KernelInterfaceMinorVersion = HSAKMT_VERSION_MINOR; + + return HSAKMT_STATUS_SUCCESS; +}