Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

L0 adapter leaks events when no output event is given #1947

Open
steffenlarsen opened this issue Aug 7, 2024 · 1 comment
Open

L0 adapter leaks events when no output event is given #1947

steffenlarsen opened this issue Aug 7, 2024 · 1 comment
Labels
bug Something isn't working level-zero L0 adapter specific issues

Comments

@steffenlarsen
Copy link
Contributor

It seems that the L0 adapter does not correctly release "internal" events, i.e. events that are used by enqueued commands when there are no output event given the the API call. To illustrate this, the following SYCL code leaks an event:

#include <sycl/sycl.hpp>

int main() {
  sycl::queue Queue{{sycl::property::queue::in_order()}};
  sycl::ext::oneapi::experimental::single_task(Queue, []() {});
  Queue.wait();
  return 0;
}

When run with UR_L0_LEAKS_DEBUG=1 the output is:

Check balance of create/destroy calls
----------------------------------------------------------
               zeContextCreate = 1     \--->              zeContextDestroy = 1    
          zeCommandQueueCreate = 0     \--->         zeCommandQueueDestroy = 0    
                zeModuleCreate = 1     \--->               zeModuleDestroy = 1    
                zeKernelCreate = 1     \--->               zeKernelDestroy = 1    
             zeEventPoolCreate = 1     \--->            zeEventPoolDestroy = 1    
  zeCommandListCreateImmediate = 2     | 
           zeCommandListCreate = 0     \--->          zeCommandListDestroy = 2    
                 zeEventCreate = 1     \--->                zeEventDestroy = 0     ---> LEAK = 1
                 zeFenceCreate = 0     \--->                zeFenceDestroy = 0    
                 zeImageCreate = 0     \--->                zeImageDestroy = 0    
               zeSamplerCreate = 0     \--->              zeSamplerDestroy = 0    
              zeMemAllocDevice = 1     | 
                zeMemAllocHost = 1     | 
              zeMemAllocShared = 2     \--->                     zeMemFree = 4    
terminate called after throwing an instance of 'sycl::_V1::exception'
  what():  Native API failed. Native API returns: 11 (UR_RESULT_ERROR_INVALID_MEM_OBJECT)

which shows exactly one event creation and zero releases, corresponding to the internal event for the kernel enqueue. Note that this seems to affect most (if not all) enqueue functions that have an optional output event.

@steffenlarsen steffenlarsen added bug Something isn't working level-zero L0 adapter specific issues labels Aug 7, 2024
@pbalcer
Copy link
Contributor

pbalcer commented Aug 7, 2024

Related: #1297

steffenlarsen added a commit to steffenlarsen/llvm that referenced this issue Aug 7, 2024
Due to a bug in the L0 UR adapter, the profiling tag extension leaks
UR events on out-of-order queues. This is not due to the profiling tag
events themselves, but rather due to the need for a barrier enforcing
correct ordering of the inserted tag. Since the barrier ensures
completion prior to the profiling tag executing, the output event is not
needed, but the L0 adapter leaks the event if no output event is
specified. To combat this, this work-around passes an output event and
immediately frees it after the barrier has been submitted.

See oneapi-src/unified-runtime#1947.

Signed-off-by: Larsen, Steffen <[email protected]>
steffenlarsen added a commit to steffenlarsen/llvm that referenced this issue Aug 7, 2024
Due to a bug in the L0 UR adapter, the profiling tag extension leaks
UR events on out-of-order queues. This is not due to the profiling tag
events themselves, but rather due to the need for a barrier enforcing
correct ordering of the inserted tag. Since the barrier ensures
completion prior to the profiling tag executing, the output event is not
needed, but the L0 adapter leaks the event if no output event is
specified. To combat this, this work-around passes an output event and
immediately frees it after the barrier has been submitted.

See oneapi-src/unified-runtime#1947.

Signed-off-by: Larsen, Steffen <[email protected]>
steffenlarsen added a commit to intel/llvm that referenced this issue Aug 8, 2024
Due to a bug in the L0 UR adapter, the profiling tag extension leaks UR
events on out-of-order queues. This is not due to the profiling tag
events themselves, but rather due to the need for a barrier enforcing
correct ordering of the inserted tag. Since the barrier ensures
completion prior to the profiling tag executing, the output event is not
needed, but the L0 adapter leaks the event if no output event is
specified. To combat this, this work-around passes an output event and
immediately frees it after the barrier has been submitted.

See oneapi-src/unified-runtime#1947.

Signed-off-by: Larsen, Steffen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working level-zero L0 adapter specific issues
Projects
None yet
Development

No branches or pull requests

2 participants