Skip to content

Commit

Permalink
Regards #677: Added equality and inequality operators for context_t
Browse files Browse the repository at this point in the history
…'s and `kernel_t`'s
  • Loading branch information
eyalroz committed Sep 10, 2024
1 parent b1ef7f0 commit a9008d5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/cuda/api/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -759,14 +759,16 @@ class context_t {

/// @note: The comparison ignores whether or not the wrapper is owning
///@{
inline bool operator==(const context_t& lhs, const context_t& rhs)
inline bool operator==(const context_t& lhs, const context_t& rhs) noexcept
{
return lhs.handle() == rhs.handle();
// Note: Contexts on different devices cannot have the same context handle,
// so this is redundant, but let's be extra safe:
return lhs.device_id() == rhs.device_id() and lhs.handle() == rhs.handle();
}

inline bool operator!=(const context_t& lhs, const context_t& rhs)
inline bool operator!=(const context_t& lhs, const context_t& rhs) noexcept
{
return lhs.handle() != rhs.handle();
return not (lhs == rhs);
}
///@}

Expand Down
13 changes: 13 additions & 0 deletions src/cuda/api/kernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,19 @@ inline grid::dimension_t kernel_t::max_active_blocks_per_multiprocessor(
dynamic_shared_memory_per_block, disable_caching_override);
}

inline bool operator==(const kernel_t& lhs, const kernel_t& rhs) noexcept
{
return
lhs.device_id() == rhs.device_id()
and lhs.context_handle() == rhs.context_handle()
and lhs.handle() == rhs.handle();
}

inline bool operator!=(const kernel_t& lhs, const kernel_t& rhs) noexcept
{
return not (lhs == rhs);
}

} // namespace cuda

#endif // CUDA_API_WRAPPERS_KERNEL_HPP_

0 comments on commit a9008d5

Please sign in to comment.