nvGRAPH SSSP 示例代码在使用 COO 作为输入时给出错误 8
nvGRAPH SSSP example code gives error 8 when using COO as input
我复制了 nvGRAPH 提供的 example code 来计算 SSSP,并修改了代码,以便我使用 COO(而不是 CSC)作为输入图形格式。
在调用 nvgraphSetGraphStructure
的那一行,我得到一个 ERROR 8
,这是一个 type not supported by this function 错误。错误描述进一步说,这通常是由将无效的图形描述符传递给函数引起的。但是,我认为这里不是这种情况。
代码示例:
#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 的代码示例中的代码运行良好。
错误似乎很明显。不支持 COO。请改用 CSR 或 CSC。 nvGraph documentation
中多处提到了这一点
例如:
Graphs may be uploaded using the CSR (compressed sparse row) format and the CSC(compressed column storage) format, using nvgraphCreateGraphDescr().
并且:
NVGRAPH_COO_32 Coordinate list format with source or destination major. Not used in any algorithm and provided for data storage only.
并且:
topologyData Pointer to a filled structure of one of the types {nvgraphCSRTopology32I_t, nvgraphCSCTopology32I_t}. The particular type to be used is defined by parameter TType.
我复制了 nvGRAPH 提供的 example code 来计算 SSSP,并修改了代码,以便我使用 COO(而不是 CSC)作为输入图形格式。
在调用 nvgraphSetGraphStructure
的那一行,我得到一个 ERROR 8
,这是一个 type not supported by this function 错误。错误描述进一步说,这通常是由将无效的图形描述符传递给函数引起的。但是,我认为这里不是这种情况。
代码示例:
#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 的代码示例中的代码运行良好。
错误似乎很明显。不支持 COO。请改用 CSR 或 CSC。 nvGraph documentation
中多处提到了这一点例如:
Graphs may be uploaded using the CSR (compressed sparse row) format and the CSC(compressed column storage) format, using nvgraphCreateGraphDescr().
并且:
NVGRAPH_COO_32 Coordinate list format with source or destination major. Not used in any algorithm and provided for data storage only.
并且:
topologyData Pointer to a filled structure of one of the types {nvgraphCSRTopology32I_t, nvgraphCSCTopology32I_t}. The particular type to be used is defined by parameter TType.