-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Memory] Adds typed ptr() and use_host_pointer for CPU modes
- Loading branch information
Showing
10 changed files
with
143 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
namespace occa { | ||
template <class TM> | ||
TM* memory::ptr() { | ||
return (TM*) ptr<void>(); | ||
} | ||
|
||
template <class TM> | ||
const TM* memory::ptr() const { | ||
return (const TM*) ptr<void>(); | ||
} | ||
|
||
template <class TM> | ||
TM* memory::ptr(const occa::properties &props) { | ||
return (TM*) ptr<void>(props); | ||
} | ||
|
||
template <class TM> | ||
const TM* memory::ptr(const occa::properties &props) const { | ||
return (const TM*) ptr<void>(props); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include <occa.hpp> | ||
#include <occa/tools/testing.hpp> | ||
|
||
void testMalloc(); | ||
void testCpuWrapMemory(); | ||
|
||
int main(const int argc, const char **argv) { | ||
testMalloc(); | ||
testCpuWrapMemory(); | ||
|
||
return 0; | ||
} | ||
|
||
void testMalloc() { | ||
const occa::udim_t bytes = 1 * sizeof(int); | ||
int value = 4660; | ||
int *hostPtr = &value; | ||
|
||
occa::memory mem = occa::malloc(bytes); | ||
|
||
mem = occa::malloc(bytes, hostPtr); | ||
ASSERT_EQ(((int*) mem.ptr())[0], value); | ||
ASSERT_NEQ(mem.ptr<int>(), hostPtr); | ||
|
||
mem = occa::malloc(bytes, hostPtr, "use_host_pointer: true"); | ||
ASSERT_EQ(mem.ptr<int>()[0], value); | ||
ASSERT_EQ(mem.ptr<int>(), hostPtr); | ||
} | ||
|
||
void testCpuWrapMemory() { | ||
const occa::udim_t bytes = 1 * sizeof(int); | ||
int value = 4660; | ||
int *hostPtr = &value; | ||
|
||
occa::memory mem = occa::cpu::wrapMemory(hostPtr, bytes); | ||
ASSERT_EQ(mem.ptr<int>()[0], value); | ||
ASSERT_EQ(mem.ptr<int>(), hostPtr); | ||
|
||
mem = occa::cpu::wrapMemory(hostPtr, bytes, "use_host_pointer: false"); | ||
ASSERT_EQ(mem.ptr<int>()[0], value); | ||
ASSERT_EQ(mem.ptr<int>(), hostPtr); | ||
} |