Skip to content

Instantly share code, notes, and snippets.

@navyxliu
Created October 26, 2014 08:45
Show Gist options
  • Save navyxliu/cc624857eb54f13db2fb to your computer and use it in GitHub Desktop.
Save navyxliu/cc624857eb54f13db2fb to your computer and use it in GitHub Desktop.
bug011.cc
//adapted from bug011
#include <amp.h>
using namespace Concurrency;
int test() restrict(amp)
{
int data0[] = {1, 2, 3, 4};
extent<4> e4(data0);
for (int i = 0; i < 4; i++)
{
if (e4[i] != i + 1)
{
return 12;
}
}
return 0;
}
void kernel(index<1>& idx, array<int, 1>& result) restrict(amp)
{
result[idx] = test();
}
const int size = 4;
int test_device()
{
accelerator device;// = require_device(Device::ALL_DEVICES);
accelerator_view av = device.get_default_view();
extent<1> e(size);
array<int, 1> result(e, av);
std::vector<int> presult(size, 0);
parallel_for_each(e, [&](index<1> idx) restrict(amp) {
kernel(idx, result);
});
presult = result;
for (int i = 0; i < size; i++)
{
if (presult[i] != 0)
{
printf("Test failed. Return code: %d\n", presult[i]);
return 1;
}
}
return 0;
}
int main(int argc, char **argv)
{
int result = test_device();
printf("Test %s on device\n", ((result == 0) ? "passed" : "failed"));
return result;
}
@navyxliu
Copy link
Author

navyxliu commented Aug 3, 2015

vadimg: yes, that's wrong. it shouldn't be converted to address space 1 (global) pointer. emitter does that because we have no info about address spaces in WHIRL, and by default it assumes global ptr

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