|
| 1 | +//==------------ fpga_dsp_control.hpp --- SYCL FPGA DSP Control ------------==// |
| 2 | +// |
| 3 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | +// See https://llvm.org/LICENSE.txt for license information. |
| 5 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | +// |
| 7 | +//===----------------------------------------------------------------------===// |
| 8 | +#pragma once |
| 9 | + |
| 10 | +__SYCL_INLINE_NAMESPACE(cl) { |
| 11 | +namespace sycl { |
| 12 | +namespace ext { |
| 13 | +namespace intel { |
| 14 | + |
| 15 | +enum class Preference { DSP, Softlogic, Compiler_default }; |
| 16 | +enum class Propagate { On, Off }; |
| 17 | + |
| 18 | +template <typename Function> |
| 19 | +#ifdef __SYCL_DEVICE_ONLY__ |
| 20 | +[[intel::prefer_dsp]] |
| 21 | +[[intel::propagate_dsp_preference]] |
| 22 | +#endif // __SYCL_DEVICE_ONLY__ |
| 23 | +void math_prefer_dsp_propagate(Function f) |
| 24 | +{ |
| 25 | + f(); |
| 26 | +} |
| 27 | + |
| 28 | +template <typename Function> |
| 29 | +#ifdef __SYCL_DEVICE_ONLY__ |
| 30 | +[[intel::prefer_dsp]] |
| 31 | +#endif // __SYCL_DEVICE_ONLY__ |
| 32 | +void math_prefer_dsp_no_propagate(Function f) |
| 33 | +{ |
| 34 | + f(); |
| 35 | +} |
| 36 | + |
| 37 | +template <typename Function> |
| 38 | +#ifdef __SYCL_DEVICE_ONLY__ |
| 39 | +[[intel::prefer_softlogic]] |
| 40 | +[[intel::propagate_dsp_preference]] |
| 41 | +#endif // __SYCL_DEVICE_ONLY__ |
| 42 | +void math_prefer_softlogic_propagate(Function f) |
| 43 | +{ |
| 44 | + f(); |
| 45 | +} |
| 46 | + |
| 47 | +template <typename Function> |
| 48 | +#ifdef __SYCL_DEVICE_ONLY__ |
| 49 | +[[intel::prefer_softlogic]] |
| 50 | +#endif // __SYCL_DEVICE_ONLY__ |
| 51 | +void math_prefer_softlogic_no_propagate(Function f) |
| 52 | +{ |
| 53 | + f(); |
| 54 | +} |
| 55 | + |
| 56 | +template <Preference my_preference = Preference::DSP, |
| 57 | + Propagate my_propagate = Propagate::On, typename Function> |
| 58 | +void math_dsp_control(Function f) { |
| 59 | + if (my_preference == Preference::DSP) { |
| 60 | + if (my_propagate == Propagate::On) { |
| 61 | + math_prefer_dsp_propagate(f); |
| 62 | + } else { |
| 63 | + math_prefer_dsp_no_propagate(f); |
| 64 | + } |
| 65 | + } else if (my_preference == Preference::Softlogic) { |
| 66 | + if (my_propagate == Propagate::On) { |
| 67 | + math_prefer_softlogic_propagate(f); |
| 68 | + } else { |
| 69 | + math_prefer_softlogic_no_propagate(f); |
| 70 | + } |
| 71 | + } else { // my_preference == Preference::Compiler_default |
| 72 | + math_prefer_dsp_no_propagate([&]() { f(); }); |
| 73 | + } |
| 74 | +} |
| 75 | + |
| 76 | +} // namespace intel |
| 77 | +} // namespace ext |
| 78 | +} // namespace sycl |
| 79 | +} // __SYCL_INLINE_NAMESPACE(cl) |
0 commit comments