From 4550eacc18535ea8480c8303c62adbd046fa031d Mon Sep 17 00:00:00 2001 From: Pasha Date: Tue, 25 Oct 2022 18:48:39 +0000 Subject: initial test --- simplex-dev/src/host.cpp | 123 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 simplex-dev/src/host.cpp (limited to 'simplex-dev/src/host.cpp') diff --git a/simplex-dev/src/host.cpp b/simplex-dev/src/host.cpp new file mode 100644 index 0000000..8d0507b --- /dev/null +++ b/simplex-dev/src/host.cpp @@ -0,0 +1,123 @@ +//============================================================== +// Copyright Intel Corporation +// +// SPDX-License-Identifier: MIT +// ============================================================= + +#include +#include +#include +#include + +#include +#include + +// dpc_common.hpp can be found in the dev-utilities include folder. +// e.g., $ONEAPI_ROOT/dev-utilities//include/dpc_common.hpp +#include "dpc_common.hpp" + +// This code sample demonstrates how to split the host and FPGA kernel code into +// separate compilation units so that they can be separately recompiled. +// Consult the README for a detailed discussion. +// - host.cpp (this file) contains exclusively code that executes on the host. +// - kernel.cpp contains almost exclusively code that executes on the device. +// - kernel.hpp contains only the forward declaration of a function containing +// the device code. +#include "kernel.hpp" + +using namespace sycl; + +template +void printMatrix(std::vector &vec, int col, std::string msg) { + std::cout << msg << ":" << std::endl << "[" << std::endl; + for (size_t i=0; i 1) { + std::cout << ",\t"; + } + if (i%col == col-1) { + std::cout << std::endl; + } + } + std::cout << "]" << std::endl; +} + +template +void printVec(std::vector &vec, std::string msg) { + std::cout << msg << ": "; + std::cout << "["; + + for (size_t i=0; i 1) { + std::cout << ", "; + } + } + std::cout << "]" << std::endl; +} + +int main() { + std::vector a = { 2, 1, 1, 1, 0, 0, + 1, 3, 2, 0, 1, 0, + 2, 1, 2, 0, 0, 1}; + + std::vector c = {-6, -5, -4, 0, 0, 0}; + std::vector b = {180, 300, 240}; + + std::vector resultFlags = {-1, -1, -1}; + + // Select either the FPGA emulator or FPGA device +#if defined(FPGA_EMULATOR) + ext::intel::fpga_emulator_selector device_selector; +#else + ext::intel::fpga_selector device_selector; +#endif + + try { + // Create a queue bound to the chosen device. + // If the device is unavailable, a SYCL runtime exception is thrown. + queue q(device_selector, dpc_common::exception_handler); + + + // make sure the device supports USM device allocations + device d = q.get_device(); + if (!d.get_info()) { + std::cerr << "ERROR: The selected device does not support USM device" + << " allocations\n"; + return 1; + } + + printMatrix(a, 6, "a"); + printVec(resultFlags, "result flags"); + // The definition of this function is in a different compilation unit, + // so host and device code can be separately compiled. + double timePassed = RunKernel(q, a, b, c, resultFlags); + + std::cout << "------------------------" << std::endl; + printMatrix(a, 6, "a"); + printVec(resultFlags, "result flags"); + + std::cout << std::endl << std::endl; + std::cout << "timePassed: " << timePassed << std::endl; + + + } catch (exception const &e) { + // Catches exceptions in the host code + std::cerr << "Caught a SYCL host exception:\n" << e.what() << "\n"; + + // Most likely the runtime couldn't find FPGA hardware! + if (e.code().value() == CL_DEVICE_NOT_FOUND) { + std::cerr << "If you are targeting an FPGA, please ensure that your " + "system has a correctly configured FPGA board.\n"; + std::cerr << "Run sys_check in the oneAPI root directory to verify.\n"; + std::cerr << "If you are targeting the FPGA emulator, compile with " + "-DFPGA_EMULATOR.\n"; + } + std::terminate(); + } + + + + std::cout << "done\n"; + return 0; +} -- cgit v1.2.1