src/runtime_src/core/edge/skd/sk_daemon.cpp
static int createSoftKernelFile(uint64_t paddr, size_t size, uint32_t cuidx)
{
  xclDeviceHandle handle;
  unsigned int boHandle;
  FILE *fptr;
  void *buf;
  char path[XRT_MAX_PATH_LENGTH];
  int len, i;

  handle = initXRTHandle(0);
  if (!handle) {
    syslog(LOG_ERR, "Cannot initialize XRT.\n");
    return -1;
  }

  boHandle = xclGetHostBO(handle, paddr, size);
  buf = xclMapBO(handle, boHandle, false);
  if (!buf) {
    syslog(LOG_ERR, "Cannot map xlcbin BO.\n");
    return -1;
  }

  snprintf(path, XRT_MAX_PATH_LENGTH, "%s", SOFT_KERNEL_FILE_PATH);
  len = strlen(path);

  /* If not exist, create the path one by one. */
  for (i = 1; i < len; i++) {
    if (path[i] == '/') {
      path[i] = '\0';
      if (access(path, F_OK) != 0) {
        if (mkdir(path, 0744) != 0) {
          syslog(LOG_ERR, "Cannot create soft kernel file.\n");
          return -1;
        }
      }
      path[i] = '/';
    }
  }

  /* Create soft kernel file */
  getSoftKernelPathName(cuidx, path);

  fptr = fopen(path, "w+b");
  if (fptr == NULL) {
     syslog(LOG_ERR, "Cannot create file: %s\n", path);
     return -1;
  }

  /* copy the soft kernel to file */
  if (fwrite(buf, size, 1, fptr) != 1) {
    syslog(LOG_ERR, "Fail to write to file %s.\n", path);
    fclose(fptr);
    return -1;
  }

  fclose(fptr);
  xclClose(handle);

  return 0;
}
/*
 * This function create a soft kernel file.
 * paddr  : The physical address of the soft kernel shared object.
 *          This image is DMAed from host to PS's memory. The XRT
 *          provides interface to create a BO handle for this
 *          memory and map it to process's memory space. So that
 *          we can create a file and copy the image to it.
 * size   : Size of the soft kenel image.
 * cuidx  : CU index. The file will be name bease on fixed path
 *          and name plus the CU index.
 */
This function create a soft kernel file.
paddr  : The physical address of the soft kernel shared object.
This image is DMAed from host to PS's memory. The XRT
provides interface to create a BO handle for this
memory and map it to process's memory space. So that
we can create a file and copy the image to it.
size   : Size of the soft kenel image.
cuidx  : CU index. The file will be name bease on fixed path
and name plus the CU index.
This function create a soft kernel file . paddr : The physical address of the soft kernel shared object . This image is DMAed from host to PS ' s memory . The XRT provides interface to create a BO handle for this memory and map it to process ' s memory space . So that we can create a file and copy the image to it . size : Size of the soft kenel image . cuidx : CU index . The file will be name bease on fixed path and name plus the CU index .
static int createSoftKernelFile(uint64_t paddr, size_t size, uint32_t cuidx)
{
  xclDeviceHandle handle;
  unsigned int boHandle;
  FILE *fptr;
  void *buf;
  char path[XRT_MAX_PATH_LENGTH];
  int len, i;
  handle = initXRTHandle(0);
  if (!handle) {
    syslog(LOG_ERR, "Cannot initialize XRT.\n");
    return -1;
  }
  boHandle = xclGetHostBO(handle, paddr, size);
  buf = xclMapBO(handle, boHandle, false);
  if (!buf) {
    syslog(LOG_ERR, "Cannot map xlcbin BO.\n");
    return -1;
  }
  snprintf(path, XRT_MAX_PATH_LENGTH, "%s", SOFT_KERNEL_FILE_PATH);
  len = strlen(path);
  for (i = 1; i < len; i++) {
    if (path[i] == '/') {
      path[i] = '\0';
      if (access(path, F_OK) != 0) {
        if (mkdir(path, 0744) != 0) {
          syslog(LOG_ERR, "Cannot create soft kernel file.\n");
          return -1;
        }
      }
      path[i] = '/';
    }
  }
  getSoftKernelPathName(cuidx, path);
  fptr = fopen(path, "w+b");
  if (fptr == NULL) {
     syslog(LOG_ERR, "Cannot create file: %s\n", path);
     return -1;
  }
  if (fwrite(buf, size, 1, fptr) != 1) {
    syslog(LOG_ERR, "Fail to write to file %s.\n", path);
    fclose(fptr);
    return -1;
  }
  fclose(fptr);
  xclClose(handle);
  return 0;
}
static int createSoftKernelFile ( uint64_t paddr , size_t size , uint32_t cuidx ) { xclDeviceHandle handle ; unsigned int boHandle ; FILE * fptr ; void * buf ; char path [ XRT_MAX_PATH_LENGTH ] ; int len , i ; handle = initXRTHandle ( 0 ) ; if ( ! handle ) { syslog ( LOG_ERR , " \n " ) ; return -1 ; } boHandle = xclGetHostBO ( handle , paddr , size ) ; buf = xclMapBO ( handle , boHandle , false ) ; if ( ! buf ) { syslog ( LOG_ERR , " \n " ) ; return -1 ; } snprintf ( path , XRT_MAX_PATH_LENGTH , " " , SOFT_KERNEL_FILE_PATH ) ; len = strlen ( path ) ; for ( i = 1 ; i < len ; i ++ ) { if ( path [ i ] == ' ' ) { path [ i ] = ' \0 ' ; if ( access ( path , F_OK ) != 0 ) { if ( mkdir ( path , 0744 ) != 0 ) { syslog ( LOG_ERR , " \n " ) ; return -1 ; } } path [ i ] = ' ' ; } } getSoftKernelPathName ( cuidx , path ) ; fptr = fopen ( path , " " ) ; if ( fptr == NULL ) { syslog ( LOG_ERR , " \n " , path ) ; return -1 ; } if ( fwrite ( buf , size , 1 , fptr ) != 1 ) { syslog ( LOG_ERR , " \n " , path ) ; fclose ( fptr ) ; return -1 ; } fclose ( fptr ) ; xclClose ( handle ) ; return 0 ; }
This function create a soft kernel file.
This function create a soft kernel file .
/* If not exist, create the path one by one. */ /* Create soft kernel file */ /* copy the soft kernel to file */