-
Notifications
You must be signed in to change notification settings - Fork 769
ITT stubs and wrappers for SPIR-V devices. #3279
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a985517
ITT stubs and compiler wrappers for SPIR-V devices.
e2e60cb
clang-format
47a8102
Removed \t.
391d0e3
Moved declarations to spirv_vars.h
ea511ff
Renamed itt_cmplr_wrappers.cpp
ab8c04c
Cleaned up names and added user wrappers.
2d9c6c6
clang-format
089a806
Revert changes that uncovered __spirv_GlobalInvocationId_x issue.
b5b3ff1
Added documentation.
e80f1b4
Fomatting fixed.
0c091bb
Updated __itt_atomic_mem_order_t enum.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
//==------- device_itt.h - ITT devicelib functions declarations ------------==// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//==------------------------------------------------------------------------==// | ||
|
||
#ifndef __LIBDEVICE_DEVICE_ITT_H__ | ||
#define __LIBDEVICE_DEVICE_ITT_H__ | ||
|
||
#include "device.h" | ||
|
||
#ifdef __SPIR__ | ||
#include "spirv_vars.h" | ||
|
||
#define ITT_STUB_ATTRIBUTES __attribute__((noinline, optnone)) | ||
|
||
/// Atomic operation type | ||
enum __itt_atomic_mem_op_t { | ||
__itt_mem_load = 0, | ||
__itt_mem_store = 1, | ||
__itt_mem_update = 2 | ||
}; | ||
|
||
/// Memory operation ordering semantic type | ||
enum __itt_atomic_mem_order_t { | ||
__itt_mem_order_relaxed = 0, | ||
__itt_mem_order_acquire = 1, | ||
__itt_mem_order_release = 2, | ||
__itt_mem_order_acquire_release = 3 | ||
}; | ||
|
||
// FIXME: must be enabled via -fdeclare-spirv-builtins | ||
DEVICE_EXTERN_C char __spirv_SpecConstant(int, char); | ||
|
||
#define ITT_SPEC_CONSTANT 0xFF747469 | ||
|
||
static inline bool isITTEnabled() { | ||
return __spirv_SpecConstant(ITT_SPEC_CONSTANT, 0) != 0; | ||
} | ||
|
||
// Wrapper APIs that may be called by compiler-generated code. | ||
// These are just parameterless helper APIs that call the corresponding | ||
// stub APIs after preparing the arguments for them. | ||
// | ||
// Note that we do not provide compiler wrappers for all stub APIs. | ||
// For example, there is no compiler wrapper for | ||
// __itt_offload_sync_acquired_stub, since the API's parameter cannot | ||
// be computed in the wrapper itself and has to be passed from outside. | ||
// If a compiler needs to invoke such an API, it has to use the user | ||
// visible API directly (i.e. __itt_offload_sync_acquired). | ||
DEVICE_EXTERN_C | ||
void __itt_offload_wi_start_wrapper(); | ||
DEVICE_EXTERN_C | ||
void __itt_offload_wi_finish_wrapper(); | ||
DEVICE_EXTERN_C | ||
void __itt_offload_wg_barrier_wrapper(); | ||
DEVICE_EXTERN_C | ||
void __itt_offload_wi_resume_wrapper(); | ||
|
||
// Non-inlinable and non-optimizable APIs that are recognized | ||
// by profiling tools. | ||
DEVICE_EXTERN_C ITT_STUB_ATTRIBUTES void | ||
__itt_offload_wi_start_stub(size_t *group_id, size_t wi_id, uint32_t wg_size); | ||
DEVICE_EXTERN_C ITT_STUB_ATTRIBUTES void | ||
__itt_offload_wi_finish_stub(size_t *group_id, size_t wi_id); | ||
DEVICE_EXTERN_C ITT_STUB_ATTRIBUTES void | ||
__itt_offload_wg_barrier_stub(uintptr_t barrier_id); | ||
DEVICE_EXTERN_C ITT_STUB_ATTRIBUTES void | ||
__itt_offload_wi_resume_stub(size_t *group_id, size_t wi_id); | ||
DEVICE_EXTERN_C ITT_STUB_ATTRIBUTES void | ||
__itt_offload_sync_acquired_stub(uintptr_t sync_id); | ||
DEVICE_EXTERN_C ITT_STUB_ATTRIBUTES void | ||
__itt_offload_sync_releasing_stub(uintptr_t sync_id); | ||
DEVICE_EXTERN_C ITT_STUB_ATTRIBUTES void | ||
__itt_offload_wg_local_range_stub(void *ptr, size_t size); | ||
DEVICE_EXTERN_C ITT_STUB_ATTRIBUTES void | ||
__itt_offload_atomic_op_start_stub(void *object, __itt_atomic_mem_op_t op_type, | ||
__itt_atomic_mem_order_t mem_order); | ||
DEVICE_EXTERN_C ITT_STUB_ATTRIBUTES void | ||
__itt_offload_atomic_op_finish_stub(void *object, __itt_atomic_mem_op_t op_type, | ||
__itt_atomic_mem_order_t mem_order); | ||
|
||
// User visible APIs. These may called both from user code and from | ||
// compiler generated code. | ||
DEVICE_EXTERN_C void __itt_offload_wi_start(size_t *group_id, size_t wi_id, | ||
uint32_t wg_size); | ||
DEVICE_EXTERN_C void __itt_offload_wi_finish(size_t *group_id, size_t wi_id); | ||
DEVICE_EXTERN_C void __itt_offload_wg_barrier(uintptr_t barrier_id); | ||
DEVICE_EXTERN_C void __itt_offload_wi_resume(size_t *group_id, size_t wi_id); | ||
DEVICE_EXTERN_C void __itt_offload_sync_acquired(uintptr_t sync_id); | ||
DEVICE_EXTERN_C void __itt_offload_sync_releasing(uintptr_t sync_id); | ||
DEVICE_EXTERN_C void __itt_offload_wg_local_range(void *ptr, size_t size); | ||
DEVICE_EXTERN_C void | ||
__itt_offload_atomic_op_start(void *object, __itt_atomic_mem_op_t op_type, | ||
__itt_atomic_mem_order_t mem_order); | ||
DEVICE_EXTERN_C void | ||
__itt_offload_atomic_op_finish(void *object, __itt_atomic_mem_op_t op_type, | ||
__itt_atomic_mem_order_t mem_order); | ||
|
||
#endif // __SPIR__ | ||
#endif // __LIBDEVICE_DEVICE_ITT_H__ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
//==--- itt_compiler_wrappers.cpp - compiler wrappers for ITT --------------==// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "device_itt.h" | ||
|
||
#ifdef __SPIR__ | ||
|
||
DEVICE_EXTERN_C | ||
void __itt_offload_wi_start_wrapper() { | ||
if (!isITTEnabled()) | ||
return; | ||
|
||
size_t GroupID[3] = {__spirv_BuiltInWorkgroupId.x, | ||
__spirv_BuiltInWorkgroupId.y, | ||
__spirv_BuiltInWorkgroupId.z}; | ||
size_t WIID = __spirv_BuiltInGlobalLinearId; | ||
uint32_t WGSize = static_cast<uint32_t>(__spirv_BuiltInWorkgroupSize.x * | ||
__spirv_BuiltInWorkgroupSize.y * | ||
__spirv_BuiltInWorkgroupSize.z); | ||
__itt_offload_wi_start_stub(GroupID, WIID, WGSize); | ||
} | ||
|
||
DEVICE_EXTERN_C | ||
void __itt_offload_wi_finish_wrapper() { | ||
if (!isITTEnabled()) | ||
return; | ||
|
||
size_t GroupID[3] = {__spirv_BuiltInWorkgroupId.x, | ||
__spirv_BuiltInWorkgroupId.y, | ||
__spirv_BuiltInWorkgroupId.z}; | ||
size_t WIID = __spirv_BuiltInGlobalLinearId; | ||
__itt_offload_wi_finish_stub(GroupID, WIID); | ||
} | ||
|
||
DEVICE_EXTERN_C | ||
void __itt_offload_wg_barrier_wrapper() { | ||
if (!isITTEnabled()) | ||
return; | ||
|
||
__itt_offload_wg_barrier_stub(0); | ||
} | ||
|
||
DEVICE_EXTERN_C | ||
void __itt_offload_wi_resume_wrapper() { | ||
if (!isITTEnabled()) | ||
return; | ||
|
||
size_t GroupID[3] = {__spirv_BuiltInWorkgroupId.x, | ||
__spirv_BuiltInWorkgroupId.y, | ||
__spirv_BuiltInWorkgroupId.z}; | ||
size_t WIID = __spirv_BuiltInGlobalLinearId; | ||
__itt_offload_wi_resume_stub(GroupID, WIID); | ||
} | ||
|
||
#endif // __SPIR__ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//==--- itt_stubs.cpp - stub functions for ITT ----------------------------==// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "device_itt.h" | ||
|
||
#ifdef __SPIR__ | ||
|
||
DEVICE_EXTERN_C ITT_STUB_ATTRIBUTES void | ||
__itt_offload_wi_start_stub(size_t *group_id, size_t wi_id, uint32_t wg_size) {} | ||
|
||
DEVICE_EXTERN_C ITT_STUB_ATTRIBUTES void | ||
__itt_offload_wi_finish_stub(size_t *group_id, size_t wi_id) {} | ||
|
||
DEVICE_EXTERN_C ITT_STUB_ATTRIBUTES void | ||
__itt_offload_wg_barrier_stub(uintptr_t barrier_id) {} | ||
|
||
DEVICE_EXTERN_C ITT_STUB_ATTRIBUTES void | ||
__itt_offload_wi_resume_stub(size_t *group_id, size_t wi_id) {} | ||
|
||
DEVICE_EXTERN_C ITT_STUB_ATTRIBUTES void | ||
__itt_offload_sync_acquired_stub(uintptr_t sync_id) {} | ||
DEVICE_EXTERN_C ITT_STUB_ATTRIBUTES void | ||
__itt_offload_sync_releasing_stub(uintptr_t sync_id) {} | ||
DEVICE_EXTERN_C ITT_STUB_ATTRIBUTES void | ||
__itt_offload_wg_local_range_stub(void *ptr, size_t size) {} | ||
DEVICE_EXTERN_C ITT_STUB_ATTRIBUTES void | ||
__itt_offload_atomic_op_start_stub(void *object, __itt_atomic_mem_op_t op_type, | ||
__itt_atomic_mem_order_t mem_order) {} | ||
DEVICE_EXTERN_C ITT_STUB_ATTRIBUTES void | ||
__itt_offload_atomic_op_finish_stub(void *object, __itt_atomic_mem_op_t op_type, | ||
__itt_atomic_mem_order_t mem_order) {} | ||
|
||
#endif // __SPIR__ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
//==--- itt_user_wrappers.cpp - user visible functions for ITT ------------==// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "device_itt.h" | ||
|
||
#ifdef __SPIR__ | ||
|
||
DEVICE_EXTERN_C void __itt_offload_wi_start(size_t *group_id, size_t wi_id, | ||
uint32_t wg_size) { | ||
if (isITTEnabled()) | ||
__itt_offload_wi_start_stub(group_id, wi_id, wg_size); | ||
} | ||
|
||
DEVICE_EXTERN_C void __itt_offload_wi_finish(size_t *group_id, size_t wi_id) { | ||
if (isITTEnabled()) | ||
__itt_offload_wi_finish_stub(group_id, wi_id); | ||
} | ||
|
||
DEVICE_EXTERN_C void __itt_offload_wg_barrier(uintptr_t barrier_id) { | ||
if (isITTEnabled()) | ||
__itt_offload_wg_barrier_stub(barrier_id); | ||
} | ||
|
||
DEVICE_EXTERN_C void __itt_offload_wi_resume(size_t *group_id, size_t wi_id) { | ||
if (isITTEnabled()) | ||
__itt_offload_wi_resume_stub(group_id, wi_id); | ||
} | ||
|
||
DEVICE_EXTERN_C void __itt_offload_sync_acquired(uintptr_t sync_id) { | ||
if (isITTEnabled()) | ||
__itt_offload_sync_acquired_stub(sync_id); | ||
} | ||
|
||
DEVICE_EXTERN_C void __itt_offload_sync_releasing(uintptr_t sync_id) { | ||
if (isITTEnabled()) | ||
__itt_offload_sync_releasing_stub(sync_id); | ||
} | ||
|
||
DEVICE_EXTERN_C void __itt_offload_wg_local_range(void *ptr, size_t size) { | ||
if (isITTEnabled()) | ||
__itt_offload_wg_local_range_stub(ptr, size); | ||
} | ||
|
||
DEVICE_EXTERN_C void | ||
__itt_offload_atomic_op_start(void *object, __itt_atomic_mem_op_t op_type, | ||
__itt_atomic_mem_order_t mem_order) { | ||
if (isITTEnabled()) | ||
__itt_offload_atomic_op_start_stub(object, op_type, mem_order); | ||
} | ||
|
||
DEVICE_EXTERN_C void | ||
__itt_offload_atomic_op_finish(void *object, __itt_atomic_mem_op_t op_type, | ||
__itt_atomic_mem_order_t mem_order) { | ||
if (isITTEnabled()) | ||
__itt_offload_atomic_op_finish_stub(object, op_type, mem_order); | ||
} | ||
|
||
#endif // __SPIR__ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.