Esempio n. 1
0
static bool readDist(int fd, const char* filename, DistMat& M, uint64_t* bytes)
{
    struct layer_header header;
    ssize_t read_rc = read(fd, &header, sizeof(header));
    if (read_rc != sizeof(header)) {
        // error!
    }
    *bytes += read_rc;

    // check that header values match up

    Int height = header.height;
    Int width  = header.width;
    M.Resize(height, width);

    if(M.ColStride() == 1 && M.RowStride() == 1) {
        if(M.Height() == M.LDim()) {
            void* buf = (void*) M.Buffer();
            size_t bufsize = height * width * sizeof(DataType);
            read_rc = read(fd, buf, bufsize);
            if (read_rc != bufsize) {
                // error!
            }
            *bytes += read_rc;
        } else {
            for(Int j = 0; j < width; ++j) {
                void* buf = (void*) M.Buffer(0, j);
                size_t bufsize = height * sizeof(DataType);
                read_rc = read(fd, buf, bufsize);
                if (read_rc != bufsize) {
                    // error!
                }
                *bytes += read_rc;
            }
        }
    } else {
        const Int localHeight = M.LocalHeight();
        const Int localWidth = M.LocalWidth();
        const Int lDim = M.LDim();
        if(localHeight == lDim) {
            void* buf = (void*) M.Buffer();
            size_t bufsize = localHeight * localWidth * sizeof(DataType);
            read_rc = read(fd, buf, bufsize);
            if (read_rc != bufsize) {
                // error!
            }
            *bytes += read_rc;
        } else {
            for(Int jLoc = 0; jLoc < localWidth; ++jLoc) {
                void* buf = (void*) M.Buffer(0, jLoc);
                size_t bufsize = localHeight * sizeof(DataType);
                read_rc = read(fd, buf, bufsize);
                if (read_rc != bufsize) {
                    // error!
                }
                *bytes += read_rc;
            }
        }
    }
    return true;
}
Esempio n. 2
0
/** Create a new matrix. */
void create_mat(DistMat& mat, DataType def = 1.0) {
  mat.Resize(LBANN_COMM_TEST_NROWS, LBANN_COMM_TEST_NCOLS);
  El::Fill(mat, def);
}