[SYCL] Add oneDNN primitive support (#9091)
* add onednn * add sycl_f16 * add dnnl stream * add engine map * use dnnl for intel only * use fp16fp16fp16 * update doc
This commit is contained in:
parent
a1631e53f6
commit
1731d4238f
6 changed files with 186 additions and 10 deletions
|
@ -19,6 +19,10 @@
|
|||
#include "dpct/helper.hpp"
|
||||
#include "ggml-sycl.h"
|
||||
#include "presets.hpp"
|
||||
#if GGML_SYCL_DNNL
|
||||
#include "dnnl.hpp"
|
||||
#include "dnnl_sycl.hpp"
|
||||
#endif
|
||||
|
||||
#define GGML_COMMON_DECL_SYCL
|
||||
#define GGML_COMMON_IMPL_SYCL
|
||||
|
@ -277,6 +281,52 @@ struct ggml_backend_sycl_context {
|
|||
return stream(device, 0);
|
||||
}
|
||||
|
||||
#if GGML_SYCL_DNNL
|
||||
dnnl::engine make_engine(sycl::queue* q) {
|
||||
// Get the device associated with the queue
|
||||
sycl::device dev = q->get_device();
|
||||
// Get the context associated with the queue
|
||||
sycl::context ctx = q->get_context();
|
||||
const dnnl::engine eng = dnnl::sycl_interop::make_engine(dev, ctx);
|
||||
return eng;
|
||||
}
|
||||
|
||||
std::unordered_map<sycl::queue*, dnnl::stream> stream_map;
|
||||
std::unordered_map<sycl::queue*, dnnl::engine> engine_map;
|
||||
dnnl::stream stream_dnnl(int device, int _stream) {
|
||||
auto q = stream(device, _stream);
|
||||
return stream_dnnl(q);
|
||||
}
|
||||
dnnl::engine engine_dnnl(sycl::queue* qptr) {
|
||||
auto it = engine_map.find(qptr);
|
||||
if (it == engine_map.end()) {
|
||||
auto eng = make_engine(qptr);
|
||||
engine_map[qptr] = eng;
|
||||
return eng;
|
||||
}
|
||||
else
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
}
|
||||
dnnl::stream stream_dnnl(sycl::queue* qptr) {
|
||||
auto it = stream_map.find(qptr);
|
||||
if (it == stream_map.end()) {
|
||||
auto eng = engine_dnnl(qptr);
|
||||
auto stream = dnnl::sycl_interop::make_stream(eng, *qptr);
|
||||
stream_map[qptr] = stream;
|
||||
return stream;
|
||||
}
|
||||
else
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
}
|
||||
dnnl::stream stream_dnnl() {
|
||||
return stream_dnnl(device, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
// pool
|
||||
std::unique_ptr<ggml_sycl_pool> pools[GGML_SYCL_MAX_DEVICES];
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue