Skip to content

Add simple multiply2 XNNPACK example - #1

Merged
ramiro050 merged 1 commit into
xnnpackfrom
add-mul2
Oct 18, 2023
Merged

ramiro050 merged 1 commit into
xnnpackfrom
add-mul2

Conversation

@ramiro050

Copy link
Copy Markdown
Owner

This commit replaces the multiplication of tensors in the system plugin example with a call to XNNPACK's multiply2. The plugin runs e2e correctly.

Note: the CMake changes are very hacky. I just needed to get the ball rolling.

@ramiro050

Copy link
Copy Markdown
Owner Author

Running:

../iree-build/tools/iree-run-module \
                              --device=local-sync \
                              --executable_plugin=../iree-build/samples/custom_dispatch/cpu/plugin/system_plugin.so \
                              --function=mixed_invocation \
                              --input=8xf32=2 \
                              --input=8xf32=4 \
                              --module=/tmp/example.vmfb

produces:

EXEC @mixed_invocation
processor_id=4
processor_data[0]=1F0CC0F
mul2[0:0](2 * 4 = 8)
mul2[0:1](2 * 4 = 8)
mul2[0:2](2 * 4 = 8)
mul2[0:3](2 * 4 = 8)
mul2[0:4](2 * 4 = 8)
mul2[0:5](2 * 4 = 8)
mul2[0:6](2 * 4 = 8)
mul2[0:7](2 * 4 = 8)
result[0]: hal.buffer_view
8xf32=12 12 12 12 12 12 12 12

This commit replaces the multiplication of tensors in the system
plugin example with a call to XNNPACK's multiply2. The plugin runs e2e
correctly.

Note: the CMake changes can definitely be improved. I just needed to
get the ball rolling.
@okkwon

okkwon commented Oct 18, 2023

Copy link
Copy Markdown
Collaborator

Do you know why the output values are all 12 instead of 8?

@okkwon

okkwon commented Oct 18, 2023

Copy link
Copy Markdown
Collaborator

It would be nice to create a new folder for the work. Otherwise, it is really a good start!

@ramiro050

Copy link
Copy Markdown
Owner Author

Do you know why the output values are all 12 instead of 8?

Yeah, there is an extra add in the example MLIR to show that you can mix external calls with builtin MLIR ops:

%0 = flow.dispatch @executable::@simple_mul[%dim](%arg0, %arg1, %dim) : (tensor<?xf32>{%dim}, tensor<?xf32>{%dim}, index) -> tensor<?xf32>{%dim}
// Code gen some other ops - these will interleave with hand-authored
// ones but naturally won't be able to fuse with them.
%1 = arith.addf %0, %arg1 : tensor<?xf32>

@ramiro050

Copy link
Copy Markdown
Owner Author

It would be nice to create a new folder for the work. Otherwise, it is really a good start!

Agreed! I'll refactor things in a follow up patch.

@ramiro050
ramiro050 merged commit ee0377a into xnnpack Oct 18, 2023
@ramiro050
ramiro050 deleted the add-mul2 branch October 18, 2023 17:08
ramiro050 pushed a commit that referenced this pull request Dec 19, 2023
…e_thread_request_affinity` (iree-org#15499)

TSan report:

```
WARNING: ThreadSanitizer: data race (pid=45817)
  Read of size 4 at 0x0001084004e0 by thread T2:
    #0 iree_thread_request_affinity threading_darwin.c:230 (local-task_vmvx_semaphore_submission_test:arm64+0x100078f40)
    #1 iree_task_worker_main worker.c:385 (local-task_vmvx_semaphore_submission_test:arm64+0x100071594)
    #2 iree_thread_start_routine threading_darwin.c:72 (local-task_vmvx_semaphore_submission_test:arm64+0x100078e3c)

  Previous write of size 4 at 0x0001084004e0 by main thread:
    #0 iree_thread_create threading_darwin.c:140 (local-task_vmvx_semaphore_submission_test:arm64+0x100078ca4)
    #1 iree_task_worker_initialize worker.c:66 (local-task_vmvx_semaphore_submission_test:arm64+0x1000714f8)
    #2 iree_task_executor_create executor.c:161 (local-task_vmvx_semaphore_submission_test:arm64+0x10006b2b0)
```

The read of `thread->mach_port` at
https://github.com/openxla/iree/blob/ccc4c3719cea467477a783f1c9e9f1fc06b4c508/runtime/src/iree/base/internal/threading_darwin.c#L230

is not ordered relatively to the write of that variable in the parent
thread after `pthread_mach_thread_np` returns:
https://github.com/openxla/iree/blob/ccc4c3719cea467477a783f1c9e9f1fc06b4c508/runtime/src/iree/base/internal/threading_darwin.c#L140

The proposed fix is that the worker thread shouldn't need to access its
own `thread->mach_port`, it can equivalently call `mach_task_self()`.
ramiro050 pushed a commit that referenced this pull request Dec 19, 2023
…e_thread_request_affinity` (iree-org#15499)

TSan report:

```
WARNING: ThreadSanitizer: data race (pid=45817)
  Read of size 4 at 0x0001084004e0 by thread T2:
    #0 iree_thread_request_affinity threading_darwin.c:230 (local-task_vmvx_semaphore_submission_test:arm64+0x100078f40)
    #1 iree_task_worker_main worker.c:385 (local-task_vmvx_semaphore_submission_test:arm64+0x100071594)
    #2 iree_thread_start_routine threading_darwin.c:72 (local-task_vmvx_semaphore_submission_test:arm64+0x100078e3c)

  Previous write of size 4 at 0x0001084004e0 by main thread:
    #0 iree_thread_create threading_darwin.c:140 (local-task_vmvx_semaphore_submission_test:arm64+0x100078ca4)
    #1 iree_task_worker_initialize worker.c:66 (local-task_vmvx_semaphore_submission_test:arm64+0x1000714f8)
    #2 iree_task_executor_create executor.c:161 (local-task_vmvx_semaphore_submission_test:arm64+0x10006b2b0)
```

The read of `thread->mach_port` at
https://github.com/openxla/iree/blob/ccc4c3719cea467477a783f1c9e9f1fc06b4c508/runtime/src/iree/base/internal/threading_darwin.c#L230

is not ordered relatively to the write of that variable in the parent
thread after `pthread_mach_thread_np` returns:
https://github.com/openxla/iree/blob/ccc4c3719cea467477a783f1c9e9f1fc06b4c508/runtime/src/iree/base/internal/threading_darwin.c#L140

The proposed fix is that the worker thread shouldn't need to access its
own `thread->mach_port`, it can equivalently call `mach_task_self()`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants