Beispiel #1
0
def common_uspmv_dev(rows,cols,datas,m_sizes,k_sizes,nnz_sizes, num_runs,A_handles,B_handles,C_handles):
  ddrWidth = int(xclbin_opts["GEMX_ddrWidth"])
  stages = int(xclbin_opts["GEMX_uspmvStages"])
  min_k = ddrWidth
  min_m = ddrWidth * int(xclbin_opts["GEMX_uspmvInterleaves"]) 
  for i in range(len(m_sizes)):
     m_sizes[i] = test.get_padded_size (m_sizes[i], min_m)
     k_sizes[i] = test.get_padded_size (k_sizes[i], min_m)
  print ("size:",m_sizes,k_sizes,"nnz:",nnz_sizes)    
  B = gemx.addDevBuf(B_handles[0],num_runs, k_sizes[0],np.float32)
  B_tmp = np.zeros((num_runs, k_sizes[0]), dtype=np.float32)
  test.fillMod(9, num_runs, k_sizes[0],B_tmp)
  B[:]=B_tmp
  C_list=[]
  for i in range(len(m_sizes)):
    C = gemx.addDevBuf(C_handles[i],num_runs, m_sizes[-1],np.float32)
    C.fill(0)
    C_list.append(C)
    A = gemx.addUSpDevBuf(np.array(rows[i]).astype(np.uint16),
                        np.array(cols[i]).astype(np.uint16),
                        np.array(datas[i]),
                        A_handles[i],
                        np.array(m_sizes[i],dtype=np.int32),
                        np.array(k_sizes[i],dtype=np.int32),
                        np.array(nnz_sizes[i],dtype=np.int32),
                        np.array(1,dtype=np.float32),xclbin_opts)
    gemx.sendDevBuf(A_handles[i])
    gemx.sendDevBuf(B_handles[i])
    gemx.sendDevBuf(C_handles[i])
    gemx.addUSPMVDevOp(A_handles[i],B_handles[i],C_handles[i],num_runs)

  gemx.executeDev()
  gemx.getDevBuf(C_handles[-1])
  test.multiply_and_cmp_uspmv(rows,cols,datas,m_sizes,k_sizes,B,C_list[-1])
Beispiel #2
0
def common_spmv(row, col, data, m, k, nnz, vector_range):
    if xclbin_opts["GEMX_dataType"] == "float":
        data_type = np.float32
    elif xclbin_opts["GEMX_dataType"] == "int32_t":
        data_type = np.int32
    else:
        raise TypeError("type", xclbin_opts["GEMX_dataType"], "not supported")
    ddrWidth = int(xclbin_opts["GEMX_ddrWidth"])
    min_k = ddrWidth
    spmvWidth = int(xclbin_opts["GEMX_spmvWidth"])
    min_m = spmvWidth * int(xclbin_opts["GEMX_spmvMacGroups"])
    m = get_padded_size(m, min_m)
    k = get_padded_size(k, min_k)
    print("size:", m, k, "nnz:", nnz)
    if data_type == np.int32:
        B = np.random.randint(low=-vector_range,
                              high=vector_range,
                              size=(k, 1),
                              dtype=np.int32)
    else:
        B = np.zeros((k, 1), dtype=np.float32)
        test.fillMod(B, k, vector_range)
    C = np.zeros((m, 1), dtype=data_type)
    A = gemx.sendSpMat(row, col, data, m, k, nnz, xclbin_opts)
    gemx.sendMat(B)
    gemx.sendMat(C)
    gemx.addSPMVOp(A, B, C, nnz, xclbin_opts)
    gemx.execute()
    gemx.clearInstrBuf()
    gemx.getMat(C)
    test.multiply_and_cmp_spmv(row, col, data, m, k, nnz, B, C)
Beispiel #3
0
def common_spmv(row, col, data, m, k, nnz, vector_range, dtype):
    if dtype == np.int32:
        B = np.random.randint(low=-vector_range,
                              high=vector_range,
                              size=(k, 1),
                              dtype=np.int32)
        C = np.zeros((m, 1), dtype=np.int32)
        A = gemx.sendSpMat(row, col, data, nnz, dtype)
        gemx.sendMat(B)
        gemx.sendMat(C)
        gemx.addSPMVOp(A, B, C, nnz)
        gemx.execute()
        gemx.getMat(C)
        test.multiply_and_cmp_spmv(row, col, data, m, k, nnz, B, C)
    elif dtype == np.float32:
        B = np.zeros((k, 1), dtype=np.float32)
        test.fillMod(B, k, vector_range)
        C = np.zeros((m, 1), dtype=np.float32)
        A = gemx.sendSpMat(row, col, data, nnz, dtype)
        gemx.sendMat(B)
        gemx.sendMat(C)
        gemx.addSPMVOp(A, B, C, nnz)
        gemx.execute()
        gemx.getMat(C)
        test.multiply_and_cmp_spmv(row, col, data, m, k, nnz, B, C)
    else:
        raise TypeError("type", dtype, "not supported")
Beispiel #4
0
def common_uspmv(rows,cols,datas,m_sizes,k_sizes,nnz_sizes, num_runs,vector_range):
  ddrWidth = int(xclbin_opts["GEMX_ddrWidth"])
  min_k = ddrWidth
  min_m = ddrWidth * int(xclbin_opts["GEMX_uspmvInterleaves"]) 
  for i in range(len(m_sizes)):
     m_sizes[i] = test.get_padded_size (m_sizes[i], min_m)
     k_sizes[i] = test.get_padded_size (k_sizes[i], min_m)
  print ("size:",m_sizes,k_sizes,"nnz:",nnz_sizes) 
  B = np.zeros((num_runs, k_sizes[i]), dtype=np.float32)
  test.fillMod(9, num_runs, k_sizes[i],B)
  B = B.astype(np.float32)
  C_list=[B]
  for i in range(len(m_sizes)):
    C = np.zeros ((num_runs, m_sizes[i]), dtype=np.float32)
    C_list.append(C)
    A = gemx.sendUSpMat(np.array(rows[i]).astype(np.uint16),
                        np.array(cols[i]).astype(np.uint16),
                        np.array(datas[i]),
                        np.array(m_sizes[i],dtype=np.int32),
                        np.array(k_sizes[i],dtype=np.int32),
                        np.array(nnz_sizes[i],dtype=np.int32),
                        np.array(1,dtype=np.float32),
                        xclbin_opts)  
    gemx.sendMat(C_list[i])
    gemx.sendMat(C_list[i+1])
    gemx.addUSPMVOp(A,C_list[i],C_list[i+1],num_runs)
  gemx.execute()
  gemx.clearInstrBuf()
  gemx.getMat(C_list[-1])
  test.multiply_and_cmp_uspmv(rows,cols,datas,m_sizes,k_sizes,B,C_list[-1])
Beispiel #5
0
def common_spmv(row, col, data, m, k, nnz, vector_range):
    ddrWidth = int(xclbin_opts["GEMX_ddrWidth"])
    if xclbin_opts["GEMX_dataType"] == "float":
        dtype = np.float32
    elif xclbin_opts["GEMX_dataType"] == "int32_t":
        dtype = np.int32
    else:
        raise TypeError("type", xclbin_opts["GEMX_dataType"], "not supported")
    if dtype == np.int32:
        B = np.random.randint(low=-vector_range,
                              high=vector_range,
                              size=(k, 1),
                              dtype=np.int32)
        C = np.zeros((m, 1), dtype=np.int32)
        A = gemx.sendSpMat(row, col, data, ddrWidth, dtype)
        gemx.sendMat(B)
        gemx.sendMat(C)
        gemx.addSPMVOp(A, B, C, nnz)
        gemx.execute()
        gemx.clearInstrBuf()
        gemx.getMat(C)
        test.multiply_and_cmp_spmv(row, col, data, m, k, nnz, B, C)
    elif dtype == np.float32:
        B = np.zeros((k, 1), dtype=np.float32)
        test.fillMod(B, k, vector_range)
        C = np.zeros((m, 1), dtype=np.float32)
        A = gemx.sendSpMat(row, col, data, ddrWidth, dtype)
        gemx.sendMat(B)
        gemx.sendMat(C)
        gemx.addSPMVOp(A, B, C, nnz)
        gemx.execute()
        gemx.clearInstrBuf()
        gemx.getMat(C)
        test.multiply_and_cmp_spmv(row, col, data, m, k, nnz, B, C)
Beispiel #6
0
def common_spmv(row, col, data, m, k, nnz, vector_range):
    if xclbin_opts["GEMX_dataType"] == "float":
        data_type = np.float32
    elif xclbin_opts["GEMX_dataType"] == "int32_t":
        data_type = np.int32
    else:
        raise TypeError("type", xclbin_opts["GEMX_dataType"], "not supported")
    ddrWidth = int(xclbin_opts["GEMX_ddrWidth"])
    min_k = ddrWidth
    if xclbin_opts["GEMX_useURAM"] == "1":
        min_nnz = ddrWidth
        min_m = ddrWidth * int(xclbin_opts["GEMX_spmvUramGroups"])
    else:
        spmvWidth = int(xclbin_opts["GEMX_spmvWidth"])
        min_nnz = spmvWidth
        min_m = spmvWidth * int(xclbin_opts["GEMX_spmvMacGroups"])
    while nnz % min_nnz != 0:
        # pad with 0s and adjust dimensions when necessary
        row = (np.append(row, 0)).astype(np.int32)
        col = (np.append(col, 0)).astype(np.int32)
        data = (np.append(data, 0)).astype(np.float32)
        nnz = nnz + 1
    m = get_padded_size(m, min_m)
    k = get_padded_size(k, min_k)
    print("size:", m, k, "nnz:", nnz)
    if data_type == np.int32:
        B = np.random.randint(low=-vector_range,
                              high=vector_range,
                              size=(k, 1),
                              dtype=np.int32)
    else:
        B = np.zeros((k, 1), dtype=np.float32)
        test.fillMod(B, k, vector_range)
    C = np.zeros((m, 1), dtype=data_type)
    A = xfmlp.sendSpMat(row, col, data, m, k, nnz, xclbin_opts, data_type)
    xfmlp.sendMat(B)
    xfmlp.sendMat(C)
    xfmlp.addSPMVOp(A, B, C, nnz, xclbin_opts)
    xfmlp.execute()
    xfmlp.clearInstrBuf()
    xfmlp.getMat(C)
    test.multiply_and_cmp_spmv(row, col, data, m, k, nnz, B, C)