Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-26 08:22:12

0001 /** TRACCC library, part of the ACTS project (R&D line)
0002  *
0003  * (c) 2022-2025 CERN for the benefit of the ACTS project
0004  *
0005  * Mozilla Public License Version 2.0
0006  */
0007 
0008 #pragma once
0009 
0010 // Local include(s).
0011 #include "traccc/hip/utils/stream.hpp"
0012 
0013 // HIP include(s).
0014 #include <hip/hip_runtime_api.h>
0015 
0016 namespace traccc::hip::details {
0017 
0018 /// Get current HIP device number.
0019 ///
0020 /// This function wraps the hipGetDevice function in a way that returns the
0021 /// device number rather than use a reference argument to write to.
0022 ///
0023 /// Note that calling the function on a machine with no HIP device does not
0024 /// result in an error, the function just returns -1 in that case.
0025 ///
0026 int get_device();
0027 
0028 /// Get the warp size for a given device.
0029 ///
0030 /// @param device The device to query.
0031 ///
0032 /// @return The warp size for the device.
0033 ///
0034 unsigned int get_warp_size(int device);
0035 
0036 /// Get concrete @c hipStream_t object out of our wrapper
0037 hipStream_t get_stream(const stream& str);
0038 
0039 /// Class with RAII mechanism for selecting a HIP device.
0040 ///
0041 /// This class can be used to select HIP devices in a modern C++ way, with
0042 /// scope safety. When an object of this class is constructed, it will switch
0043 /// the thread-local device selector to the device number specified in the
0044 /// constructor argument. When this object goes out of scope or gets
0045 /// destructed in any other way, it will restore the device that was set
0046 /// before the object was constructed. This allows us to easily write methods
0047 /// with few side-effects.
0048 ///
0049 /// @warning The behaviour of this class is not well-defined if you construct
0050 /// more than one in the same scope.
0051 ///
0052 class select_device {
0053  public:
0054   /// Constructs the object, switching the current HIP device
0055   /// to the requested number.
0056   ///
0057   /// @param device The HIP device number to switch to.
0058   ///
0059   select_device(int device);
0060 
0061   /// Deconstructs the object, returning to the device that was
0062   /// selected before constructing this object.
0063   ~select_device();
0064 
0065   /// Return the identifier for the device being seleced
0066   int device() const;
0067 
0068  private:
0069   /// The old device number, this is what we restore when the
0070   /// object goes out of scope.
0071   int m_device;
0072 };
0073 
0074 }  // namespace traccc::hip::details