运行时
常量内存使用错误hipErrorInvalidSymbol
2022-03-23 20:53:23
49

设备常量声明

__constant__ int xlength_d, num_cells_d;

在以下函数调用:

extern "C" void DoIteration(float *collide_field, float *stream_field, int *flag_field, float tau,
                float *wall_velocity, int xlength, float **collide_field_dd, float **stream_field_dd,
                int **flag_field_d, float *mlups_sum){
        int num_cells = pow(xlength+2, D_LBM);
        clock_t mlups_time;

        /* initialize constant data */
        // 从以下代码开始报错
        hipErrorCheck(hipMemcpyToSymbol(HIP_SYMBOL(xlength_d), &xlength, sizeof(int), 0, hipMemcpyHostToDevice));
        hipErrorCheck(hipMemcpyToSymbol(HIP_SYMBOL(num_cells_d), &num_cells, sizeof(int), 0, hipMemcpyHostToDevice));
        hipErrorCheck(hipMemcpyToSymbol(HIP_SYMBOL(tau_d), &tau, sizeof(float), 0, hipMemcpyHostToDevice));
        hipErrorCheck(hipMemcpyToSymbol(HIP_SYMBOL(wall_velocity_d), wall_velocity, D_LBM*sizeof(float), 0, hipMemcpyHostToDevice));

        hipErrorCheck(hipMemcpyToSymbol(HIP_SYMBOL(collide_field_d), collide_field_dd, sizeof(*collide_field_dd), 0, hipMemcpyHostToDevice));
        hipErrorCheck(hipMemcpyToSymbol(HIP_SYMBOL(stream_field_d), stream_field_dd, sizeof(*stream_field_dd), 0, hipMemcpyHostToDevice));

其中hipErrorCheck如下:

#define hipErrorCheck(ans){ hipAssert((ans), __FILE__, __LINE__); }
inline void hipAssert(hipError_t code, char const *file, int line, bool abort=true){
        if (code != hipSuccess){
                fprintf(stderr,"HIP Assert: %s %s %d\n", hipGetErrorString(code), file, line);
                if (abort) exit(code);
        }
}

在自己写的小算例中这种方式是可以正常赋值的,但此处从第一个常量复制语句开始总是会提示错误:hipErrorInvalidSymbol,请问是为什么?

全部评论(1)
只看楼主
L
louis
1楼

constant修饰目前并不支持,请使用device

2022/3/24
没有更多内容了
--
楼主
Level.4
0 帖子
楼主热帖
暂无数据