  */
 
 #include <stdio.h>
+#include <unistd.h>
 
 #include "xgpu.h"
 #include "xgpu_info.h"

  }
  context->internal = internal;

  long long unsigned int vecLength = compiletime_info.vecLength;
  long long unsigned int vecLengthPipe = compiletime_info.vecLengthPipe;
  long long unsigned int matLength = compiletime_info.matLength;


    // Register caller-allocated host memory with CUDA.
    // This requires that the caller allocated the memory properly vis-a-vis
    // the requirements of cudaHostRegister!
    size_t length = compiletime_info.matLength*sizeof(Complex);
    // Round length up to next multiple of page size
    length = (length+page_size-1) / page_size * page_size;
    fprintf(stderr, "context->matrix_h = %p\n", context->matrix_h);
    fprintf(stderr, "length = %lx\n", length);
    cudaHostRegister(context->matrix_h, length, 0);
    internal->unregister_matrix_h = context->matrix_h;
    internal->free_matrix_h = NULL;
    checkCudaError();
  } else {
    // allocate host memory
    cudaMallocHost(&(context->matrix_h), compiletime_info.matLength*sizeof(Complex));
