-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathusm_array.hpp
More file actions
133 lines (122 loc) · 3.79 KB
/
Copy pathusm_array.hpp
File metadata and controls
133 lines (122 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
//===----------- usm_array.hpp - class representing an array -*-C++-*- ===//
//
// Data Parallel Control (dpctl)
//
// Copyright 2020-2021 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//===----------------------------------------------------------------------===//
///
/// \file
/// This file defines classes for strided_array, and usm_array
//===----------------------------------------------------------------------===//
#pragma once
#include "dpctl_sycl_types.h"
#include <cstdlib>
namespace usm_array
{
class strided_array
{
public:
/* strided_array is data only class encapsulating information about
* type homogeneous nd-array.
* ptr : pointer to memory block storing array values
* nd : number of indices needed to reference an array element
* shape : pointer to C-array of length `nd` of array dimensions
* strides : pointer to C-array of length `nd` of memory displacements
* for unit increment of each index
* typenum : an integer (enum), encoding value type of array elements
* flags : field to encode additional array attributes
*/
explicit strided_array(char *ptr, int nd, size_t *shape, int typenum)
: ptr_(ptr), nd_(nd), shape_(shape), typenum_(typenum){};
explicit strided_array(char *ptr,
int nd,
size_t *shape,
std::ptrdiff_t *strides,
int typenum)
: ptr_(ptr), nd_(nd), shape_(shape), strides_(strides),
typenum_(typenum){};
explicit strided_array(char *ptr,
int nd,
size_t *shape,
std::ptrdiff_t *strides,
int typenum,
int flags)
: ptr_(ptr), nd_(nd), shape_(shape), strides_(strides),
typenum_(typenum), flags_(flags){};
// member access functions
char *get_data_ptr() const
{
return ptr_;
}
int ndim() const
{
return nd_;
}
size_t *get_shape_ptr() const
{
return shape_;
}
std::ptrdiff_t *get_strides_ptr() const
{
return strides_;
}
int typenum() const
{
return typenum_;
}
int flags() const
{
return flags_;
}
size_t get_shape(int i) const
{
return shape_[i];
}
std::ptrdiff_t get_stride(int i) const
{
return strides_[i];
}
private:
char *ptr_{0};
int nd_{0};
size_t *shape_{0};
std::ptrdiff_t *strides_{0};
int typenum_{0};
int flags_{0};
};
class usm_array : public strided_array
{
public:
/*
* usm_array additionally carries DPCTLSyclQueueRef
* recording Sycl context the data USM pointer is bound to
*/
explicit usm_array(char *data,
int nd,
size_t *shape,
std::ptrdiff_t *strides,
int typenum,
int flags,
DPCTLSyclQueueRef qref)
: strided_array(data, nd, shape, strides, typenum, flags), q_(qref){};
DPCTLSyclQueueRef get_queue_ref() const
{
return q_;
}
private:
DPCTLSyclQueueRef q_{0};
};
} // namespace usm_array