Skip to content

Commit a51d682

Browse files
committed
update with refactoring based on the PR comments
1 parent a8a1e24 commit a51d682

File tree

11 files changed

+1831
-2638
lines changed

11 files changed

+1831
-2638
lines changed

xla/backends/profiler/gpu/BUILD

Lines changed: 100 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
load("@local_config_cuda//cuda:build_defs.bzl", "cuda_library")
23
load("@local_config_rocm//rocm:build_defs.bzl", "if_rocm_is_configured")
34
load("@rules_cc//cc:cc_library.bzl", "cc_library")
@@ -38,7 +39,6 @@ cc_library(
3839
deps = [
3940
":cupti_collector",
4041
":cupti_tracer",
41-
":cupti_tracer_options_utils",
4242
"//xla/tsl/platform:errors",
4343
"//xla/tsl/profiler/utils:time_utils",
4444
"//xla/tsl/util:env_var",
@@ -157,7 +157,9 @@ xla_test(
157157
":cupti_wrapper",
158158
":mock_cupti",
159159
"//xla/tsl/profiler/utils:time_utils",
160+
"@com_google_absl//absl/memory",
160161
"@com_google_googletest//:gtest_main",
162+
"@tsl//tsl/platform:test",
161163
],
162164
)
163165

@@ -223,8 +225,6 @@ cc_library(
223225
"//xla/tsl/profiler/backends/cpu:annotation_stack",
224226
"//xla/tsl/profiler/utils:lock_free_queue",
225227
"//xla/tsl/profiler/utils:per_thread",
226-
"//xla/tsl/profiler/utils:xplane_builder",
227-
"//xla/tsl/profiler/utils:xplane_schema",
228228
"@com_google_absl//absl/base:core_headers",
229229
"@com_google_absl//absl/cleanup",
230230
"@com_google_absl//absl/container:flat_hash_map",
@@ -260,7 +260,6 @@ cc_library(
260260
"cuda-only",
261261
"gpu",
262262
],
263-
visibility = ["//visibility:public"],
264263
deps = [
265264
":cupti_collector",
266265
":cupti_interface",
@@ -287,9 +286,9 @@ cc_library(
287286
"cuda-only",
288287
"gpu",
289288
],
290-
visibility = ["//visibility:public"],
291289
deps = [
292290
":cupti_collector",
291+
":cupti_interface",
293292
"@com_google_absl//absl/status",
294293
"@com_google_absl//absl/time",
295294
],
@@ -308,7 +307,6 @@ cc_library(
308307
"gpu",
309308
"manual", # This target requires CUDA 12.6+, therefore we only built it if it was requested via a dependency.
310309
],
311-
visibility = ["//visibility:public"],
312310
deps = [
313311
":cupti_collector",
314312
":cupti_interface",
@@ -360,11 +358,39 @@ cc_library(
360358
],
361359
)
362360

361+
cc_library(
362+
name = "rocm_tracer_utils",
363+
srcs = ["rocm_tracer_utils.cc"],
364+
hdrs = ["rocm_tracer_utils.h"],
365+
deps = [
366+
"//xla/tsl/profiler/backends/cpu:annotation_stack",
367+
"//xla/tsl/profiler/utils:time_utils",
368+
"//xla/tsl/profiler/utils:math_utils",
369+
"@com_google_absl//absl/strings:string_view",
370+
"@com_google_absl//absl/container:flat_hash_map",
371+
"@com_google_absl//absl/container:flat_hash_set",
372+
"@com_google_absl//absl/container:node_hash_map",
373+
"@com_google_absl//absl/container:node_hash_set",
374+
"@tsl//tsl/platform:env_time",
375+
"@tsl//tsl/platform:env",
376+
"@tsl//tsl/platform:errors",
377+
"@tsl//tsl/platform:logging",
378+
"@tsl//tsl/platform:macros",
379+
],
380+
visibility = ["//visibility:public"],
381+
)
382+
363383
cc_library(
364384
name = "rocm_collector",
365385
srcs = ["rocm_collector.cc"],
366386
hdrs = ["rocm_collector.h"],
367387
# copybara:uncomment compatible_with = ["//buildenv/target:non_prod"],
388+
linkopts = select({
389+
"//conditions:default": [
390+
"-L/opt/rocm/lib", # search path for all ROCm shared objects
391+
"-lrocprofiler-sdk", # the library that owns the missing symbols
392+
],
393+
}),
368394
tags = [
369395
"gpu",
370396
"rocm-only",
@@ -373,6 +399,7 @@ cc_library(
373399
"manual",
374400
]),
375401
deps = [
402+
":rocm_tracer_utils",
376403
"//xla/stream_executor/rocm:roctracer_wrapper",
377404
"//xla/tsl/profiler/backends/cpu:annotation_stack",
378405
"//xla/tsl/profiler/utils:parse_annotation",
@@ -405,6 +432,12 @@ cc_library(
405432
srcs = ["rocm_tracer.cc"],
406433
hdrs = ["rocm_tracer.h"],
407434
# copybara:uncomment compatible_with = ["//buildenv/target:non_prod"],
435+
linkopts = select({
436+
"//conditions:default": [
437+
"-L/opt/rocm/lib", # search path for all ROCm shared objects
438+
"-lrocprofiler-sdk", # the library that owns the missing symbols
439+
],
440+
}),
408441
tags = [
409442
"gpu",
410443
"rocm-only",
@@ -413,10 +446,15 @@ cc_library(
413446
"manual",
414447
]),
415448
deps = [
449+
":rocm_tracer_utils",
416450
":rocm_collector",
417451
"//xla/stream_executor/rocm:roctracer_wrapper",
418452
"//xla/tsl/profiler/backends/cpu:annotation_stack",
419453
"//xla/tsl/profiler/utils:time_utils",
454+
"//xla/tsl/profiler/utils:xplane_builder",
455+
"//xla/tsl/profiler/utils:xplane_schema",
456+
"//xla/tsl/profiler/utils:xplane_utils",
457+
"//xla/tsl/util:env_var",
420458
"@com_google_absl//absl/container:fixed_array",
421459
"@com_google_absl//absl/container:flat_hash_map",
422460
"@com_google_absl//absl/container:flat_hash_set",
@@ -433,9 +471,64 @@ cc_library(
433471
"@tsl//tsl/platform:status",
434472
"@tsl//tsl/platform:thread_annotations",
435473
"@tsl//tsl/platform:types",
474+
"@tsl//tsl/profiler/lib:profiler_factory",
475+
"@tsl//tsl/profiler/lib:profiler_interface",
436476
],
437477
)
438478

479+
xla_cc_test(
480+
name = "rocm_tracer_test",
481+
size = "small",
482+
srcs = ["rocm_tracer_test.cc"],
483+
tags = [
484+
"gpu",
485+
"rocm",
486+
"rocm-only",
487+
] + if_google([
488+
# Optional: only run internally if ROCm config is enabled
489+
"manual",
490+
]),
491+
deps = [
492+
":rocm_tracer",
493+
":rocm_tracer_utils",
494+
"//xla/tsl/profiler/utils:xplane_builder",
495+
"@com_google_absl//absl/container:flat_hash_map",
496+
"@com_google_googletest//:gtest_main",
497+
"@tsl//tsl/platform:status_matchers",
498+
"@tsl//tsl/platform:test",
499+
"@tsl//tsl/profiler/protobuf:xplane_proto_cc",
500+
],
501+
)
502+
503+
xla_cc_test(
504+
name = "rocm_collector_test",
505+
size = "small",
506+
srcs = ["rocm_collector_test.cc"],
507+
tags = [
508+
"gpu",
509+
"rocm",
510+
"rocm-only",
511+
] + if_google([
512+
"manual",
513+
]),
514+
deps = [
515+
# ":rocm_tracer",
516+
":rocm_collector",
517+
":rocm_tracer_utils",
518+
"//xla/tsl/profiler/utils:xplane_builder",
519+
"@com_google_absl//absl/container:flat_hash_map",
520+
"@com_google_googletest//:gtest_main",
521+
"@tsl//tsl/platform:env_time",
522+
"@tsl//tsl/platform:status_matchers",
523+
"@tsl//tsl/platform:test",
524+
"@tsl//tsl/profiler/protobuf:xplane_proto_cc",
525+
"@tsl//tsl/platform:env",
526+
"@tsl//tsl/platform:errors",
527+
"@tsl//tsl/platform:logging",
528+
"@tsl//tsl/platform:macros",
529+
],
530+
)
531+
439532
cc_library(
440533
name = "nvtx_utils",
441534
srcs = ["nvtx_utils.cc"],
@@ -707,7 +800,6 @@ xla_test(
707800
deps = [
708801
":cupti_collector",
709802
":cupti_error_manager",
710-
":cupti_pm_sampler_stub",
711803
":cupti_tracer",
712804
":cupti_utils",
713805
":cupti_wrapper",
@@ -717,27 +809,4 @@ xla_test(
717809
"@com_google_absl//absl/time",
718810
"@com_google_googletest//:gtest_main",
719811
],
720-
)
721-
722-
cc_library(
723-
name = "cupti_tracer_options_utils",
724-
srcs = ["cupti_tracer_options_utils.cc"],
725-
hdrs = ["cupti_tracer_options_utils.h"],
726-
# copybara:uncomment compatible_with = ["//buildenv/target:non_prod"],
727-
tags = [
728-
"cuda-only",
729-
"gpu",
730-
],
731-
visibility = ["//visibility:public"],
732-
deps = [
733-
":cupti_collector",
734-
":cupti_tracer",
735-
"//xla/tsl/platform:errors",
736-
"//xla/tsl/profiler/utils:profiler_options_util",
737-
"@com_google_absl//absl/container:flat_hash_set",
738-
"@com_google_absl//absl/status",
739-
"@com_google_absl//absl/strings",
740-
"@local_config_cuda//cuda:cuda_headers",
741-
"@tsl//tsl/profiler/protobuf:profiler_options_proto_cc",
742-
],
743-
)
812+
)

0 commit comments

Comments
 (0)