如何使用pycuda处理带字符串的结构化numpy数组?

2024-05-08 23:42:47 发布

您现在位置:Python中文网/ 问答频道 /正文

首先,我从csv文件中获得了结构化数组:

columns = []
columns.append(('DAY', 'uint8'))
columns.append(('MONTH', 'uint8'))
columns.append(('YEAR', 'uint16'))
columns.append(('CLIENT_NAME', 'U13')) #ATTENTION!!!
columns.append(('QUANTITY', 'uint32'))
dtype = np.dtype(columns)  

data_from_file = np.fromregex(file='/home/semen/deals.csv', regexp=regular_expression, dtype=dtype)

其次,我尝试使用PyCuda执行此数据:

mod = SourceModule("""
    #define uint unsigned int
    #define uchar unsigned char
    #define ushort unsigned short int
    
    struct FileData{
        uchar DAY;
        uchar MONTH;
        ushort YEAR;
        std::string CLIENT_NAME; #ATTENTION!!!
        uint QUANTITY;
    };
    
    __global__ void crate_date_and_time_struct(const uint N, FileData* initial_data, uint* dates){
        const int idx = threadIdx.x + blockIdx.x * blockDim.x;
        if(idx >= N) return;
        
        FileData record = initial_data[idx];
        dates[idx] = 10000 * record.YEAR + 100 * record.MONTH + record.DAY;
    }
    """)

但我得到了一个错误:

pycuda.driver.CompileError: nvcc compilation of /tmp/tmpx6ywxfnh/kernel.cu failed [command: nvcc --cubin -arch sm_61 -I/home/semen/.local/lib/python3.8/site-packages/pycuda/cuda kernel.cu] [stderr: kernel.cu(26): error: namespace "std" has no member "string"

1 error detected in the compilation of "kernel.cu". ]

如何在Pycuda中使用字符串