@@ -154,6 +154,15 @@ RT_API_ATTRS std::size_t Descriptor::Elements() const {
154
154
return elements;
155
155
}
156
156
157
+ RT_API_ATTRS static inline int MapAllocIdx (const Descriptor &desc) {
158
+ #ifdef RT_DEVICE_COMPILATION
159
+ // Force default allocator in device code.
160
+ return kDefaultAllocator ;
161
+ #else
162
+ return desc.GetAllocIdx ();
163
+ #endif
164
+ }
165
+
157
166
RT_API_ATTRS int Descriptor::Allocate () {
158
167
std::size_t elementBytes{ElementBytes ()};
159
168
if (static_cast <std::int64_t >(elementBytes) < 0 ) {
@@ -162,11 +171,10 @@ RT_API_ATTRS int Descriptor::Allocate() {
162
171
elementBytes = raw_.elem_len = 0 ;
163
172
}
164
173
std::size_t byteSize{Elements () * elementBytes};
174
+ AllocFct alloc{allocatorRegistry.GetAllocator (MapAllocIdx (*this ))};
165
175
// Zero size allocation is possible in Fortran and the resulting
166
176
// descriptor must be allocated/associated. Since std::malloc(0)
167
177
// result is implementation defined, always allocate at least one byte.
168
-
169
- AllocFct alloc{allocatorRegistry.GetAllocator (GetAllocIdx ())};
170
178
void *p{alloc (byteSize ? byteSize : 1 )};
171
179
if (!p) {
172
180
return CFI_ERROR_MEM_ALLOCATION;
@@ -209,7 +217,7 @@ RT_API_ATTRS int Descriptor::Deallocate() {
209
217
if (!descriptor.base_addr ) {
210
218
return CFI_ERROR_BASE_ADDR_NULL;
211
219
} else {
212
- FreeFct free{allocatorRegistry.GetDeallocator (GetAllocIdx ( ))};
220
+ FreeFct free{allocatorRegistry.GetDeallocator (MapAllocIdx (* this ))};
213
221
free (descriptor.base_addr );
214
222
descriptor.base_addr = nullptr ;
215
223
return CFI_SUCCESS;
0 commit comments