From 25e05907f0292310eaae27a032db0ee274413874 Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Tue, 2 Jul 2024 19:46:02 +0200 Subject: Preparing benchmark work --- modules/remote-sycl/benchmarks/mixed_precision.cpp | 110 +++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 modules/remote-sycl/benchmarks/mixed_precision.cpp (limited to 'modules/remote-sycl/benchmarks/mixed_precision.cpp') diff --git a/modules/remote-sycl/benchmarks/mixed_precision.cpp b/modules/remote-sycl/benchmarks/mixed_precision.cpp new file mode 100644 index 0000000..e63a814 --- /dev/null +++ b/modules/remote-sycl/benchmarks/mixed_precision.cpp @@ -0,0 +1,110 @@ +#include "./mixed_precision.hpp" +#include + + +int main(){ + using namespace saw; + + constexpr uint64_t max_test_size = 1024ul * 1024ul * 512ul; + + std::random_device r; + std::default_random_engine e1{r()}; + std::uniform_real_distribution<> dis{-1.0,1.0}; + + + saw::event_loop loop; + saw::wait_scope wait{loop}; + + remote rmt; + + own> rmt_addr{}; + + rmt.resolve_address().then([&](auto addr){ + rmt_addr = std::move(addr); + }).detach(); + + wait.poll(); + if(!rmt_addr){ + return -1; + } + + data mixed_host_data; + data float64_host_data; + data float32_host_data; + + cl::sycl::event mixed_ev; + cl::sycl::event float32_ev; + cl::sycl::event float64_ev; + + auto sycl_iface = listen_mixed_precision(mixed_ev, float64_ev, float32_ev); + + auto time_eval = [](std::string_view tag, cl::sycl::event& ev){ + auto end = ev.get_profiling_info(); + auto start = ev.get_profiling_info(); + + std::cout<<"Elapsed "<get_device(); + + /** + * Warmup + */ + { + uint64_t test_size = max_test_size; + mixed_host_data = {test_size}; + float64_host_data = {test_size}; + float32_host_data = {test_size}; + for(uint64_t i = 0; i < test_size; ++i){ + double gen_num = dis(e1); + mixed_host_data.at(i) = static_cast(gen_num); + float64_host_data.at(i) = static_cast(gen_num); + float32_host_data.at(i) = static_cast(gen_num); + } + data mixed_device_data{mixed_host_data}; + data float64_device_data{float64_host_data}; + data float32_device_data{float32_host_data}; + + sycl_iface.template call<"float64_32">(mixed_device_data, &(device.get_handle())); + device.get_handle().wait(); + sycl_iface.template call<"float64">(float64_device_data, &(device.get_handle())); + device.get_handle().wait(); + sycl_iface.template call<"float32">(float32_device_data, &(device.get_handle())); + device.get_handle().wait(); + + } + + /** + * Benchmark + */ + for(uint64_t test_size = 1ul; test_size < max_test_size; test_size *= 2ul){ + device.get_handle().wait(); + mixed_host_data = {test_size}; + float64_host_data = {test_size}; + float32_host_data = {test_size}; + for(uint64_t i = 0; i < test_size; ++i){ + double gen_num = dis(e1); + mixed_host_data.at(i) = static_cast(gen_num); + float64_host_data.at(i) = static_cast(gen_num); + float32_host_data.at(i) = static_cast(gen_num); + } + data mixed_device_data{mixed_host_data}; + data float64_device_data{float64_host_data}; + data float32_device_data{float32_host_data}; + + sycl_iface.template call<"float64_32">(mixed_device_data); + device.get_handle().wait(); + sycl_iface.template call<"float64">(float64_device_data); + device.get_handle().wait(); + sycl_iface.template call<"float32">(float32_device_data); + device.get_handle().wait(); + + std::cout<<"\nSize: "<