Wykres commitów

1052 Commity

Autor SHA1 Wiadomość Data
David Yat Sin dbae8da515 rocr: Fix memory leak on non-visible GPUs
Fix memory leak for memory regions objects when GPU is masked using
ROCR_VISIBLE_DEVICES.

Change-Id: I610842a18adbc3cdc854b12650844e271bc00592
2024-10-04 17:40:47 -04:00
Jonathan Kim 0ae064fe2d rocr: Use new extended graphics handle registration call on IPC import
To correctly map to all GPUs after an import, use the new extended
registration call that can import a virtual address without having to
specify a target node.

Change-Id: Ifca8f6f6ee24fa99b2af357dcc3ea1de3ab234f7
2024-10-03 14:06:37 -04:00
David Yat Sin 73f6bfa747 rocr/vmm: Only modify permisions for specified agents
When hsa_amd_vmem_set_access is called, do not remove permissions for
unspecified agents. Also updating documentation in header to clarify
this.

Change-Id: I3bb4cf08ba399f85cc67b17fd13a4a40d862415f
2024-09-30 17:41:58 -04:00
Jonathan Kim 909b82d463 rocr: Fix race condition in IPC DMABUF socket server
Socket server accept calls do not guarantee synchronous actions
post-accept. This can result in a race condition.

To resolve this, first limit the socket server's listen backlog to a
single connection. This will force competing clients to busy-retry
until timeout.

Second, make the DMABUF IPC file descriptor send-receive and import
calls into an atomic routine per connection.

By doing these fixes, not only to we resolve potential races but
we guarantee that any exporter process will create at most one
file descriptor that will only last for the duration of the import
transaction.  This alleviates any concern on running into system
limits for the number of open file descriptors per process.

Change-Id: I6d8b14795a680d89a2707e082fa027d525792e05
2024-09-27 14:40:59 -04:00
Jonathan Kim 32bb0764b7 rocr: Fix IPC DMA Buf fragment handling and enable for development
Discarding blocks for reallocation on IPC export for better memory
performance trigger memory violations with DMA BUF exports so bypass
this for now as application performance drops haven't been observed
with the bypass.

The raw fragment should be passed to the DMA Buf export call as well
since offsets will be implicitly applied in the Thunk/KFD for
export/import calls.

Also, use the agent information directly from the pointer
information so that the export call doesn't have to scan memory to find
this.  Pass the node ID in the handle so that the import call doesn't
have to make two thunk imports to fetch the node ID for GPU memory
imports.

Finally, allow the user to use DMA Buf IPC via
HSA_ENABLE_IPC_MODE_LEGACY=0 for developer testing as legacy mode will
be applied by default.

Change-Id: Ie8fe267f8768fa5df37126078406f7065f69ff4e
2024-09-27 14:40:42 -04:00
Young Hui b530e0f619 docs: move .readthedocs.yaml to the root of repo
Change-Id: I6c5afb806c47c029359a2dee2a7e73c6d076cfb1
2024-09-23 15:49:19 +00:00
Young Hui 75b674f0ad docs: path adjustments to allow documentation to build again
- adding doc files to .gitignore

Change-Id: Ia6b2358bb1f236298ad1d705c1bed0636026632d
2024-09-23 15:49:13 +00:00
Yiannis Papadopoulos 48fdc17179 rocr/aie: Correct reporting of dev heap size
Storing the correct dev heap size in the memory region.

Change-Id: I14b053330c187da1d7d0213256625e50795b9902
2024-09-20 12:44:23 -04:00
James Xu f3664fd124 rocr: Add nullptr check in IterateExecutables
When an entry is deleted from the array, it's set to nullptr
but not removed. Most other functions that
iterate over the array check if the entry is nullptr
but this loop in IterateExecutables did not.

Change-Id: I763b361eea59f6df201bb86ead0234e95f2cf79c
2024-09-19 19:44:53 +00:00
David Yat Sin 7f3dcd4e0b rocr: Add extended fine-grain memory on host
Change-Id: Id9317fee89b51a5097459255e0a3092820eff430
2024-09-19 19:44:53 +00:00
David Yat Sin 0af7a54ebe rocr: Return err when freeing invalid pointer
Return false if trying to free a NULL pointer (or invalid size)
internally in ROCr. This is to detect errors within ROCr when trying
to free NULL pointers. If a user of ROCr tries to free a NULL
pointer, this condition should be caught at the beginning of the
Runtime::FreeMemory(...) function and return HSA_STATUS_SUCCESS. This
matches the behavior of the free(...) or delete functions that
silently ignores calls when the passed a NULL pointer.

Change-Id: I84bc26928b35023e19cd9f214b42c6ee9508029c
2024-09-19 19:44:53 +00:00
David Yat Sin 561c44a4a9 rocr: extend agents_allow_access support VMM
Extend hsa_amd_agents_allow_access API to handle memory allocations done
via VMM APIs.

Change-Id: I4ae51d3e42dd104e98d513b1da86133d312a7203
2024-09-19 19:44:53 +00:00
David Yat Sin 8f1b05660a rocr: refactor VMemorySetAccess function
Refactor VMemorySetAccess so that it can be re-used in the following
patch.

Change-Id: I341241da7a59724bb3611172f0d26b0689d7bb46
2024-09-19 19:44:53 +00:00
Sam Wu 5506b9af7a Update rocm-docs-core to 1.8.0
Updating past rocm-docs-core 0.x.x requires Python 3.10 (specified in .readthedocs.yaml config)

Change-Id: I3421aa92cda62d48a1466046f1fdeb0a3abf3ef7
2024-09-19 19:44:53 +00:00
Tony Gutierrez 4bf102dc6b rocr/aie: Support VMEM handle creation
Adds support for AllocateMemoryOnly inside XDNA driver.

Move the IsLocalMemory() check inside the KFD driver
since the XDNA driver can, and needs to, create handles
on system memory buffer objects.

Changed handle variable name from thunk_handle to user_mode_driver_handle,
which is more representative if we support non-GPU drivers.

Change-Id: I95db9d575afd1ab0ff2de74cea5175d9a12a721b
2024-09-19 19:44:53 +00:00
Tony Gutierrez 54a459c05c rocr/aie: Allocate AIE queue's ring buf
Change-Id: I799a8223d695ec5c0ea2eaea012bc1b5d877e103
2024-09-19 19:44:53 +00:00
Tony Gutierrez a851f73da5 rocr/aie: Init mem regions for AIE agents
Change-Id: If180bdbcb3eb659f0d05a710526864494316d7a9
2024-09-19 19:44:53 +00:00
Tony Gutierrez 6abb993f65 rocr/aie: Add AMD AIE Embedded Runtime vendor packets
Adds support for the packet interface for interacting with
the Embedded Runtime (ERT) on AIE agents. The ERT is what
interprets command packets send to the AIE agent work
queues.

Change-Id: Id28fb98056b2c046354c446bdc9568d74385bea1
2024-09-19 19:44:53 +00:00
Tony Gutierrez 931733d51a rocr/aie: Add support for creating AIE queue context
Adds support for initialzing the XDNA driver so that
a hardware context can be created for an AIE queue.

Right now this initializes the device heap in the driver,
gets the relevant tile parameters for the AIE agent,
and creates a hardware context that backs the AIE queue.

Change-Id: Ib90e1bc67a8637f6db3ff2bebe34677843796417
2024-09-19 19:44:53 +00:00
David Yat Sin d6ec7b6489 rocr: Remove unnecessary function declarations
Change-Id: Ia2613ce74cac808f9239fc24049b57b7b1abaed9
2024-09-19 19:44:53 +00:00
David Yat Sin 12e299e8d4 rocr: Fix compile error
Change-Id: Iae6bf08e834a426f6f97cbc51d2a1a38199015bd
2024-09-19 19:44:53 +00:00
David Yat Sin 924e11ba7f rocr: Increase queue size for co-op queues
Increase queue-size for co-op queues to 16K to improve performance on
some workloads

Change-Id: I4d3bf0ecbd30ebb648b68d9c5fdabadc670a386c
2024-09-19 19:44:53 +00:00
Jonathan Kim 509e8d863a rocr: Reverse host-device copy engines on GFX94x
GFX 9.4.x has better performance for CPU-GPU copies when using
engines in reverse order from other devices.

Change-Id: I1eaebf0e837bb7f44712f40d5115df618f6a73d7
2024-09-06 19:02:59 -04:00
Jonathan Kim 24b25003b0 rocr: Fix backwards compatible host-device copies on target engines
If the KFD doesn't support targeting SDMA engines, ensure that ROCr
selects the correct downstream queue type by using an invalid engine.

Change-Id: Ia6848126f67f3d35ab37248633e8e0e6e2d77fff
2024-09-06 19:02:51 -04:00
Saleel Kudchadker 3baaa6e9c0 rocr: Allocate AQL queue on device memory
- Use HSA_ALLOCATE_QUEUE_DEV_MEM=1 to create AQL queue in device
memory.
- Before writing AQL packet header to the queue use an SFENCE to ensure
that there is no reodering of the writes over PCIE

Change-Id: I5eacdc35108c4a1e245c75ae349b7495451aa60d
2024-09-05 17:48:02 -04:00
Chris Freehill 7e13b9e62f hsakmt: Fix ROCr static lib build in new layout
Change-Id: Idc71524924b96a44d63be9b1d0fccbe0e328d96e
2024-09-05 10:26:06 -04:00
Tony Gutierrez 68669f4e1a rocr: Generalize AMD::MemoryRegion Allocate and Free
Remove KFD-specific Allocate/Free calls from the AMD::MemoryRegion.
The KFD-driver-specific Allocate/Free calls are now implemented in
the KfdDriver. Future changes will migrate the remaining KFD-specific
calls out of AMD::MemoryRegion.

This allows the MemoryRegion to be used across AMD drivers like the
XDNA driver.

Change-Id: Ib6a2a9e5e1a15e61644d2592beb3a8e6578c3010
2024-08-28 14:35:07 -07:00
Tony Gutierrez c42ff44a6a rocr/kfd-driver: Add initial KFD driver interface
Adds the initial KFD driver interface and use it to open the
KFD from amd_topology.cpp.

This change is to show the direction of the Driver interface for
initially supporting the KFD and to get feedback on the approach.
For now we wrap relevant ROCt calls behind this generic driver
interface so that we can generalize core ROCr components like
MemoryRegion, Runtime, etc.

Now that ROCt is incorporated into ROCr, we can more fully integrate
ROCt into the Driver interface. Ideally, we get to a point where
the generic Driver interface can support KFD, XDNA, and potential
future drivers.

Change-Id: I4573fd6af1f8398233ee9d3814d9f3139dd0279c
2024-08-28 14:34:54 -07:00
Tony Gutierrez 86f40ae489 rocr/xdna-driver: Initial support for amdxdna driver
Change-Id: I319b55d89dc644e7151228cb6c19d1a633171295
2024-08-28 14:34:39 -07:00
Shweta Khatri da69ffff0f Set internal cache for rocprofiler-register dependency
Change-Id: I8a661818c11c4de0df9743dacb78b7c5163b6da9
2024-08-28 14:48:51 -04:00
Tony Gutierrez 8ea62f1cea rocr/aie: Add initial support for AIE agents
This change adds the initial classes for the AIE agent and AIE AQL
queue.

An AIE agent list is added to the core runtime object.

Change-Id: I84b02f52171b80726dfb2c8431582a3ea2986eb3
2024-08-27 14:47:05 -07:00
David Yat Sin cb672ebcd1 Set ELF_GETSHDRSTRNDX when cxx compiler is not loaded
Change-Id: Ia26b8999909f688ce78d9bbe4cb2a7262df2ee02
2024-08-22 17:20:37 -04:00
David Yat Sin c8dd4d2b3b rocr: Handle pthread_create returning errors
Rewriting logic to fix issue where pthread_create would return errors
other than EINVAL, and these errors would be ignored.

Change-Id: I573958724dcf886c20e8c14e6a9182303b3ffa06
2024-08-22 12:15:10 -04:00
Lancelot SIX 3475a45137 rocr/amd_core_dump: Fix "arithmetic on a pointer to void"
A recent patch introduced a build failure when building with Clang:

    [ 65%] Building CXX object runtime/hsa-runtime/CMakeFiles/hsa-runtime64.dir/libamdhsacode/amd_core_dump.cpp.o
    […]/runtime/hsa-runtime/libamdhsacode/amd_core_dump.cpp:271:29: error: arithmetic on a pointer to void
      271 |       read = pread(fd_, buf + done, buf_size - done,
          |                         ~~~ ^
    1 error generated.

This patch fixes this by making sure the "void *" pointer is converting
to "char *" before doing arithmetic on it.

Change-Id: Ib1663ed30abce76e05f06d042975eccd7d729823
2024-08-21 17:19:28 -04:00
Jonathan Kim eb30a5bbc7 rocr: Memory copy based on recommended SDMA engines
Recommended SDMA engines for DMA copies are now exposed for better
GPU-GPU performance. ROCr can now select those DMA engines.

Also lock-in host-device copies to SDMA0 and device-host copies to
SDMA1 for better stability and performance.

Change-Id: Ideff2e13daf537104efecb8b837bd49ee5096cb5
2024-08-20 16:22:32 -04:00
Yifan Zhang 3f1f68c8cb libhsakmt: add OverrideEngineId property
When HSA_OVERRIDE_GFX_VERSION is used, save the overrided GFX
version to OverrideEngineId instead of original EngineId. There
are places where real GFX properties still needed, e.g. CWSR size
calculation.

Change-Id: I9d9149bae465b7cfe55604fc19e7ca34e48b7b1c
Signed-off-by: Yifan Zhang <yifan1.zhang@amd.com>
2024-08-20 09:10:52 -04:00
Lancelot Six 123b2c080a rocr/trap_handler_gfx12: Properly ignore HOST_TRAP and debug_trap
The current trap handler has 2 limitations:
1) If it receives a HOST_TRAP, it clears the corresponding bit
   and notifies the host, when it should not.
2) When it is entered because of a debug trap (s_trap 3) and the
   debugger is not attached, it returns unconditionally.  However,
   if another exception is reported at the same time as the trap
   handler is entered for the debug trap (a memory violation for
   example), that other exception ends-up being ignored.

This patch addresses both of those issues.  It makes it so host traps
and debug traps are ignored when necessary.  If any other exception is
reported to the wave, we halt the wave and notify the host, and if no
other exception is reported (i.e. we entered the trap handler because of
host trap or debug trap), we return to shader code.

Other minor defects are also fixed during this refactor:
- Fixed SQ_WAVE_EXCP_FLAG_PRIV_XNACK_ERROR_SHIFT which had an incorrect
  value
- Host traps can be sent at any time, including after we have halted a
  wave.  In such case, the old approach would have:
  1) cleared the trap ID saved in ttmp6
  2) clobbered ttmp10 where part of the actual wave's PC is saved.

Change-Id: I9ecd341f4967e686233dec182b3e5b0388ef19bd
2024-08-19 21:22:13 -04:00
David Yat Sin 88eaa834d0 Separate AsyncEventsLoop into two separate threads
This fixes an issue for missing HW events when out of HW events.

We cannot determine whether a HW event has occurred unless we call the
underlying drivers with hsaKmtWaitOnMultipleEvents_Ext. Previous logic
in Signal::WaitAny would switch to ACTIVE_WAIT state if we run out of
hardware events (signal->EopEvent() == NULL) and this would cause the
hsaKmtWaitOnMultipleEvents_Ext call to be skipped. But also, when we
have some signals without hardware events, calling
hsaKmtWaitOnMultipleEvents_Ext with a timeout of 0 so that we can poll
for remaining signals adds overhead with an IOCTL call and may cause
extra delay. Separating AsyncEventLoop into two separate threads so
that:

1. We can have a new Signal::WaitAnyExceptions to wait for HW events
This function can be simpler as it does not have to perform all the
timer calculations because it is expected to be always waiting on
hsaKmtWaitOnMultipleEvents_Ext through the lifetime of a process.

2. Signal::WaitAny does not need to have extra code to check for HW
exceptions as it only needs to handle HSA_EVENTTYPE_SIGNAL events. It
can also skip the calls to hsaKmtWaitOnMultipleEvents_Ext if needed.

Change-Id: I52ba99fd6e483e0cb477b7931a0dcc03520aa523
Signed-off-by: David Yat Sin <David.YatSin@amd.com>
2024-08-19 17:54:11 -04:00
David Yat Sin 56ba584a22 rocr: Delete internal CP queues in GPU agent destructor
Delete queues used internally in agent destructor to make sure any
memory allocated by the queue objects are freed before the agent memory
regions are destroyed.

Change-Id: I4768c9cf66f77ac00a5a355f373f7f22dc266e47
2024-08-19 17:16:46 -04:00
David Yat Sin 921471bd94 Raise system error when memory free is denied
If user application tries to free memory that is currently being used by
the underlying HW device, the hsaKmtFreeMemory function call will fail.

This would be caused by an incorrect call by the user application. A
system memory error is raised and the user application is expected to
abort when this happens.

Note: This leaves the allocation_map_ table in an inconsistent state as
this address entry is removed from it while the pointer is not actually
free'd. But re-organising the FreeMemory() function would require the
memory_lock_ to be held for much longer and may affect performance.
Since this is a very unlikely and invalid use case, we prefer to leave
the FreeMemory() function as is.

Change-Id: I24279eb98620c32d34f4c5ad1b7a0a30cb65835d
Signed-off-by: David Yat Sin <David.YatSin@amd.com>
2024-08-19 14:03:12 -04:00
David Yat Sin aae4dab88e Do not generate coredump on VM fault signal event
Skip coredump generation when receiving HSA_STATUS_ERROR_MEMORY_FAULT.
We also receive a system error of type HSA_EVENTTYPE_MEMORY and generate
the coredump there. Trying to generate coredump from 2 places sometimes
causes unnecessary error message because both places try to create a
coredump file with the same name.

Change-Id: If3f03bab2c24ad71dfeff39ab411bb9ac08b337e
Signed-off-by: David Yat Sin <David.YatSin@amd.com>
2024-08-19 13:21:26 -04:00
David Yat Sin 5f943dc44e Fix compile warnings
Removing unused variables

Change-Id: I3a9811e40c9bc735d13a0330b2015576ed112026
Signed-off-by: David Yat Sin <David.YatSin@amd.com>
2024-08-19 13:21:08 -04:00
Shweta.Khatri fda2a395a3 PC-Sampling - gfx94x Hosttrap method support
Supports PC-Sampling on gfx94x in both CPX and SPX mode

Change-Id: Ife1e50ab08155678ea4aa2b80475b9974812c40e
2024-08-19 13:20:42 -04:00
Lancelot Six 3646064a0e coredump: Print diagnostic in stderr when errors are detected
This patch adds output (to stderr) to indicate step in the core dump
creation failed to improve debuggability.

Change-Id: I349692e278c2d744136d7fba7f7c2e5a7ada0c06
Signed-off-by: David Yat Sin <David.YatSin@amd.com>
2024-08-19 13:20:20 -04:00
Lancelot Six 3e0d3d6d61 coredump: Improve error handling when reading VRAM
It is possible for the runtime to receive an interrupt while trying to
access VRAM data using /proc/self/mem.  In such case, pread(2) would
return -1 and set errno to -EINTR.  This is not an error case, the
pread(2) call just need to be restarted, however current implementation
would tread it as an error.

This patch changes the the implementation to correctly retry on EINTR.
While at it, this patch also handles cases where pread(2) reads less
data than originally requested.

Change-Id: I6a72fc5eda4afd90319f0d24b35c9eac6d1ff41c
Signed-off-by: David Yat Sin <David.YatSin@amd.com>
2024-08-19 12:20:22 -04:00
David Yat Sin 1d1d402dcc Do not allow default mem_flags
Force mem_flags to be explicit passed in then calling Queue constructor
to avoid ambiguity with calls to Queue constructor trying to only pass
the agent_node_id.

Change-Id: Ib6fedcb9e52d6c9f35f9051dfa989343456ca368
Signed-off-by: David Yat Sin <David.YatSin@amd.com>
2024-08-19 12:19:32 -04:00
Swati Rawat 4cb5c509f9 Tagging APIs from hsa_ext_amd.h for Doxygen
Change-Id: I2ab2358985442647cedbd99eca5b1140cb0b0680
Signed-off-by: David Yat Sin <David.YatSin@amd.com>
2024-08-19 12:17:20 -04:00
Shweta.Khatri 8176a8830f Adjusted indentation with tabs
No functional change

Change-Id: Ibe97b03f62c4affcb60d3469312c8a0b6eb11391
Signed-off-by: David Yat Sin <David.YatSin@amd.com>
2024-08-19 12:16:58 -04:00
James Xu a621bca303 Fix compile errors with musl>=1.2.3
Patch submitted on behalf of user AngryLoki:

The fix repeats common pattern, used for musl, 
e.g: https://github.com/void-linux/void-packages/blob/5ccf1c66a1df2d644e1a0db0a68fca321469c57e/srcpkgs/MangoHud/patches/0001-elfhacks-d_un.d_ptr-is-relative-on-non-glibc-systems.patch#L90.

Quoting:
d_un.d_ptr is relative on non glibc systems

elf(5) documents it this way, glibc diverts from this documentation

Change-Id: I815f88f127ef00c88ae827a8ad48df0d33c92467
2024-08-19 11:02:29 -04:00
Jonathan Kim ea646cf958 Disable DMABUF IPC iplementation
Current DMABUF implemenation is unstable.  Switch back to legacy
support for now.

Change-Id: I3be871f38c6524b0bcc9225bab61de4e57771efb
2024-08-12 13:14:14 -04:00