Skip to content

Commit

Permalink
Windows build fixes: struct vs class, unused arg/var, avoid VLA, Dele…
Browse files Browse the repository at this point in the history
…ter arg

PiperOrigin-RevId: 724285438
  • Loading branch information
jan-wassenberg authored and copybara-github committed Feb 7, 2025
1 parent 82ca526 commit 9e5947f
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion compression/fields.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace gcpp {
// fields: not required for the intended use case of `ModelConfig`.
// - support any other languages than C++ and Python (for the exporter).

class IFields; // breaks circular dependency
struct IFields; // breaks circular dependency

// Visitors are internal-only, but their base class is visible to user code
// because their `IFields::VisitFields` calls `visitor.operator()`.
Expand Down
1 change: 0 additions & 1 deletion compression/nuq-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ class NuqClustering {
using VF = hn::Vec<decltype(df)>;
using MF = hn::Mask<decltype(df)>;
using VI = hn::Vec<decltype(di)>;
const VI k1 = hn::Set(di, 1);
const size_t N = hn::Lanes(df);
HWY_DASSERT(kGroupSize % N == 0);

Expand Down
1 change: 1 addition & 0 deletions gemma/configs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ static LayerConfig LayerConfigGriffin2B(size_t model_dim) {
config.kv_heads = 1;
config.qkv_dim = 256;
config.conv1d_width = 4;
HWY_DASSERT(config.conv1d_width <= kMaxConv1DWidth);
config.ff_biases = true;
config.softmax_attn_output_biases = true;
config.optimized_gating = false;
Expand Down
1 change: 1 addition & 0 deletions gemma/configs.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ namespace gcpp {
static constexpr size_t kSeqLen = GEMMA_MAX_SEQLEN;
static constexpr size_t kTopK = GEMMA_TOPK;
static constexpr size_t kVocabSize = 256000;
static constexpr size_t kMaxConv1DWidth = 4;

using EmbedderInputT = BF16;

Expand Down
3 changes: 2 additions & 1 deletion gemma/gemma-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ HWY_NOINLINE void GriffinRecurrent(size_t batch_start, size_t num_tokens,
const size_t layer_offset = layer * model_dim * (conv_1d_width - 1);

// cache[i] = input at time t-i.
float* HWY_RESTRICT cache[HWY_MAX(conv_1d_width, 1)];
float* HWY_RESTRICT cache[kMaxConv1DWidth];
cache[0] = x;
for (size_t i = 1; i < conv_1d_width; i++) {
cache[i] =
Expand Down Expand Up @@ -887,6 +887,7 @@ HWY_NOINLINE void VitTransformerLayer(size_t num_tokens, size_t layer,
const size_t model_dim = activations.weights_config.model_dim;
auto type = layer_weights->layer_config.type;
HWY_DASSERT(type == LayerAttentionType::kVit);
(void)type;

auto& x = activations.x;
HWY_DASSERT(x.BatchSize() == num_tokens);
Expand Down
6 changes: 3 additions & 3 deletions gemma/weights.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,15 @@ struct LayerWeightsPtrs {
} \
if (tensors[0]->Ptr() != nullptr || fet != ForEachType::kIgnoreNulls) { \
func(ptrs[0]->member.CacheName(layer_idx, sep, sep_index).c_str(), \
hwy::Span<MatPtr*>(tensors, ptrs.size())); \
hwy::Span<MatPtr*>(tensors.data(), ptrs.size())); \
} \
}

template <class Func>
static void ForEachTensor(const std::vector<LayerWeightsPtrs<Weight>*>& ptrs,
int layer_idx, ForEachType fet, Func func,
char sep = ' ', int sep_index = -1) {
MatPtr* tensors[ptrs.size()];
std::vector<MatPtr*> tensors(ptrs.size(), nullptr);
auto type = ptrs[0]->layer_config.type;
if (type == LayerAttentionType::kVit) {
// MHA.
Expand Down Expand Up @@ -449,7 +449,7 @@ struct ModelWeightsPtrs {
ForEachType fet, Func func) {
std::vector<LayerWeightsPtrs<Weight>*> layers(ptrs.size());
std::vector<LayerWeightsPtrs<Weight>*> vit_layers(ptrs.size());
MatPtr* tensors[ptrs.size()];
std::vector<MatPtr*> tensors(ptrs.size(), nullptr);
// Variables used by GEMMA_CALL_FUNC.
int layer_idx = -1;
char sep = ' ';
Expand Down
2 changes: 1 addition & 1 deletion util/allocator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ Allocator::PtrAndDeleter Allocator::AllocBytes(size_t bytes) {
};
return PtrAndDeleter{p, Deleter(call_munmap, bytes)};
#elif HWY_OS_WIN
const auto call_free = [](void* ptr, void*) { _aligned_free(ptr); };
const auto call_free = [](void* ptr, size_t) { _aligned_free(ptr); };
const size_t alignment = HWY_MAX(vector_bytes_, line_bytes_);
return PtrAndDeleter{_aligned_malloc(bytes, alignment),
Deleter(call_free, bytes)};
Expand Down

0 comments on commit 9e5947f

Please sign in to comment.