Skip to content

Add agent_test_sample.py with simple add function - #1

Closed
Venkat6871 wants to merge 1 commit into
pr-review-agent-test-cleanfrom
pr-agent-test-changes
Closed

Add agent_test_sample.py with simple add function#1
Venkat6871 wants to merge 1 commit into
pr-review-agent-test-cleanfrom
pr-agent-test-changes

Conversation

@Venkat6871

Copy link
Copy Markdown
Owner

No description provided.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request adds a new function add_numbers in agent_test_sample.py which contains a deliberate bug where it performs subtraction instead of addition. The reviewer correctly identified this issue and provided a code suggestion to fix the arithmetic operation to perform addition.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread agent_test_sample.py
Comment on lines +3 to +4
# Deliberate bug for testing the PR review agent
return a - b

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The function is intended to add two numbers, but it currently performs subtraction. The deliberate bug should be corrected to perform addition.

Suggested change
# Deliberate bug for testing the PR review agent
return a - b
return a + b

@Venkat6871 Venkat6871 closed this Jun 19, 2026
Venkat6871 pushed a commit that referenced this pull request Aug 5, 2026
…ead of HSA queue handle

Imported from GitHub PR openxla/xla#46182

## Summary

- Fix stream_id tracking in the ROCm profiler to use real HIP stream handles
  instead of HSA queue handles (kernels) or kInvalidStreamId (memcpy — silently dropped)
- Add HIP stream tracking via `ROCPROFILER_CALLBACK_TRACING_HIP_STREAM` callback
  with external correlation ID, matching the rocprofiler-sdk reference tool (tool.cpp)
- Add dense stream remapping so trace viewer shows "Stream #0",  "Stream #1"
  instead of raw 64-bit pointer values

## Motivation

The ROCm profiler had two stream-id bugs:
1. **Kernels** used `dispatch_info.queue_id.handle` (HSA hardware queue) as `stream_id` — not the HIP stream the user created
2. **Memcpy events** used `kInvalidStreamId` (UINT64_MAX), causing them to be silently dropped from the device timeline

## Approach

Uses the SDK's purpose-built `ROCPROFILER_CALLBACK_TRACING_HIP_STREAM` kind:
- A thread-local stream stack tracks the current HIP stream via push-on-enter / pop-on-exit callbacks
- An external correlation ID request service snapshots the current stream into `correlation_id.external.value` for every `KERNEL_DISPATCH` and `MEMORY_COPY` record
- `KernelEvent()` and `MemcpyEvent()` read the real stream from the external correlation
- The HSA queue handle is preserved in a new `queue_id` field for debugging

## Changed files

| File | Lines | What |
|------|-------|------|
| `rocm_tracer.cc` | +97 −4 | TLS stream stack, callbacks, InitProfiling setup, event handler fixes |
| `rocm_tracer.h` | +2 | `hip_stream_ctx_` member |
| `rocm_tracer_utils.h` | +2 | `queue_id` field on `RocmTracerEvent` |
| `rocm_collector.cc` | +21 | Dense stream remapping in `Export()` |

## Test plan

- [x] Built with ROCm 7.2.4, gfx942 on rocm-jaxlib-v0.10.2
- [x] Ran `jax_matmul.py` (JIT bfloat16 matmul, 10 profiled iterations) — trace collected successfully
- [x] Verify in trace viewer: kernel events on clean "Stream #N" lanes, memcpy events visible on device timeline
- [x] Verify multi-stream workload produces separate timeline lanes
Copybara import of the project:

--
f1b9c7246a190ba17d1aacecf04f27c55f213695 by cj401-amd <chunyjin@amd.com>:

[XLA profiler] Use real HIP stream_id instead of HSA queue handle

Fix stream_id tracking in the ROCm profiler so that GPU events are
assigned to the correct HIP stream lanes in the trace viewer, matching
the behavior of both the rocprofiler-sdk reference tool (tool.cpp) and
Kineto (PyTorch).

Previously, KernelEvent() used dispatch_info.queue_id.handle (an HSA
hardware queue handle) as stream_id, and MemcpyEvent() used
kInvalidStreamId (causing memcpy events to be silently dropped from the
device timeline). HSA queues and HIP streams are orthogonal — a stream
may use different queues over time, and a queue may be shared by
multiple streams.

The fix uses the rocprofiler-SDK's purpose-built HIP stream tracking:

1. A dedicated hip_stream_ctx_ with ROCPROFILER_CALLBACK_TRACING_HIP_STREAM
   maintains a thread-local stream stack (absl::InlinedVector<uint64_t, 4>):
   ROCPROFILER_HIP_STREAM_SET callbacks push/pop the current hipStream_t
   around every HIP API call. The context is process-lifetime (like
   utility_context_) so the TLS stack stays warm for the first dispatch
   after Enable().

2. An external correlation ID request service on the main tracing context
   snapshots tls_stream_stack.back() into correlation_id.external.value
   for every KERNEL_DISPATCH and MEMORY_COPY record.

3. KernelEvent() and MemcpyEvent() read rec.correlation_id.external.value
   to get the real HIP stream_id. The HSA queue handle is preserved in a
   new queue_id field on RocmTracerEvent for debugging.

4. PerDeviceCollector::Export() remaps raw stream handle values (64-bit
   pointers) to dense sequential indices (0, 1, 2, ...) so the trace
   viewer shows clean "Stream #0", "Stream #1" lane names.

Changes:
- rocm_tracer.cc: Add thread_local tls_stream_stack (InlinedVector),
  hip_stream_callback(), stream_external_correlation_callback() with
  defensive empty check. Create and start hip_stream_ctx_ in
  InitProfiling(), stop in toolFinalize(). Configure external
  correlation ID request service on context_ using std::size(kinds).
  KernelEvent(): stream_id = rec.correlation_id.external.value,
  queue_id = kinfo.queue_id.handle. MemcpyEvent(): stream_id =
  rec.correlation_id.external.value. Add VLOG for unexpected HIP
  stream operations. Add breadcrumb comments at consumption sites.
- rocm_tracer.h: Add rocprofiler_context_id_t hip_stream_ctx_ member.
- rocm_tracer_utils.h: Add uint64_t queue_id field to RocmTracerEvent.
- rocm_collector.cc: Add dense stream remapping in Export().

Merging this change closes tensorflow#46182

PiperOrigin-RevId: 959107426
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.

1 participant