使用COO作为输入时,nvGRAPH SSSP示例代码给出错误8

时间:2018-09-26 09:38:36

标签: cuda nvgraph

我复制了nvGRAPH提供的example code来计算SSSP,并修改了代码,以使我使用COO(而不是CSC)作为输入图形格式。

在调用nvgraphSetGraphStructure的行上,我得到一个type not supported by this function错误的ERROR 8。错误说明还指出,这通常是由于将无效的图形描述符传递给函数引起的。但是,我认为情况并非如此。

代码示例:

  #include <stdio.h>
  #include <cuda_runtime.h>
  #include <nvgraph.h>
  #include <curand.h>
  #include <curand_kernel.h>
  #include <iostream>

  void check(nvgraphStatus_t status) {
      if (status != NVGRAPH_STATUS_SUCCESS) {
          printf("ERROR : %d\n", status);
          exit(0);
      }
  }

  int main(int argc, char **argv) {
     const size_t  n = 6, nnz = 10, vertex_numsets = 1, edge_numsets = 1;
     float *sssp_1_h;
     void** vertex_dim;

     // nvgraph variables
     nvgraphStatus_t status;
     nvgraphHandle_t handle;
     nvgraphGraphDescr_t graph;
     nvgraphCOOTopology32I_t COO_input;
     cudaDataType_t edge_dimT = CUDA_R_32F;
     cudaDataType_t* vertex_dimT;

     // Init host data
     sssp_1_h = (float*)malloc(n*sizeof(float));
     vertex_dim  = (void**)malloc(vertex_numsets*sizeof(void*));
     vertex_dimT = (cudaDataType_t*)malloc(vertex_numsets*sizeof(cudaDataType_t));
     COO_input = (nvgraphCOOTopology32I_t) malloc(sizeof(struct nvgraphCOOTopology32I_st));
     vertex_dim[0]= (void*)sssp_1_h;
     vertex_dimT[0] = CUDA_R_32F;

     int source_indices_h[]       =   {2, 0, 2, 0, 4, 5, 2, 3, 3, 4};
     int destination_indices_h[]  =   {0, 1, 1, 2, 3, 3, 4, 4, 5, 5};
     float weights_h[] = {0.333333, 0.5, 0.333333, 0.5, 0.5, 1.0, 0.333333, 0.5, 0.5, 0.5};

     check(nvgraphCreate(&handle));
     check(nvgraphCreateGraphDescr (handle, &graph));
     COO_input->nvertices = n;
     COO_input->nedges = nnz;
     COO_input->source_indices = source_indices_h;
     COO_input->destination_indices = destination_indices_h;
     COO_input->tag = NVGRAPH_UNSORTED;

     // Set graph connectivity and properties (tranfers)
     check(nvgraphSetGraphStructure(handle, graph, (void*)COO_input, NVGRAPH_COO_32)); // Error 8 occurs here
     check(nvgraphAllocateVertexData(handle, graph, vertex_numsets, vertex_dimT));
     check(nvgraphAllocateEdgeData  (handle, graph, edge_numsets, &edge_dimT));
     check(nvgraphSetEdgeData(handle, graph, (void*)weights_h, 0));

     // Solve
     int source_vert = 0;
     check(nvgraphSssp(handle, graph, 0,  &source_vert, 0));

     // Get and print result
     check(nvgraphGetVertexData(handle, graph, (void*)sssp_1_h, 0));

     // Clean
     free(sssp_1_h);
     free(vertex_dim);
     free(vertex_dimT);
     free(COO_input);
     check(nvgraphDestroyGraphDescr(handle, graph));
     check(nvgraphDestroy(handle));

     return 0;
  }

我尝试过的事情:

为主机上的目标和源边缘分配内存,并将其复制到设备。但是,由于nvGRAPH提供的代码示例中并未做到这一点,所以我认为这不是必不可少的。不过,我仍然有一个ERROR 8。 只是要澄清一下:按nvGRAPH的代码示例运行代码可以正常工作。

1 个答案:

答案 0 :(得分:2)

错误似乎很明显。不支持COO。请改用CSR或CSC。 nvGraph documentation

中的多个地方都提到了这一点

例如:

  

可以使用nvgraphCreateGraphDescr()使用CSR(压缩的稀疏行)格式和CSC(压缩的列存储)格式上传图形。

并且:

  

NVGRAPH_COO_32带有源或目标专业的坐标列表格式。未在任何算法中使用,仅用于数据存储。

并且:

  

topologyData指向{nvgraphCSRTopology32I_t,nvgraphCSCTopology32I_t}类型之一的填充结构的指针。通过参数TType定义要使用的特定类型。