Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
openclenvironment.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2023 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19/*! \file qle/math/openclenvironment.hpp
20 \brief opencl compute env implementation
21*/
22
23#pragma once
24
26
27#include <boost/thread/lock_types.hpp>
28#include <boost/thread/shared_mutex.hpp>
29
30#include <map>
31
32#ifdef ORE_ENABLE_OPENCL
33#ifdef __APPLE__
34#include <OpenCL/cl.h>
35#else
36#include <CL/cl.h>
37#endif
38#endif
39
40#define ORE_OPENCL_MAX_N_PLATFORMS 4U
41#define ORE_OPENCL_MAX_N_DEVICES 8U
42
43namespace QuantExt {
44
46public:
48 ~OpenClFramework() override final;
49 std::set<std::string> getAvailableDevices() const override final;
50 ComputeContext* getContext(const std::string& deviceName) override final;
51
52private:
53 static void init();
54
55 std::map<std::string, ComputeContext*> contexts_;
56
57 static boost::shared_mutex mutex_;
58 static bool initialized_;
59#ifdef ORE_ENABLE_OPENCL
60 static cl_uint nPlatforms_;
61 static cl_uint nDevices_[ORE_OPENCL_MAX_N_PLATFORMS];
62 static cl_device_id devices_[ORE_OPENCL_MAX_N_PLATFORMS][ORE_OPENCL_MAX_N_DEVICES];
63 static cl_context context_[ORE_OPENCL_MAX_N_PLATFORMS][ORE_OPENCL_MAX_N_DEVICES];
64#endif
67 static std::vector<std::pair<std::string, std::string>> deviceInfo_[ORE_OPENCL_MAX_N_PLATFORMS]
70};
71
72} // namespace QuantExt
std::map< std::string, ComputeContext * > contexts_
static std::string platformName_[4U]
static std::vector< std::pair< std::string, std::string > > deviceInfo_[4U][8U]
static std::string deviceName_[4U][8U]
static bool supportsDoublePrecision_[4U][8U]
static boost::shared_mutex mutex_
ComputeContext * getContext(const std::string &deviceName) override final
std::set< std::string > getAvailableDevices() const override final
interface to compute envs
#define ORE_OPENCL_MAX_N_PLATFORMS
#define ORE_OPENCL_MAX_N_DEVICES