Skip to content

Instantly share code, notes, and snippets.

@navyxliu
Created July 25, 2015 17:02
Show Gist options
  • Save navyxliu/c6bb74352ecff08eba77 to your computer and use it in GitHub Desktop.
Save navyxliu/c6bb74352ecff08eba77 to your computer and use it in GitHub Desktop.
broken case
#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 foo2() {
Concurrency::extent<1> g(DOMAIN_SIZE);
vector<int> a(DOMAIN_SIZE);
Concurrency::array<int, 1> a_a(g);
Concurrency::array<int, 1> a_b(g);
int b1 = 0;
parallel_for_each(a_a.get_extent(), [&, b1] (index<1> idx) restrict(amp) {
s1<int,1> o(a_a);
s1<int,1> o_f(a_b);
s1<int, 1> *p = !b1 ? &o : &(o_f); // broken
//s1<int, 1> *p = &o; //okay
bar0(idx, p);
});
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() {
foo2();
}
@navyxliu
Copy link
Author

pathamp -device=tahiti -CG2:dump-opt-ir -Wb,-tt61:0x1 ./t5.cpp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment