Skip to content

Commit

Permalink
hip device guard rule-5
Browse files Browse the repository at this point in the history
  • Loading branch information
yhmtsai committed Oct 23, 2019
1 parent bee3b42 commit c653acb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
File renamed without changes.
16 changes: 16 additions & 0 deletions hip/base/device_guard.hip.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace gko {


/**
* This class defines a device guard for the hip functions and the hip module.
* The guard is used to make sure that the device code is run on the correct
* hip device, when run with multiple devices. The class records the current
* device id and uses `hipSetDevice` to set the device id to the one being
* passed in. After the scope has been exited, the destructor sets the device_id
* back to the one before entering the scope.
*/
class hip_device_guard {
public:
hip_device_guard(int device_id)
Expand All @@ -48,6 +56,14 @@ class hip_device_guard {
GKO_ASSERT_NO_HIP_ERRORS(hipSetDevice(device_id));
}

hip_device_guard(hip_device_guard &other) = delete;

hip_device_guard &operator=(const hip_device_guard &other) = delete;

hip_device_guard(hip_device_guard &&other) = delete;

hip_device_guard const &operator=(hip_device_guard &&other) = delete;

~hip_device_guard() noexcept(false)
{
/* Ignore the error during stack unwinding for this call */
Expand Down

0 comments on commit c653acb

Please sign in to comment.