Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions include/alpaka/dev/DevCpu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ namespace alpaka
return 0;
}

friend struct trait::GetName<DevCpu>;
friend struct trait::GetMemBytes<DevCpu>;
friend struct trait::GetFreeMemBytes<DevCpu>;
friend struct trait::GetWarpSizes<DevCpu>;
friend struct trait::GetPreferredWarpSize<DevCpu>;

private:
std::shared_ptr<cpu::detail::DevCpuImpl> m_spDevCpuImpl;
};
Expand All @@ -99,19 +105,36 @@ namespace alpaka
template<>
struct GetName<DevCpu>
{
ALPAKA_FN_HOST static auto getName(DevCpu const& /* dev */) -> std::string
ALPAKA_FN_HOST static auto getName(DevCpu const& dev) -> std::string
{
return cpu::detail::getCpuName();
auto& devProperties = dev.m_spDevCpuImpl->deviceProperties();
std::call_once(
dev.m_spDevCpuImpl->onceFlag(),
[&]() noexcept
{
devProperties->name = cpu::detail::getCpuName();
devProperties->totalGlobalMem = cpu::detail::getTotalGlobalMemSizeBytes();
});
return devProperties->name;
}
};

//! The CPU device available memory get trait specialization.
template<>
struct GetMemBytes<DevCpu>
{
ALPAKA_FN_HOST static auto getMemBytes(DevCpu const& /* dev */) -> std::size_t
ALPAKA_FN_HOST static auto getMemBytes(DevCpu const& dev) -> std::size_t
{
return cpu::detail::getTotalGlobalMemSizeBytes();
auto& devProperties = dev.m_spDevCpuImpl->deviceProperties();
std::call_once(
dev.m_spDevCpuImpl->onceFlag(),
[&]() noexcept
{
devProperties->name = cpu::detail::getCpuName();
devProperties->totalGlobalMem = cpu::detail::getTotalGlobalMemSizeBytes();
});

return devProperties->totalGlobalMem;
}
};

Expand Down
126 changes: 112 additions & 14 deletions include/alpaka/dev/DevGenericSycl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "alpaka/core/Common.hpp"
#include "alpaka/core/Sycl.hpp"
#include "alpaka/dev/Traits.hpp"
#include "alpaka/dev/common/DeviceProperties.hpp"
#include "alpaka/mem/buf/Traits.hpp"
#include "alpaka/platform/Traits.hpp"
#include "alpaka/queue/Properties.hpp"
Expand Down Expand Up @@ -112,11 +113,23 @@ namespace alpaka
return m_context;
}

std::once_flag& onceFlag()
{
return m_onceFlag;
}

std::optional<alpaka::DeviceProperties>& deviceProperties()
{
return m_deviceProperties;
}

private:
sycl::device m_device;
sycl::context m_context;
std::vector<std::weak_ptr<QueueGenericSyclImpl>> m_queues;
std::optional<alpaka::DeviceProperties> m_deviceProperties;
std::shared_mutex mutable m_mutex;
std::once_flag m_onceFlag;
};
} // namespace detail

Expand Down Expand Up @@ -160,8 +173,30 @@ namespace alpaka
{
static auto getName(DevGenericSycl<TTag> const& dev) -> std::string
{
auto const device = dev.getNativeHandle().first;
return device.template get_info<sycl::info::device::name>();
auto& devProperties = dev.m_impl->deviceProperties();
std::call_once(
dev.m_impl->onceFlag(),
[&]()
{
devProperties = std::make_optional<alpaka::DeviceProperties>();
auto const device = dev.getNativeHandle().first;
devProperties->name = device.template get_info<sycl::info::device::name>();
devProperties->totalGlobalMem
= device.template get_info<sycl::info::device::global_mem_size>();

std::vector<std::size_t> warp_sizes
= device.template get_info<sycl::info::device::sub_group_sizes>();
// The CPU runtime supports a sub-group size of 64, but the SYCL implementation currently
// does not
auto find64 = std::find(warp_sizes.begin(), warp_sizes.end(), 64);
if(find64 != warp_sizes.end())
warp_sizes.erase(find64);
// Sort the warp sizes in decreasing order
std::sort(warp_sizes.begin(), warp_sizes.end(), std::greater<>{});
devProperties->warpSizes = std::move(warp_sizes);
devProperties->preferredWarpSize = devProperties->warpSizes.front();
});
return devProperties->name;
}
};

Expand All @@ -171,8 +206,31 @@ namespace alpaka
{
static auto getMemBytes(DevGenericSycl<TTag> const& dev) -> std::size_t
{
auto const device = dev.getNativeHandle().first;
return device.template get_info<sycl::info::device::global_mem_size>();
auto& devProperties = dev.m_impl->deviceProperties();
std::call_once(
dev.m_impl->onceFlag(),
[&]()
{
devProperties = std::make_optional<alpaka::DeviceProperties>();
auto const device = dev.getNativeHandle().first;
devProperties->name = device.template get_info<sycl::info::device::name>();
devProperties->totalGlobalMem
= device.template get_info<sycl::info::device::global_mem_size>();

std::vector<std::size_t> warp_sizes
= device.template get_info<sycl::info::device::sub_group_sizes>();
// The CPU runtime supports a sub-group size of 64, but the SYCL implementation currently
// does not
auto find64 = std::find(warp_sizes.begin(), warp_sizes.end(), 64);
if(find64 != warp_sizes.end())
warp_sizes.erase(find64);
// Sort the warp sizes in decreasing order
std::sort(warp_sizes.begin(), warp_sizes.end(), std::greater<>{});
devProperties->warpSizes = std::move(warp_sizes);
devProperties->preferredWarpSize = devProperties->warpSizes.front();
});

return devProperties->totalGlobalMem;
}
};

Expand All @@ -195,15 +253,31 @@ namespace alpaka
{
static auto getWarpSizes(DevGenericSycl<TTag> const& dev) -> std::vector<std::size_t>
{
auto const device = dev.getNativeHandle().first;
std::vector<std::size_t> warp_sizes = device.template get_info<sycl::info::device::sub_group_sizes>();
// The CPU runtime supports a sub-group size of 64, but the SYCL implementation currently does not
auto find64 = std::find(warp_sizes.begin(), warp_sizes.end(), 64);
if(find64 != warp_sizes.end())
warp_sizes.erase(find64);
// Sort the warp sizes in decreasing order
std::sort(warp_sizes.begin(), warp_sizes.end(), std::greater<>{});
return warp_sizes;
auto& devProperties = dev.m_impl->deviceProperties();
std::call_once(
dev.m_impl->onceFlag(),
[&]()
{
devProperties = std::make_optional<alpaka::DeviceProperties>();
auto const device = dev.getNativeHandle().first;
devProperties->name = device.template get_info<sycl::info::device::name>();
devProperties->totalGlobalMem
= device.template get_info<sycl::info::device::global_mem_size>();

std::vector<std::size_t> warp_sizes
= device.template get_info<sycl::info::device::sub_group_sizes>();
// The CPU runtime supports a sub-group size of 64, but the SYCL implementation currently
// does not
auto find64 = std::find(warp_sizes.begin(), warp_sizes.end(), 64);
if(find64 != warp_sizes.end())
warp_sizes.erase(find64);
// Sort the warp sizes in decreasing order
std::sort(warp_sizes.begin(), warp_sizes.end(), std::greater<>{});
devProperties->warpSizes = std::move(warp_sizes);
devProperties->preferredWarpSize = devProperties->warpSizes.front();
});

return devProperties->warpSizes;
}
};

Expand All @@ -213,7 +287,31 @@ namespace alpaka
{
static auto getPreferredWarpSize(DevGenericSycl<TTag> const& dev) -> std::size_t
{
return GetWarpSizes<DevGenericSycl<TTag>>::getWarpSizes(dev).front();
auto& devProperties = dev.m_impl->deviceProperties();
std::call_once(
dev.m_impl->onceFlag(),
[&]()
{
devProperties = std::make_optional<alpaka::DeviceProperties>();
auto const device = dev.getNativeHandle().first;
devProperties->name = device.template get_info<sycl::info::device::name>();
devProperties->totalGlobalMem
= device.template get_info<sycl::info::device::global_mem_size>();

std::vector<std::size_t> warp_sizes
= device.template get_info<sycl::info::device::sub_group_sizes>();
// The CPU runtime supports a sub-group size of 64, but the SYCL implementation currently
// does not
auto find64 = std::find(warp_sizes.begin(), warp_sizes.end(), 64);
if(find64 != warp_sizes.end())
warp_sizes.erase(find64);
// Sort the warp sizes in decreasing order
std::sort(warp_sizes.begin(), warp_sizes.end(), std::greater<>{});
devProperties->warpSizes = std::move(warp_sizes);
devProperties->preferredWarpSize = devProperties->warpSizes.front();
});

return devProperties->preferredWarpSize;
}
};

Expand Down
Loading
Loading