Fix name shadowing and C4146

This commit is contained in:
yamashi 2023-05-19 17:35:22 +02:00
parent 5ea4339273
commit a4d7e000ff
2 changed files with 24 additions and 23 deletions

View file

@ -101,12 +101,12 @@ struct llama_file {
LLAMA_ASSERT(ret == 0); // same LLAMA_ASSERT(ret == 0); // same
} }
void read_raw(void * ptr, size_t size) { void read_raw(void * ptr, size_t len) {
if (size == 0) { if (len == 0) {
return; return;
} }
errno = 0; errno = 0;
std::size_t ret = std::fread(ptr, size, 1, fp); std::size_t ret = std::fread(ptr, len, 1, fp);
if (ferror(fp)) { if (ferror(fp)) {
throw std::runtime_error(format("read error: %s", strerror(errno))); throw std::runtime_error(format("read error: %s", strerror(errno)));
} }
@ -127,12 +127,12 @@ struct llama_file {
return std::string(chars.data(), len); return std::string(chars.data(), len);
} }
void write_raw(const void * ptr, size_t size) { void write_raw(const void * ptr, size_t len) {
if (size == 0) { if (len == 0) {
return; return;
} }
errno = 0; errno = 0;
size_t ret = std::fwrite(ptr, size, 1, fp); size_t ret = std::fwrite(ptr, len, 1, fp);
if (ret != 1) { if (ret != 1) {
throw std::runtime_error(format("write error: %s", strerror(errno))); throw std::runtime_error(format("write error: %s", strerror(errno)));
} }
@ -267,9 +267,9 @@ struct llama_mlock {
} }
} }
void init(void * addr) { void init(void * ptr) {
LLAMA_ASSERT(this->addr == NULL && this->size == 0); LLAMA_ASSERT(addr == NULL && size == 0);
this->addr = addr; addr = ptr;
} }
void grow_to(size_t target_size) { void grow_to(size_t target_size) {
@ -340,14 +340,14 @@ struct llama_mlock {
return (size_t) si.dwPageSize; return (size_t) si.dwPageSize;
} }
bool raw_lock(void * addr, size_t size) { bool raw_lock(void * ptr, size_t len) {
for (int tries = 1; ; tries++) { for (int tries = 1; ; tries++) {
if (VirtualLock(addr, size)) { if (VirtualLock(ptr, len)) {
return true; return true;
} }
if (tries == 2) { if (tries == 2) {
fprintf(stderr, "warning: failed to VirtualLock %zu-byte buffer (after previously locking %zu bytes): %s\n", fprintf(stderr, "warning: failed to VirtualLock %zu-byte buffer (after previously locking %zu bytes): %s\n",
size, this->size, llama_format_win_err(GetLastError()).c_str()); len, size, llama_format_win_err(GetLastError()).c_str());
return false; return false;
} }
@ -363,7 +363,7 @@ struct llama_mlock {
// is equal to the number of pages in its minimum working set minus // is equal to the number of pages in its minimum working set minus
// a small overhead." // a small overhead."
// Hopefully a megabyte is enough overhead: // Hopefully a megabyte is enough overhead:
size_t increment = size + 1048576; size_t increment = len + 1048576;
// The minimum must be <= the maximum, so we need to increase both: // The minimum must be <= the maximum, so we need to increase both:
min_ws_size += increment; min_ws_size += increment;
max_ws_size += increment; max_ws_size += increment;
@ -375,8 +375,8 @@ struct llama_mlock {
} }
} }
void raw_unlock(void * addr, size_t size) { void raw_unlock(void * ptr, size_t len) {
if (!VirtualUnlock(addr, size)) { if (!VirtualUnlock(ptr, len)) {
fprintf(stderr, "warning: failed to VirtualUnlock buffer: %s\n", fprintf(stderr, "warning: failed to VirtualUnlock buffer: %s\n",
llama_format_win_err(GetLastError()).c_str()); llama_format_win_err(GetLastError()).c_str());
} }
@ -388,12 +388,12 @@ struct llama_mlock {
return (size_t) 65536; return (size_t) 65536;
} }
bool raw_lock(const void * addr, size_t size) { bool raw_lock(const void * addr, size_t len) {
fprintf(stderr, "warning: mlock not supported on this system\n"); fprintf(stderr, "warning: mlock not supported on this system\n");
return false; return false;
} }
void raw_unlock(const void * addr, size_t size) {} void raw_unlock(const void * addr, size_t len) {}
#endif #endif
}; };
@ -404,10 +404,10 @@ struct llama_buffer {
llama_buffer() = default; llama_buffer() = default;
void resize(size_t size) { void resize(size_t len) {
delete[] addr; delete[] addr;
addr = new uint8_t[size]; addr = new uint8_t[len];
this->size = size; size = len;
} }
~llama_buffer() { ~llama_buffer() {

View file

@ -45,6 +45,7 @@ enum e_model {
MODEL_65B, MODEL_65B,
}; };
static const size_t MB = 1024*1024; static const size_t MB = 1024*1024;
// computed for n_ctx == 2048 // computed for n_ctx == 2048
@ -110,7 +111,7 @@ struct llama_hparams {
enum llama_ftype ftype = LLAMA_FTYPE_MOSTLY_F16; enum llama_ftype ftype = LLAMA_FTYPE_MOSTLY_F16;
bool operator!=(const llama_hparams & other) const { bool operator!=(const llama_hparams & other) const {
return memcmp(this, &other, sizeof(llama_hparams)); return static_cast<bool>(memcmp(this, &other, sizeof(llama_hparams)));
} }
}; };
@ -499,7 +500,7 @@ struct llama_file_loader {
if (file_version >= LLAMA_FILE_VERSION_GGJT_V1) { if (file_version >= LLAMA_FILE_VERSION_GGJT_V1) {
// skip to the next multiple of 32 bytes // skip to the next multiple of 32 bytes
file.seek(-file.tell() & 31, SEEK_CUR); file.seek(-static_cast<ptrdiff_t>(file.tell()) & 31, SEEK_CUR);
} }
shard.file_idx = file_idx; shard.file_idx = file_idx;
shard.file_off = file.tell(); shard.file_off = file.tell();
@ -574,7 +575,7 @@ struct llama_file_saver {
file.write_u32(new_type); file.write_u32(new_type);
file.write_raw(tensor.ne.data(), sizeof(tensor.ne[0]) * tensor.ne.size()); file.write_raw(tensor.ne.data(), sizeof(tensor.ne[0]) * tensor.ne.size());
file.write_raw(tensor.name.data(), tensor.name.size()); file.write_raw(tensor.name.data(), tensor.name.size());
file.seek(-file.tell() & 31, SEEK_CUR); file.seek(-static_cast<ptrdiff_t >(file.tell()) & 31, SEEK_CUR);
LLAMA_ASSERT(new_size == llama_calc_tensor_size(tensor.ne, new_type)); LLAMA_ASSERT(new_size == llama_calc_tensor_size(tensor.ne, new_type));
file.write_raw(new_data, new_size); file.write_raw(new_data, new_size);
} }