Skip to content

Commit

Permalink
build : fix compilation errors and warnigns when building with MSVC (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
iboB authored Jun 24, 2023
1 parent 72e59ee commit c1bb712
Show file tree
Hide file tree
Showing 20 changed files with 125 additions and 36 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
build/
build-debug/
build-*/
out/

compile_commands.json
CMakeSettings.json
.vs/
.vscode/

.exrc
.cache
Expand Down
6 changes: 5 additions & 1 deletion examples/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
#define M_PI 3.14159265358979323846
#endif

#if defined(_MSC_VER)
#pragma warning(disable: 4244 4267) // possible loss of data
#endif

bool gpt_params_parse(int argc, char ** argv, gpt_params & params) {
for (int i = 1; i < argc; i++) {
std::string arg = argv[i];
Expand Down Expand Up @@ -366,7 +370,7 @@ void test_gpt_tokenizer(gpt_vocab & vocab, const std::string & fpath_test){
}
}

fprintf(stderr, "%s : %lu tests failed out of %lu tests.\n", __func__, n_fails, tests.size());
fprintf(stderr, "%s : %zu tests failed out of %zu tests.\n", __func__, n_fails, tests.size());
}

bool gpt_vocab_init(const std::string & fname, gpt_vocab & vocab) {
Expand Down
4 changes: 4 additions & 0 deletions examples/dolly-v2/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
#include <string>
#include <vector>

#if defined(_MSC_VER)
#pragma warning(disable: 4244 4267) // possible loss of data
#endif

// default hparams (Dolly-V2 3B)
struct dollyv2_hparams {
int32_t n_vocab = 50254; // tokenizer.vocab_size
Expand Down
4 changes: 4 additions & 0 deletions examples/gpt-2/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
#include <string>
#include <vector>

#if defined(_MSC_VER)
#pragma warning(disable: 4244 4267) // possible loss of data
#endif

// default hparams (GPT-2 117M)
struct gpt2_hparams {
int32_t n_vocab = 50257;
Expand Down
5 changes: 5 additions & 0 deletions examples/gpt-j/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
#include <string>
#include <vector>

#if defined(_MSC_VER)
#pragma warning(disable: 4244 4267) // possible loss of data
#endif


// default hparams (GPT-J 6B)
struct gptj_hparams {
int32_t n_vocab = 50400;
Expand Down
4 changes: 4 additions & 0 deletions examples/gpt-neox/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
#include <string>
#include <vector>

#if defined(_MSC_VER)
#pragma warning(disable: 4244 4267) // possible loss of data
#endif

// default hparams (StableLM 3B)
struct gpt_neox_hparams {
int32_t n_vocab = 50257;
Expand Down
4 changes: 4 additions & 0 deletions examples/mnist/main-cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
#include <fstream>
#include <vector>

#if defined(_MSC_VER)
#pragma warning(disable: 4244 4267) // possible loss of data
#endif

// evaluate the MNIST compute graph
//
// - fname_cgraph: path to the compute graph
Expand Down
4 changes: 4 additions & 0 deletions examples/mnist/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
#include <vector>
#include <algorithm>

#if defined(_MSC_VER)
#pragma warning(disable: 4244 4267) // possible loss of data
#endif

// default hparams
struct mnist_hparams {
int32_t n_input = 784;
Expand Down
6 changes: 5 additions & 1 deletion examples/mpt/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
#include <utility>
#include <vector>

#if defined(_MSC_VER)
#pragma warning(disable: 4244 4267) // possible loss of data
#endif

// no defaults for now
struct mpt_hparams {
int32_t d_model = 0;
Expand Down Expand Up @@ -932,7 +936,7 @@ int main(int argc, char ** argv) {
printf("%s: number of tokens in prompt = %zu\n", __func__, embd_inp.size());

for (size_t i = 0; i < embd_inp.size(); i++) {
printf("%s: token[%lu] = %6d\n", __func__, i, embd_inp[i]);
printf("%s: token[%zu] = %6d\n", __func__, i, embd_inp[i]);
}
printf("\n");

Expand Down
23 changes: 20 additions & 3 deletions examples/replit/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,28 @@
#include <map>
#include <stdint.h>
#include <string>
#include <unistd.h>
#include <unordered_map>
#include <utility>
#include <vector>

#if defined(_WIN32)
#define NOMINMAX
#include <Windows.h>
bool is_stdin_terminal() {
auto in = GetStdHandle(STD_INPUT_HANDLE);
return GetFileType(in) == FILE_TYPE_CHAR;
}
#else
#include <unistd.h>
bool is_stdin_terminal() {
return isatty(STDIN_FILENO);
}
#endif

#if defined(_MSC_VER)
#pragma warning(disable: 4244 4267) // possible loss of data
#endif

using piece_t = std::pair<std::size_t, float>;
using piece_map_t = std::unordered_map<std::string, piece_t>;

Expand Down Expand Up @@ -645,7 +662,7 @@ int main(int argc, char ** argv) {

std::mt19937 rng(params.seed);
if (params.prompt.empty()) {
if (!isatty(STDIN_FILENO)) {
if (!is_stdin_terminal()) {
std::string line;
while (std::getline(std::cin, line)) {
params.prompt = params.prompt + "\n" + line;
Expand Down Expand Up @@ -685,7 +702,7 @@ int main(int argc, char ** argv) {
printf("%s: number of tokens in prompt = %zu\n", __func__, embd_inp.size());

for (int i = 0; i < embd_inp.size(); i++) {
printf("%s: token[%d] = %6lu\n", __func__, i, embd_inp[i]);
printf("%s: token[%d] = %6zu\n", __func__, i, embd_inp[i]);
// vocab.id_to_token.at(embd_inp[i]).c_str()
}
printf("\n");
Expand Down
4 changes: 4 additions & 0 deletions examples/starcoder/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
#include <string>
#include <vector>

#if defined(_MSC_VER)
#pragma warning(disable: 4244 4267) // possible loss of data
#endif

// default hparams (GPT-2 117M)
// https://huggingface.co/bigcode/gpt_bigcode-santacoder/blob/main/config.json
struct starcoder_hparams {
Expand Down
4 changes: 4 additions & 0 deletions examples/whisper/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
#include <vector>
#include <cstring>

#if defined(_MSC_VER)
#pragma warning(disable: 4244 4267) // possible loss of data
#endif

// Terminal color map. 10 colors grouped in ranges [0.0, 0.1, ..., 0.9]
// Lowest is red, middle is yellow, highest is green.
const std::vector<std::string> k_colors = {
Expand Down
4 changes: 4 additions & 0 deletions examples/whisper/whisper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
#include <regex>
#include <random>

#if defined(_MSC_VER)
#pragma warning(disable: 4244 4267) // possible loss of data
#endif

#if defined(GGML_BIG_ENDIAN)
#include <bit>

Expand Down
4 changes: 2 additions & 2 deletions src/ggml.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Defines CLOCK_MONOTONIC on Linux
#define _GNU_SOURCE
#define _GNU_SOURCE // Defines CLOCK_MONOTONIC on Linux
#define _CRT_SECURE_NO_DEPRECATE // Disables ridiculous "unsafe" warnigns on Windows

#include "ggml.h"

Expand Down
5 changes: 5 additions & 0 deletions tests/test-grad0.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
#define _CRT_SECURE_NO_DEPRECATE // Disables ridiculous "unsafe" warnigns on Windows
#include "ggml.h"

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

#if defined(_MSC_VER)
#pragma warning(disable: 4244 4267) // possible loss of data
#endif

#define MAX_NARGS 3

#undef MIN
Expand Down
5 changes: 5 additions & 0 deletions tests/test-mul-mat0.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define _CRT_SECURE_NO_DEPRECATE // Disables ridiculous "unsafe" warnigns on Windows
#include "ggml/ggml.h"

#include <math.h>
Expand All @@ -6,6 +7,10 @@
#include <assert.h>
#include <inttypes.h>

#if defined(_MSC_VER)
#pragma warning(disable: 4244 4267) // possible loss of data
#endif

#define MAX_NARGS 2

float frand() {
Expand Down
35 changes: 17 additions & 18 deletions tests/test-mul-mat2.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
#include <float.h>
#include <stdint.h>
#include <stdio.h>
#include <inttypes.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <math.h>

#include <sys/time.h>

#if defined(__ARM_NEON)
#include "arm_neon.h"
#elif defined(__AVX__) || defined(__AVX2__)
Expand All @@ -24,6 +22,12 @@
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#endif

#if defined(_MSC_VER)
#pragma warning(disable: 4244 4267) // possible loss of data
#include <intrin.h>
#define __builtin_popcountll __popcnt64
#endif

const int M = 1280;
const int N = 1536;
const int K = 1280;
Expand Down Expand Up @@ -54,12 +58,6 @@ float frand() {
return (float) rand() / (float) RAND_MAX;
}

uint64_t get_time_us() {
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec * 1000000 + tv.tv_usec;
}

#if defined(__AVX2__)
// horizontally reduce 8 32-bit integers
static inline uint32_t _mm256_hadd_epi32_gg(__m256i v) {
Expand Down Expand Up @@ -255,8 +253,8 @@ void mul_mat_gq_1(
s1[b + 1] = d1*(1 << b);
}

m0[0] = -1ULL;
m1[0] = -1ULL;
m0[0] = 0-1ULL;
m1[0] = 0-1ULL;

for (int s = 0; s < QK/gq_t_bits; ++s) {
for (int b = 0; b < QB; b++) {
Expand Down Expand Up @@ -2373,6 +2371,7 @@ void mul_mat_gq_6(

int main(int argc, const char ** argv) {
assert(sizeof(gq_quant_t)*8 == gq_t_bits);
ggml_time_init();

// needed to initialize f16 tables
{
Expand Down Expand Up @@ -2462,7 +2461,7 @@ int main(int argc, const char ** argv) {

// convert fp32 -> gq
{
const uint64_t t_start = get_time_us();
const int64_t t_start = ggml_time_us();

if (method == 1) {
quantize_1(src0, src0_gq, M, K);
Expand Down Expand Up @@ -2494,7 +2493,7 @@ int main(int argc, const char ** argv) {
quantize_6(src1, src1_gq, N, K);
}

const uint64_t t_end = get_time_us();
const int64_t t_end = ggml_time_us();
printf("convert time: %f ms / method = %d\n", (t_end - t_start) / 1000.0, method);
}

Expand All @@ -2504,8 +2503,8 @@ int main(int argc, const char ** argv) {

const int nIter = 1;

const clock_t start = clock();
const uint64_t start_us = get_time_us();
const int64_t start = ggml_cycles();
const int64_t start_us = ggml_time_us();

double iM = 1.0/M;
double sum = 0.0f;
Expand Down Expand Up @@ -2544,9 +2543,9 @@ int main(int argc, const char ** argv) {
}

{
const clock_t end = clock();
const uint64_t end_us = get_time_us();
printf("%s: elapsed ticks: %ld\n", __func__, end - start);
const int64_t end = ggml_cycles();
const int64_t end_us = ggml_time_us();
printf("%s: elapsed ticks: %" PRIu64 "\n", __func__, end - start);
printf("%s: elapsed us: %d / %f ms\n", __func__, (int)(end_us - start_us), (end_us - start_us) / 1000.0 / nIter);
}

Expand Down
Loading

0 comments on commit c1bb712

Please sign in to comment.