Skip to content

Commit

Permalink
Remove some incorrectly marked const qualifiers
Browse files Browse the repository at this point in the history
No functional change
  • Loading branch information
xu-shawn authored and PikaCat-OuO committed Jan 6, 2025
1 parent 771c82e commit b9aa24c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/nnue/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ bool read_parameters(std::istream& stream, T& reference) {

// Write evaluation function parameters
template<typename T>
bool write_parameters(std::ostream& stream, const T& reference) {
bool write_parameters(std::ostream& stream, T& reference) {

write_little_endian<std::uint32_t>(stream, T::get_hash_value());
return reference.write_parameters(stream);
Expand Down
16 changes: 7 additions & 9 deletions src/nnue/nnue_feature_transformer.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,39 +280,37 @@ class FeatureTransformer {
#endif
}

void permute_weights([[maybe_unused]] void (*order_fn)(uint64_t*)) const {
void permute_weights([[maybe_unused]] void (*order_fn)(uint64_t*)) {
#if defined(USE_AVX2)
#if defined(USE_AVX512) || defined(USE_AVX512F)
constexpr IndexType di = 16;
#else
constexpr IndexType di = 8;
#endif
uint64_t* b = reinterpret_cast<uint64_t*>(const_cast<BiasType*>(&biases[0]));
uint64_t* b = reinterpret_cast<uint64_t*>(&biases[0]);
for (IndexType i = 0; i < HalfDimensions * sizeof(BiasType) / sizeof(uint64_t); i += di)
order_fn(&b[i]);

for (IndexType j = 0; j < InputDimensions; ++j)
{
uint64_t* w =
reinterpret_cast<uint64_t*>(const_cast<WeightType*>(&weights[j * HalfDimensions]));
uint64_t* w = reinterpret_cast<uint64_t*>(&weights[j * HalfDimensions]);
for (IndexType i = 0; i < HalfDimensions * sizeof(WeightType) / sizeof(uint64_t);
i += di)
order_fn(&w[i]);
}
#endif
}

inline void scale_weights(bool read) const {
inline void scale_weights(bool read) {
for (IndexType j = 0; j < InputDimensions; ++j)
{
WeightType* w = const_cast<WeightType*>(&weights[j * HalfDimensions]);
WeightType* w = &weights[j * HalfDimensions];
for (IndexType i = 0; i < HalfDimensions; ++i)
w[i] = read ? w[i] * 2 : w[i] / 2;
}

BiasType* b = const_cast<BiasType*>(biases);
for (IndexType i = 0; i < HalfDimensions; ++i)
b[i] = read ? b[i] * 2 : b[i] / 2;
biases[i] = read ? biases[i] * 2 : biases[i] / 2;
}

// Read network parameters
Expand All @@ -328,7 +326,7 @@ class FeatureTransformer {
}

// Write network parameters
bool write_parameters(std::ostream& stream) const {
bool write_parameters(std::ostream& stream) {

permute_weights(order_packs);
scale_weights(false);
Expand Down

0 comments on commit b9aa24c

Please sign in to comment.