Skip to content

Commit

Permalink
tests: Skip cuInit tests if cuda-gdb is not found or not working (rap…
Browse files Browse the repository at this point in the history
…idsai#12644)

Since rapidsai#12545, we use cuda-gdb for scripting (since that is already installed in the nvidia/cuda:-devel docker images) to check that RAPIDS_NO_INITIALIZE ensured that cuInit is not called on import.

Unfortunately, the official cuda-gdb-11-2 package for Debian-based systems does not correctly advertise all its dependencies (we need to manually install libtinfo5 and libncursesw5). Consequently cuda-gdb does not work if the base image rapids builds against is for CUDA 11.2.

To workaround this, build the cuda-gdb command as a fixture that is appropriately marked in the cases where it is either not installed, or else not working due to broken dependencies.

Authors:
  - Lawrence Mitchell (https://github.com/wence-)
  - Ashwin Srinath (https://github.com/shwina)

Approvers:
  - Ashwin Srinath (https://github.com/shwina)

URL: rapidsai#12644
  • Loading branch information
wence- authored Jan 31, 2023
1 parent f12d067 commit 78cc98a
Showing 1 changed file with 49 additions and 30 deletions.
79 changes: 49 additions & 30 deletions python/cudf/cudf/tests/test_no_cuinit.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
# Copyright (c) 2023, NVIDIA CORPORATION.

import os
import platform
import subprocess
import sys
from shutil import which

import pytest

gdb = which("cuda-gdb")
machine_arch = platform.uname().machine


GDB_COMMANDS = b"""
GDB_COMMANDS = """
set confirm off
set breakpoint pending on
break cuInit
Expand All @@ -21,21 +16,31 @@
"""


pytestmark = [
pytest.mark.skipif(
machine_arch != "x86_64",
reason=(
"cuda-gdb install is broken on nvidia/cuda aarch64 images "
"(libexpat is missing)"
),
),
pytest.mark.skipif(
gdb is None, reason="cuda-gdb not found, can't detect cuInit"
),
]
@pytest.fixture(scope="module")
def cuda_gdb(request):
gdb = which("cuda-gdb")
if gdb is None:
request.applymarker(
pytest.mark.xfail(reason="No cuda-gdb found, can't detect cuInit"),
)
return gdb
else:
output = subprocess.run(
[gdb, "--version"], capture_output=True, text=True
)
if output.returncode != 0:
request.applymarker(
pytest.mark.xfail(
reason=(
"cuda-gdb not working on this platform, "
f"can't detect cuInit: {output.stderr}"
)
),
)
return gdb


def test_cudf_import_no_cuinit():
def test_cudf_import_no_cuinit(cuda_gdb):
# When RAPIDS_NO_INITIALIZE is set, importing cudf should _not_
# create a CUDA context (i.e. cuInit should not be called).
# Intercepting the call to cuInit programmatically is tricky since
Expand All @@ -47,9 +52,9 @@ def test_cudf_import_no_cuinit():
# Instead, we just run under GDB and see if we hit a breakpoint
env = os.environ.copy()
env["RAPIDS_NO_INITIALIZE"] = "1"
output: str = subprocess.check_output(
output = subprocess.run(
[
gdb,
cuda_gdb,
"-x",
"-",
"--args",
Expand All @@ -59,21 +64,28 @@ def test_cudf_import_no_cuinit():
],
input=GDB_COMMANDS,
env=env,
stderr=subprocess.DEVNULL,
).decode()
capture_output=True,
text=True,
)

cuInit_called = output.find("in cuInit ()")
cuInit_called = output.stdout.find("in cuInit ()")
print("Command output:\n")
print("*** STDOUT ***")
print(output.stdout)
print("*** STDERR ***")
print(output.stderr)
assert output.returncode == 0
assert cuInit_called < 0


def test_cudf_create_series_cuinit():
def test_cudf_create_series_cuinit(cuda_gdb):
# This tests that our gdb scripting correctly identifies cuInit
# when it definitely should have been called.
env = os.environ.copy()
env["RAPIDS_NO_INITIALIZE"] = "1"
output: str = subprocess.check_output(
output = subprocess.run(
[
gdb,
cuda_gdb,
"-x",
"-",
"--args",
Expand All @@ -83,8 +95,15 @@ def test_cudf_create_series_cuinit():
],
input=GDB_COMMANDS,
env=env,
stderr=subprocess.DEVNULL,
).decode()
capture_output=True,
text=True,
)

cuInit_called = output.find("in cuInit ()")
cuInit_called = output.stdout.find("in cuInit ()")
print("Command output:\n")
print("*** STDOUT ***")
print(output.stdout)
print("*** STDERR ***")
print(output.stderr)
assert output.returncode == 0
assert cuInit_called >= 0

0 comments on commit 78cc98a

Please sign in to comment.