Skip to content

Commit

Permalink
Merge pull request #133 from MrBurmark/bugfix/burmark1/get_platform_c…
Browse files Browse the repository at this point in the history
…onst

Make get_platform a const method
  • Loading branch information
trws authored Jun 2, 2023
2 parents 240fb03 + 2e4d2be commit f06c7a1
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions include/camp/resource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ namespace resources
}
return *result->get();
}
Platform get_platform() { return m_value->get_platform(); }
Platform get_platform() const { return m_value->get_platform(); }
template <typename T>
T *allocate(size_t size, MemoryAccess ma = MemoryAccess::Device)
{
Expand All @@ -99,7 +99,7 @@ namespace resources
{
public:
virtual ~ContextInterface() {}
virtual Platform get_platform() = 0;
virtual Platform get_platform() const = 0;
virtual void *calloc(size_t size, MemoryAccess ma = MemoryAccess::Device) = 0;
virtual void deallocate(void *p, MemoryAccess ma = MemoryAccess::Device) = 0;
virtual void memcpy(void *dst, const void *src, size_t size) = 0;
Expand All @@ -115,7 +115,7 @@ namespace resources
{
public:
ContextModel(T const &modelVal) : m_modelVal(modelVal) {}
Platform get_platform() override { return m_modelVal.get_platform(); }
Platform get_platform() const override { return m_modelVal.get_platform(); }
void *calloc(size_t size, MemoryAccess ma = MemoryAccess::Device) override { return m_modelVal.calloc(size, ma); }
void deallocate(void *p, MemoryAccess ma = MemoryAccess::Device) override { m_modelVal.deallocate(p, ma); }
void memcpy(void *dst, const void *src, size_t size) override
Expand Down
2 changes: 1 addition & 1 deletion include/camp/resource/cuda.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ namespace resources
}

// Methods
Platform get_platform() { return Platform::cuda; }
Platform get_platform() const { return Platform::cuda; }
static Cuda get_default()
{
static Cuda c([] {
Expand Down
2 changes: 1 addition & 1 deletion include/camp/resource/hip.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ namespace resources
}

// Methods
Platform get_platform() { return Platform::hip; }
Platform get_platform() const { return Platform::hip; }
static Hip get_default()
{
static Hip h([] {
Expand Down
2 changes: 1 addition & 1 deletion include/camp/resource/host.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace resources
Host(int /* group */ = -1) {}

// Methods
Platform get_platform() { return Platform::host; }
Platform get_platform() const { return Platform::host; }
static Host get_default()
{
static Host h;
Expand Down
2 changes: 1 addition & 1 deletion include/camp/resource/omp_target.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ namespace resources
}

// Methods
Platform get_platform() { return Platform::omp_target; }
Platform get_platform() const { return Platform::omp_target; }
static Omp get_default()
{
static Omp o;
Expand Down
2 changes: 1 addition & 1 deletion include/camp/resource/sycl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ namespace resources
}

// Methods
Platform get_platform() { return Platform::sycl; }
Platform get_platform() const { return Platform::sycl; }
static Sycl get_default()
{
static Sycl h;
Expand Down
8 changes: 4 additions & 4 deletions test/resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ TEST(CampResource, ConvertFails)
}
TEST(CampResource, GetPlatform)
{
ASSERT_EQ(Resource(Host()).get_platform(), Platform::host);
ASSERT_EQ(static_cast<const Resource>(Host()).get_platform(), Platform::host);
#ifdef CAMP_HAVE_CUDA
ASSERT_EQ(Resource(Cuda()).get_platform(), Platform::cuda);
ASSERT_EQ(static_cast<const Resource>(Cuda()).get_platform(), Platform::cuda);
#endif
#ifdef CAMP_HAVE_HIP
ASSERT_EQ(Resource(Hip()).get_platform(), Platform::hip);
ASSERT_EQ(static_cast<const Resource>(Hip()).get_platform(), Platform::hip);
#endif
#ifdef CAMP_HAVE_OMP_OFFLOAD
ASSERT_EQ(Resource(Omp()).get_platform(), Platform::omp_target);
ASSERT_EQ(static_cast<const Resource>(Omp()).get_platform(), Platform::omp_target);
#endif
}
TEST(CampResource, ConvertWorks)
Expand Down

0 comments on commit f06c7a1

Please sign in to comment.