oneAPI Deep Neural Network Library (oneDNN)
Performance library for Deep Learning
2.1.0
dnnl_threadpool.hpp
1 /*******************************************************************************
2 * Copyright 2020 Intel Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *******************************************************************************/
16 
17 #ifndef ONEAPI_DNNL_DNNL_THREADPOOL_HPP
18 #define ONEAPI_DNNL_DNNL_THREADPOOL_HPP
19 
20 #include "oneapi/dnnl/dnnl.hpp"
21 #include "oneapi/dnnl/dnnl_threadpool.h"
22 
23 #include "oneapi/dnnl/dnnl_threadpool_iface.hpp"
24 
27 
28 namespace dnnl {
29 
32 
36 
38 namespace threadpool_interop {
39 
49  const dnnl::engine &aengine, threadpool_iface *threadpool) {
50  dnnl_stream_t c_stream;
52  &c_stream, aengine.get(), threadpool),
53  "could not create stream");
54  return dnnl::stream(c_stream);
55 }
56 
65 inline threadpool_iface *get_threadpool(const dnnl::stream &astream) {
66  void *tp;
69  "could not get stream threadpool");
70  return static_cast<threadpool_iface *>(tp);
71 }
72 
74 inline status sgemm(char transa, char transb, dnnl_dim_t M, dnnl_dim_t N,
75  dnnl_dim_t K, float alpha, const float *A, dnnl_dim_t lda,
76  const float *B, dnnl_dim_t ldb, float beta, float *C, dnnl_dim_t ldc,
77  threadpool_iface *tp) {
78  return static_cast<status>(dnnl_threadpool_interop_sgemm(
79  transa, transb, M, N, K, alpha, A, lda, B, ldb, beta, C, ldc, tp));
80 }
82 inline status gemm_u8s8s32(char transa, char transb, char offsetc, dnnl_dim_t M,
83  dnnl_dim_t N, dnnl_dim_t K, float alpha, const uint8_t *A,
84  dnnl_dim_t lda, uint8_t ao, const int8_t *B, dnnl_dim_t ldb, int8_t bo,
85  float beta, int32_t *C, dnnl_dim_t ldc, const int32_t *co,
86  threadpool_iface *tp) {
87  return static_cast<status>(
88  dnnl_threadpool_interop_gemm_u8s8s32(transa, transb, offsetc, M, N,
89  K, alpha, A, lda, ao, B, ldb, bo, beta, C, ldc, co, tp));
90 }
91 
93 inline status gemm_s8s8s32(char transa, char transb, char offsetc, dnnl_dim_t M,
94  dnnl_dim_t N, dnnl_dim_t K, float alpha, const int8_t *A,
95  dnnl_dim_t lda, int8_t ao, const int8_t *B, dnnl_dim_t ldb, int8_t bo,
96  float beta, int32_t *C, dnnl_dim_t ldc, const int32_t *co,
97  threadpool_iface *tp) {
98  return static_cast<status>(
99  dnnl_threadpool_interop_gemm_s8s8s32(transa, transb, offsetc, M, N,
100  K, alpha, A, lda, ao, B, ldb, bo, beta, C, ldc, co, tp));
101 }
102 
103 } // namespace threadpool_interop
104 
106 
108 
109 } // namespace dnnl
110 
112 
113 #endif
status sgemm(char transa, char transb, dnnl_dim_t M, dnnl_dim_t N, dnnl_dim_t K, float alpha, const float *A, dnnl_dim_t lda, const float *B, dnnl_dim_t ldb, float beta, float *C, dnnl_dim_t ldc, threadpool_iface *tp)
Definition: dnnl_threadpool.hpp:74
dnnl_status_t DNNL_API dnnl_threadpool_interop_sgemm(char transa, char transb, dnnl_dim_t M, dnnl_dim_t N, dnnl_dim_t K, float alpha, const float *A, dnnl_dim_t lda, const float *B, dnnl_dim_t ldb, float beta, float *C, dnnl_dim_t ldc, void *threadpool)
Performs single-precision matrix-matrix multiply.
oneDNN namespace
Definition: dnnl.hpp:74
dnnl::stream make_stream(const dnnl::engine &aengine, threadpool_iface *threadpool)
Constructs an execution stream for the specified engine and threadpool.
Definition: dnnl_threadpool.hpp:48
status gemm_u8s8s32(char transa, char transb, char offsetc, dnnl_dim_t M, dnnl_dim_t N, dnnl_dim_t K, float alpha, const uint8_t *A, dnnl_dim_t lda, uint8_t ao, const int8_t *B, dnnl_dim_t ldb, int8_t bo, float beta, int32_t *C, dnnl_dim_t ldc, const int32_t *co, threadpool_iface *tp)
Definition: dnnl_threadpool.hpp:82
dnnl_status_t DNNL_API dnnl_threadpool_interop_gemm_u8s8s32(char transa, char transb, char offsetc, dnnl_dim_t M, dnnl_dim_t N, dnnl_dim_t K, float alpha, const uint8_t *A, dnnl_dim_t lda, uint8_t ao, const int8_t *B, dnnl_dim_t ldb, int8_t bo, float beta, int32_t *C, dnnl_dim_t ldc, const int32_t *co, void *threadpool)
Performs integer matrix-matrix multiply on 8-bit unsigned matrix A, 8-bit signed matrix B...
An execution engine.
Definition: dnnl.hpp:869
int64_t dnnl_dim_t
A type to describe tensor dimension.
Definition: dnnl_types.h:1333
threadpool_iface * get_threadpool(const dnnl::stream &astream)
Returns the pointer to a threadpool that is used by an execution stream.
Definition: dnnl_threadpool.hpp:65
T get(bool allow_empty=false) const
Returns the underlying C API handle.
Definition: dnnl.hpp:185
status
Status values returned by the library functions.
Definition: dnnl.hpp:10789
status gemm_s8s8s32(char transa, char transb, char offsetc, dnnl_dim_t M, dnnl_dim_t N, dnnl_dim_t K, float alpha, const int8_t *A, dnnl_dim_t lda, int8_t ao, const int8_t *B, dnnl_dim_t ldb, int8_t bo, float beta, int32_t *C, dnnl_dim_t ldc, const int32_t *co, threadpool_iface *tp)
Definition: dnnl_threadpool.hpp:93
static void wrap_c_api(dnnl_status_t status, const char *message)
A convenience function for wrapping calls to C API functions.
Definition: dnnl.hpp:103
C++ API.
Abstract threadpool interface.
Definition: dnnl_threadpool_iface.hpp:38
dnnl_status_t DNNL_API dnnl_threadpool_interop_stream_get_threadpool(dnnl_stream_t astream, void **threadpool)
Returns a threadpool to be used by the execution stream.
dnnl_status_t DNNL_API dnnl_threadpool_interop_stream_create(dnnl_stream_t *stream, dnnl_engine_t engine, void *threadpool)
Creates an execution stream with specified threadpool.
An opaque structure to describe an execution stream.
dnnl_status_t DNNL_API dnnl_threadpool_interop_gemm_s8s8s32(char transa, char transb, char offsetc, dnnl_dim_t M, dnnl_dim_t N, dnnl_dim_t K, float alpha, const int8_t *A, dnnl_dim_t lda, int8_t ao, const int8_t *B, dnnl_dim_t ldb, int8_t bo, float beta, int32_t *C, dnnl_dim_t ldc, const int32_t *co, void *threadpool)
Performs integer matrix-matrix multiply on 8-bit signed matrix A, 8-bit signed matrix B...
An execution stream.
Definition: dnnl.hpp:985