#include <gtest/gtest.h>
#include "gromacs/ewald/pme_gpu_program.h"
+#include "gromacs/gpu_utils/device_context.h"
#include "gromacs/hardware/gpu_hw_info.h"
#include "gromacs/utility/gmxassert.h"
std::string description_;
//! Device information pointer
const DeviceInformation* deviceInfo_;
+ //! Local copy of the device context pointer
+ DeviceContext deviceContext_;
//! Persistent compiled GPU kernels for PME.
PmeGpuProgramStorage program_;
CodePath getCodePath() const { return codePath_; }
//! Returns a human-readable context description line
std::string getDescription() const { return description_; }
+ //! Getter for the DeviceContext
+ const DeviceContext& deviceContext() const { return deviceContext_; }
//! Returns the device info pointer
const DeviceInformation* getDeviceInfo() const { return deviceInfo_; }
//! Returns the persistent PME GPU kernels
const PmeGpuProgram* getPmeGpuProgram() const { return program_.get(); }
- //! Constructs the context
- TestHardwareContext(CodePath codePath, const char* description, const DeviceInformation* deviceInfo) :
+ //! Constructs the context for CPU builds
+ TestHardwareContext(CodePath codePath, const char* description) :
+ codePath_(codePath),
+ description_(description)
+ {
+ GMX_RELEASE_ASSERT(codePath == CodePath::CPU,
+ "A GPU code path should provide DeviceInformation to the "
+ "TestHerdwareContext constructor.");
+ }
+ //! Constructs the context for GPU builds
+ TestHardwareContext(CodePath codePath, const char* description, const DeviceInformation& deviceInfo) :
codePath_(codePath),
description_(description),
- deviceInfo_(deviceInfo)
+ deviceInfo_(&deviceInfo),
+ deviceContext_(deviceInfo),
+ program_(buildPmeGpuProgram(deviceInfo, deviceContext_))
{
- if (codePath == CodePath::GPU)
- {
- program_ = buildPmeGpuProgram(deviceInfo_);
- }
+ GMX_RELEASE_ASSERT(codePath == CodePath::GPU,
+ "TestHerdwareContext tries to construct DeviceContext and PmeGpuProgram "
+ "in CPU build.");
}
~TestHardwareContext();
};