Skip to content

Commit 2d9e3c7

Browse files
committed
Adds outward interoperability functions to core occa types. (#635)
* Adds outward interoperability functions to core occa types. * Fixes line endings. * Fixes line endings. * Implements `memory::unwrap` for serial mode. * Documents outward interoperability functions for core occa types.
1 parent df2ad58 commit 2d9e3c7

66 files changed

Lines changed: 401 additions & 1 deletion

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

include/occa/core/base.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ namespace occa {
133133

134134
void printModeInfo();
135135
//====================================
136+
137+
template<typename T>
138+
void* unwrap(T& occaType);
136139
}
137140

138141
#include "base.tpp"

include/occa/core/base.tpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,9 @@ namespace occa {
1212
const occa::json &props) {
1313
return getDevice().wrapMemory(ptr, entries, occa::dtype::get<T>(), props);
1414
}
15+
16+
template<typename T>
17+
void* unwrap(T& occaType) {
18+
return occaType.unwrap();
19+
}
1520
}

include/occa/core/device.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,23 @@ namespace occa {
730730
experimental::memoryPool createMemoryPool(const occa::json &props = occa::json());
731731

732732
// |===============================
733+
734+
/**
735+
* @startDoc{unwrap}
736+
*
737+
* Description:
738+
* Retreives the mode-specific object associated with this [[device]].
739+
* The lifetime of the returned object is the same as this device.
740+
* Destruction of the returned object during this device's lifetime results in undefined behavior.
741+
*
742+
* > An OCCA application is responsible for correctly converting the returned `void*` pointer to the corresponding mode-specific device type.
743+
*
744+
* Returns:
745+
* A pointer to the mode-specific object associated with this device.
746+
*
747+
* @endDoc
748+
*/
749+
void* unwrap();
733750
};
734751

735752
template <>

include/occa/core/memory.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,23 @@ namespace occa {
460460
void free();
461461

462462
void detach();
463+
464+
/**
465+
* @startDoc{unwrap}
466+
*
467+
* Description:
468+
* Retreives the mode-specific object associated with this [[stream]].
469+
* The lifetime of the returned object is the same as this stream.
470+
* Destruction of the returned object during this stream's lifetime results in undefined behavior.
471+
*
472+
* > An OCCA application is responsible for correctly converting the returned `void*` pointer to the corresponding mode-specific stream type.
473+
*
474+
* Returns:
475+
* A pointer to the mode-specific object associated with this stream.
476+
*
477+
* @endDoc
478+
*/
479+
void* unwrap();
463480
};
464481

465482
extern memory null;

include/occa/core/stream.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,23 @@ namespace occa {
147147
* @endDoc
148148
*/
149149
void finish();
150+
151+
/**
152+
* @startDoc{unwrap}
153+
*
154+
* Description:
155+
* Retreives the mode-specific object associated with this [[memory]].
156+
* The lifetime of the returned object is the same as this memory.
157+
* Destruction of the returned object during this memory's lifetime results in undefined behavior.
158+
*
159+
* > An OCCA application is responsible for correctly converting the returned `void*` pointer to the corresponding mode-specific memory type.
160+
*
161+
* Returns:
162+
* A pointer to the mode-specific object associated with this stream.
163+
*
164+
* @endDoc
165+
*/
166+
void* unwrap();
150167
};
151168

152169
std::ostream& operator << (std::ostream &out,

include/occa/core/streamTag.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,23 @@ namespace occa {
122122
* @endDoc
123123
*/
124124
void free();
125+
126+
/**
127+
* @startDoc{unwrap}
128+
*
129+
* Description:
130+
* Retreives the mode-specific object associated with this [[streamTag]].
131+
* The lifetime of the returned object is the same as this streamTag.
132+
* Destruction of the returned object during this streamTag's lifetime results in undefined behavior.
133+
*
134+
* > An OCCA application is responsible for correctly converting the returned `void*` pointer to the corresponding mode-specific streamTag type.
135+
*
136+
* Returns:
137+
* A pointer to the mode-specific object associated with this streamTag
138+
*
139+
* @endDoc
140+
*/
141+
void* unwrap();
125142
};
126143
}
127144

src/core/device.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,13 @@ namespace occa {
535535
}
536536
// |=================================
537537

538+
void* device::unwrap() {
539+
assertInitialized();
540+
return modeDevice->unwrap();
541+
}
542+
543+
// |=================================
544+
538545
template <>
539546
hash_t hash(const occa::device &device) {
540547
return device.hash();

src/core/memory.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,11 @@ namespace occa {
338338
modeMemory = nullptr;
339339
}
340340

341+
void* memory::unwrap() {
342+
assertInitialized();
343+
return modeMemory->unwrap();
344+
}
345+
341346
memory null;
342347

343348
std::ostream& operator << (std::ostream &out,

src/core/stream.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ namespace occa {
102102
if(modeStream) modeStream->finish();
103103
}
104104

105+
void* stream::unwrap() {
106+
OCCA_ERROR(
107+
"stream::unwrap: stream is uninitialized or has been free'd",
108+
nullptr != modeStream
109+
);
110+
return modeStream->unwrap();
111+
}
112+
105113
std::ostream& operator << (std::ostream &out,
106114
const occa::stream &stream) {
107115
out << stream.properties();

src/core/streamTag.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,12 @@ namespace occa {
8989
delete modeStreamTag;
9090
modeStreamTag = NULL;
9191
}
92+
93+
void* streamTag::unwrap() {
94+
OCCA_ERROR(
95+
"streamTag::unwrap: stream is uninitialized or has been free'd",
96+
nullptr != modeStreamTag
97+
);
98+
return modeStreamTag->unwrap();
99+
}
92100
}

0 commit comments

Comments
 (0)