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

VITIS-10034 Add Usage metrics for all XRT objects #7788

Merged
merged 6 commits into from
Nov 11, 2023

Conversation

rbramand-xilinx
Copy link
Collaborator

@rbramand-xilinx rbramand-xilinx commented Nov 7, 2023

Problem solved by the commit

Added new Usage metrics logger that logs info about XRT objects like device, buffer, hw context, kernel etc
This information is collected in thread safe manner and the info is dumped in JSON format to a file after application run finishes
The info collected and spec for this solution is captured in confluence page

Bug / issue (if any) fixed, which PR introduced the bug, how it was discovered

NA

How problem was solved, alternative solutions (if any) and why they were rejected

The proposed solution is explained in above confluence page

Risks (if any) associated the changes in the commit

Low

What has been tested and how, request additional testing if necessary

Tested with a simple multi threaded bandwidth application and was able to generate JSON file properly with necessary info
The following is the JSON dump generated with application that has 5 threads :

{
    "thread 0": {
        "device": {
            "device_index": "0",
            "bdf": "0000:3b:00.1",
            "bos_peak_count": "3",
            "global_bos": {
                "total_count": "1",
                "size": "67108864 bytes",
                "avg_size": "67108864 bytes",
                "peak_size": "67108864 bytes",
                "bytes_synced_to_device": "0 bytes",
                "bytes_synced_from_device": "0 bytes"
            },
            "hw_context": [
                {
                    "id": "0",
                    "xclbin_uuid": "b3b30b4a-5ded-3ee7-88a9-f9d0859459ea",
                    "bos": {
                        "total_count": "2",
                        "size": "134217728 bytes",
                        "avg_size": "67108864 bytes",
                        "peak_size": "67108864 bytes",
                        "bytes_synced_to_device": "67108864 bytes",
                        "bytes_synced_from_device": "67108864 bytes"
                    },
                    "kernels": [
                        {
                            "name": "bandwidth",
                            "num_of_args": "4",
                            "num_total_runs": "1",
                            "avg_run_time": "172652 us"
                        }
                    ]
                }
            ]
        }
    },
    "thread 1": {
        "device": {
            "device_index": "0",
            "bdf": "0000:3b:00.1",
            "bos_peak_count": "3",
            "global_bos": {
                "total_count": "1",
                "size": "67108864 bytes",
                "avg_size": "67108864 bytes",
                "peak_size": "67108864 bytes",
                "bytes_synced_to_device": "0 bytes",
                "bytes_synced_from_device": "0 bytes"
            },
            "hw_context": [
                {
                    "id": "0",
                    "xclbin_uuid": "b3b30b4a-5ded-3ee7-88a9-f9d0859459ea",
                    "bos": {
                        "total_count": "2",
                        "size": "134217728 bytes",
                        "avg_size": "67108864 bytes",
                        "peak_size": "67108864 bytes",
                        "bytes_synced_to_device": "67108864 bytes",
                        "bytes_synced_from_device": "67108864 bytes"
                    },
                    "kernels": [
                        {
                            "name": "bandwidth",
                            "num_of_args": "4",
                            "num_total_runs": "1",
                            "avg_run_time": "84010 us"
                        }
                    ]
                }
            ]
        }
    },
    "thread 2": {
        "device": {
            "device_index": "0",
            "bdf": "0000:3b:00.1",
            "bos_peak_count": "3",
            "global_bos": {
                "total_count": "1",
                "size": "67108864 bytes",
                "avg_size": "67108864 bytes",
                "peak_size": "67108864 bytes",
                "bytes_synced_to_device": "0 bytes",
                "bytes_synced_from_device": "0 bytes"
            },
            "hw_context": [
                {
                    "id": "0",
                    "xclbin_uuid": "b3b30b4a-5ded-3ee7-88a9-f9d0859459ea",
                    "bos": {
                        "total_count": "2",
                        "size": "134217728 bytes",
                        "avg_size": "67108864 bytes",
                        "peak_size": "67108864 bytes",
                        "bytes_synced_to_device": "67108864 bytes",
                        "bytes_synced_from_device": "67108864 bytes"
                    },
                    "kernels": [
                        {
                            "name": "bandwidth",
                            "num_of_args": "4",
                            "num_total_runs": "1",
                            "avg_run_time": "342594 us"
                        }
                    ]
                }
            ]
        }
    },
    "thread 3": {
        "device": {
            "device_index": "0",
            "bdf": "0000:3b:00.1",
            "bos_peak_count": "3",
            "global_bos": {
                "total_count": "1",
                "size": "67108864 bytes",
                "avg_size": "67108864 bytes",
                "peak_size": "67108864 bytes",
                "bytes_synced_to_device": "0 bytes",
                "bytes_synced_from_device": "0 bytes"
            },
            "hw_context": [
                {
                    "id": "0",
                    "xclbin_uuid": "b3b30b4a-5ded-3ee7-88a9-f9d0859459ea",
                    "bos": {
                        "total_count": "2",
                        "size": "134217728 bytes",
                        "avg_size": "67108864 bytes",
                        "peak_size": "67108864 bytes",
                        "bytes_synced_to_device": "67108864 bytes",
                        "bytes_synced_from_device": "67108864 bytes"
                    },
                    "kernels": [
                        {
                            "name": "bandwidth",
                            "num_of_args": "4",
                            "num_total_runs": "1",
                            "avg_run_time": "261316 us"
                        }
                    ]
                }
            ]
        }
    },
    "thread 4": {
        "device": {
            "device_index": "0",
            "bdf": "0000:3b:00.1",
            "bos_peak_count": "3",
            "global_bos": {
                "total_count": "1",
                "size": "67108864 bytes",
                "avg_size": "67108864 bytes",
                "peak_size": "67108864 bytes",
                "bytes_synced_to_device": "0 bytes",
                "bytes_synced_from_device": "0 bytes"
            },
            "hw_context": [
                {
                    "id": "0",
                    "xclbin_uuid": "b3b30b4a-5ded-3ee7-88a9-f9d0859459ea",
                    "bos": {
                        "total_count": "2",
                        "size": "134217728 bytes",
                        "avg_size": "67108864 bytes",
                        "peak_size": "67108864 bytes",
                        "bytes_synced_to_device": "67108864 bytes",
                        "bytes_synced_from_device": "67108864 bytes"
                    },
                    "kernels": [
                        {
                            "name": "bandwidth",
                            "num_of_args": "4",
                            "num_total_runs": "1",
                            "avg_run_time": "84019 us"
                        }
                    ]
                }
            ]
        }
    }
}

Documentation impact (if any)

NA

@gbuildx
Copy link
Collaborator

gbuildx commented Nov 7, 2023

Build Passed!

Copy link
Collaborator

@stsoe stsoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very good Rahul. Nice clean code.
Lots of comments. Let me know what you think, not all may be possible. We can meet and discuss.
Thank you for making this a manageable pull request. The changes are about what I can comprehend in one sitting :-)

src/runtime_src/core/common/api/hw_context_int.h Outdated Show resolved Hide resolved
src/runtime_src/core/common/api/hw_context_int.h Outdated Show resolved Hide resolved
src/runtime_src/core/common/api/kernel_int.h Outdated Show resolved Hide resolved
src/runtime_src/core/common/api/kernel_int.h Outdated Show resolved Hide resolved
src/runtime_src/core/common/shim/buffer_handle.h Outdated Show resolved Hide resolved
src/runtime_src/core/common/api/xrt_hw_context.cpp Outdated Show resolved Hide resolved
src/runtime_src/core/common/api/xrt_hw_context.cpp Outdated Show resolved Hide resolved
src/runtime_src/core/common/usage_metrics.h Outdated Show resolved Hide resolved
src/runtime_src/core/common/api/xrt_kernel.cpp Outdated Show resolved Hide resolved
src/runtime_src/core/common/api/xrt_kernel.cpp Outdated Show resolved Hide resolved
@rbramand-xilinx
Copy link
Collaborator Author

This is very good Rahul. Nice clean code. Lots of comments. Let me know what you think, not all may be possible. We can meet and discuss. Thank you for making this a manageable pull request. The changes are about what I can comprehend in one sitting :-)

Thanks Soren :)

@gbuildx
Copy link
Collaborator

gbuildx commented Nov 8, 2023

Build failed :(

Copy link
Collaborator

@stsoe stsoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some more changes. Please review.

src/runtime_src/core/common/usage_metrics.h Outdated Show resolved Hide resolved
src/runtime_src/core/common/usage_metrics.h Outdated Show resolved Hide resolved
src/runtime_src/core/common/usage_metrics.h Outdated Show resolved Hide resolved
src/runtime_src/core/common/usage_metrics.cpp Outdated Show resolved Hide resolved
src/runtime_src/core/common/usage_metrics.cpp Outdated Show resolved Hide resolved
src/runtime_src/core/common/api/xrt_hw_context.cpp Outdated Show resolved Hide resolved
src/runtime_src/core/common/usage_metrics.h Outdated Show resolved Hide resolved
src/runtime_src/core/common/usage_metrics.cpp Outdated Show resolved Hide resolved
src/runtime_src/core/common/api/xrt_kernel.cpp Outdated Show resolved Hide resolved
src/runtime_src/core/common/device.h Outdated Show resolved Hide resolved
@gbuildx
Copy link
Collaborator

gbuildx commented Nov 9, 2023

Build Passed!

Copy link
Collaborator

@stsoe stsoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am sorry to drag this on. But it is making good progress. Just need to get everything perfect :-)

src/runtime_src/core/common/usage_metrics.cpp Outdated Show resolved Hide resolved
src/runtime_src/core/common/usage_metrics.cpp Outdated Show resolved Hide resolved
src/runtime_src/core/common/usage_metrics.cpp Outdated Show resolved Hide resolved
src/runtime_src/core/common/usage_metrics.cpp Outdated Show resolved Hide resolved
@gbuildx
Copy link
Collaborator

gbuildx commented Nov 10, 2023

Build failed :(

src/runtime_src/core/common/usage_metrics.cpp Outdated Show resolved Hide resolved
src/runtime_src/core/common/usage_metrics.cpp Outdated Show resolved Hide resolved
src/runtime_src/core/common/usage_metrics.cpp Outdated Show resolved Hide resolved
src/runtime_src/core/common/usage_metrics.cpp Outdated Show resolved Hide resolved
src/runtime_src/core/common/usage_metrics.cpp Outdated Show resolved Hide resolved
src/runtime_src/core/common/usage_metrics.cpp Outdated Show resolved Hide resolved
src/runtime_src/core/common/usage_metrics.cpp Outdated Show resolved Hide resolved
@gbuildx
Copy link
Collaborator

gbuildx commented Nov 10, 2023

Build Passed!

@rbramand-xilinx rbramand-xilinx force-pushed the usage_metrics branch 2 times, most recently from 46ab03d to eb8dcbe Compare November 10, 2023 21:15
rbramand added 6 commits November 11, 2023 03:17
Copy link
Collaborator

@stsoe stsoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for working through all the changes. Looks good now. Reads well IMO.

@gbuildx
Copy link
Collaborator

gbuildx commented Nov 11, 2023

Build failed :(

@stsoe
Copy link
Collaborator

stsoe commented Nov 11, 2023

retest this please

@gbuildx
Copy link
Collaborator

gbuildx commented Nov 11, 2023

Build failed :(

@chvamshi-xilinx
Copy link
Collaborator

retest this please

@gbuildx
Copy link
Collaborator

gbuildx commented Nov 11, 2023

Build failed :(

@manikandan-xilinx
Copy link
Collaborator

retest this please. (PACT board test is failing repeatedly. So witching back from it )

@gbuildx
Copy link
Collaborator

gbuildx commented Nov 11, 2023

Build Passed!

@stsoe stsoe merged commit b041f00 into Xilinx:master Nov 11, 2023
3 checks passed
Copy link
Collaborator

@stsoe stsoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

usage_metrics_logger::
~usage_metrics_logger()
Copy link
Collaborator

m_dev_map[dev_id] = {};
try {
auto bdf = xrt_core::query::pcie_bdf::to_string(xrt_core::device_query<xrt_core::query::pcie_bdf>(dev));
m_dev_map[dev_id].bdf = bdf;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

namespace {
// global variables
static std::mutex m;
static uint32_t thread_count;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

~usage_metrics_logger()
{
{
std::lock_guard<std::mutex> lk(m);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move before 337 now that thread_count is atomic

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.

6 participants