// Simple test showing how to use HC syntax with AM (accelerator memory). // AM provides a set of c-style memory management routines for allocating, // freeing, and copying memory. am_alloc returns a device pointer // which can only be used on the device. The programmer has full control // over when data is copied. #include #include int main(int argc, char *argv[]) { int sizeElements = 1000000; size_t sizeBytes = sizeElements * sizeof(float); bool pass = true; // Allocate host memory float *A_h = (float*)malloc(sizeBytes); float *B_h = (float*)malloc(sizeBytes); float *C_h = (float*)malloc(sizeBytes); // Allocate device pointers: // Unlike array_view, these must be explicitly managed by user: hc::accelerator acc; // grab default accelerator where we want to allocate memory: hc::accelerator_view av = acc.get_default_view(); float *A_d, *B_d, *C_d; A_d = hc::am_alloc(sizeBytes, acc, 0); B_d = hc::am_alloc(sizeBytes, acc, 0); C_d = hc::am_alloc(sizeBytes, acc, 0); // Initialize host data for (int i=0; i (sizeElements), [=] (hc::index<1> idx) [[hc]] { int i = idx[0]; C_d[i] = A_d[i] + B_d[i]; }); // This copy is in same AV as the kernel and thus will wait for the kernel to finish before executing. av.copy(C_d, C_h, sizeBytes); // C++ copy D2H for (int i=0; i