Created
July 11, 2015 02:12
-
-
Save navyxliu/e02ed95819dd4a91c33e to your computer and use it in GitHub Desktop.
pass object pointer
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
#include <amp.h> | |
#include <vector> | |
#include <stdlib.h> | |
using namespace concurrency; | |
using namespace std; | |
const static int DOMAIN_SIZE = 1024; | |
const static int BLOCK_SIZE = 16; | |
typedef int TY; | |
template<typename type, int rank> | |
struct s1 | |
{ | |
s1(Concurrency::array<type, rank> &a) __GPU : av_a(a) {} | |
s1(Concurrency::extent<rank> e, type *pa) __GPU : av_a(e, pa){} | |
~s1() __GPU {} | |
int placeholder1; | |
array_view<type, rank> av_a; | |
float placeholder2; | |
}; | |
void bar0(index<1> idx, s1<TY, 1> *p) restrict(amp) { | |
int * pa = &p->av_a[idx]; | |
*pa = 1; | |
} | |
void bar(tiled_index<BLOCK_SIZE> idx, s1<TY, 1> *p) __GPU { | |
int * pa = &p->av_a[idx]; | |
*pa = 1; | |
} | |
void foo() { | |
Concurrency::extent<1> g(DOMAIN_SIZE); | |
vector<int> a(DOMAIN_SIZE); | |
Concurrency::array<int, 1> a_a(g); | |
// parallel_for_each(a_a.get_extent().template tile<BLOCK_SIZE>(), [&] (tiled_index<BLOCK_SIZE> idx) restrict(amp) { | |
parallel_for_each(a_a.get_extent(), [&] (index<1> idx) restrict(amp) { | |
s1<TY,1> o(a_a); | |
bar0(idx, &o); | |
// a_a[idx] = 1; | |
}); | |
a = a_a; | |
for (int i=0; i<DOMAIN_SIZE; ++i) { | |
if (a[i] != 1) { | |
fprintf(stderr, "wrong answer idx = %d bad value= %d\n", i, a[i]); | |
exit(-1); | |
} | |
} | |
} | |
int main() { | |
foo(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
[1105123.203229] VM fault (0x01, vmid 1) at page 268404840, read from TC (72)
[1105138.940925] radeon 0000:01:00.0: GPU fault detected: 147 0x0da20401
[1105138.940928] radeon 0000:01:00.0: VM_CONTEXT1_PROTECTION_FAULT_ADDR 0x0FF02F6D
[1105138.940929] radeon 0000:01:00.0: VM_CONTEXT1_PROTECTION_FAULT_STATUS 0x02004001
[1105138.940931] VM fault (0x01, vmid 1) at page 267399021, read from TC (4)