Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions cpp/src/prefetch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@ void prefetch(void const* ptr,
cudaError_t result = cudaMemPrefetchAsync(ptr, size, device.value(), stream.value());
#endif
// cudaErrorInvalidValue is returned when non-managed memory is passed to
// cudaMemPrefetchAsync. We treat this as a no-op.
if (result != cudaErrorInvalidValue && result != cudaSuccess) { RMM_CUDA_TRY(result); }
// cudaMemPrefetchAsync. We treat this as a no-op but must clear the sticky
// error from the CUDA runtime to prevent downstream failures.
if (result == cudaErrorInvalidValue) {
(void)cudaGetLastError();
} else if (result != cudaSuccess) {
RMM_CUDA_TRY(result);
Comment on lines +32 to +35

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

# First, let's look at the file structure and find prefetch.cpp
find . -name "prefetch.cpp" -type f

Repository: rapidsai/rmm

Length of output: 78


🏁 Script executed:

# Then examine the file around the specified lines
if [ -f "cpp/src/prefetch.cpp" ]; then
  echo "=== File content around lines 25-40 ==="
  sed -n '25,40p' cpp/src/prefetch.cpp | cat -n
  echo ""
  echo "=== Full function context ==="
  head -50 cpp/src/prefetch.cpp | cat -n
fi

Repository: rapidsai/rmm

Length of output: 2344


Check the return value from cudaGetLastError() before discarding it.

Line 33 calls cudaGetLastError() to clear the sticky error state but ignores its return value. Per the coding guidelines, all CUDA API calls must have their errors checked. If the cleared error is not one of the expected values, it indicates an inconsistent error state and should be reported.

Suggested patch
   if (result == cudaErrorInvalidValue) {
-    (void)cudaGetLastError();
+    auto const cleared_error = cudaGetLastError();
+    if (cleared_error != cudaSuccess && cleared_error != cudaErrorInvalidValue) {
+      RMM_CUDA_TRY(cleared_error);
+    }
   } else if (result != cudaSuccess) {
     RMM_CUDA_TRY(result);
   }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (result == cudaErrorInvalidValue) {
(void)cudaGetLastError();
} else if (result != cudaSuccess) {
RMM_CUDA_TRY(result);
if (result == cudaErrorInvalidValue) {
auto const cleared_error = cudaGetLastError();
if (cleared_error != cudaSuccess && cleared_error != cudaErrorInvalidValue) {
RMM_CUDA_TRY(cleared_error);
}
} else if (result != cudaSuccess) {
RMM_CUDA_TRY(result);
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cpp/src/prefetch.cpp` around lines 32 - 35, When handling the
cudaErrorInvalidValue path, don't ignore the return of cudaGetLastError(); call
cudaGetLastError() into a variable (e.g., last_err), check it against
cudaSuccess (or expected values) and if it is not cudaSuccess report/propagate
it (use RMM_CUDA_TRY or equivalent) instead of discarding; update the branch
that currently calls cudaGetLastError() to validate its return and handle
unexpected error states rather than silently dropping them (references: result,
cudaErrorInvalidValue, cudaGetLastError, RMM_CUDA_TRY).

}
}

} // namespace rmm
Loading