Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows] Build applications tests and benchmarks on Windows [Include #2924 changes] #2952

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gkisalapl
Copy link
Contributor

This PR add possibility to run soma applications, tests and benchmarks on windows
It also fix support for blas and avx on windows

Self-evaluation:

  1. Build test: [X]Passed [ ]Failed [ ]Skipped
  2. Run test: [X]Passed [ ]Failed [ ]Skipped

@gkisalapl gkisalapl changed the title Apps tests windows [Windows] Build applications tests and benchmarks windows Feb 14, 2025
@dkjung
Copy link
Collaborator

dkjung commented Feb 14, 2025

You could make two PRs if you had two features. That would help others review. Just let this as it is for now.
I'll see it, thanks!

Copy link
Collaborator

@dkjung dkjung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@gkisalapl gkisalapl force-pushed the apps_tests_windows branch 4 times, most recently from 1db2541 to 17aaadc Compare February 17, 2025 11:27
@gkisalapl
Copy link
Contributor Author

You could make two PRs if you had two features. That would help others review. Just let this as it is for now. I'll see it, thanks!

I originally make this changes in 2 PRs but first one is in review for more than week (see #2924)

@gkisalapl gkisalapl changed the title [Windows] Build applications tests and benchmarks windows [Windows] Build applications tests and benchmarks Windows Feb 17, 2025
@gkisalapl gkisalapl marked this pull request as ready for review February 17, 2025 21:48
@gkisalapl gkisalapl requested a review from haehun as a code owner February 17, 2025 21:48
Copy link
Contributor

@djeong20 djeong20 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! can't wait to dive into benchmarking on Windows :)

@@ -0,0 +1,4 @@
[wrap-git]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move *wrap files under the subprojects directory. (#2917)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move *wrap files under the subprojects directory. (#2917)

Ok

@EunjuYang
Copy link
Contributor

EunjuYang commented Feb 18, 2025

You could make two PRs if you had two features. That would help others review. Just let this as it is for now. I'll see it, thanks!

I originally make this changes in 2 PRs but first one is in review for more than week (see #2924)

For the case, please mention the dependency between PRs in your title. This will be helpful for reviewers!
For example, add [Wait for #2924] at the beginning of your title!

@gkisalapl gkisalapl changed the title [Windows] Build applications tests and benchmarks Windows [Windows] Build applications tests and benchmarks Windows [include #2924 changes] Feb 18, 2025
@gkisalapl gkisalapl changed the title [Windows] Build applications tests and benchmarks Windows [include #2924 changes] [Windows] Build applications tests and benchmarks on Windows [include #2924 changes] Feb 18, 2025
@gkisalapl gkisalapl changed the title [Windows] Build applications tests and benchmarks on Windows [include #2924 changes] [Windows] Build applications tests and benchmarks on Windows [Include #2924 changes] Feb 18, 2025

nntr_alex_resdir = nntr_app_resdir / 'AlexNet'
run_command('cp', '-lr', res_path, nntr_alex_resdir)
if host_machine.system() == 'windows'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need that, it can be done in native file.
Please see https://mesonbuild.com/Machine-files.html#binaries
and also my POC

[binaries]
#mkdir = ['mkdir']
mkdir = ['wine', 'cmd.exe', '/c','mkdir']
nproc = ['wine', 'cmd', '/c', '@echo', '%NUMBER_OF_PROCESSORS%']
touch = ['@DIRNAME@'/'touch.bat']

It'll require find_program('cp')

add_project_arguments(['-mavx2'], language: ['c','cpp'])
message('-march=native added for AVX hardware acceleration.')
if host_machine.system() == 'windows'
add_project_arguments(['/arch:AVX2'], language: ['c','cpp'])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also possible in native-file
cpp_args=...
cpp_link_args=...
we still need if != windows`

meson.build Outdated
run_command('mkdir', '-p', nntrainer_resdir)

if host_machine.system() == 'windows'
nntrainer_resdir_win = nntrainer_resdir.replace('/', '\\')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we construct it correctly using '/'?
Couldn't test with wine since Z:\ is required for abs path.

Comment on lines +323 to +327
blas_options.add_cmake_defines({'BUILD_TESTING': false})
blas_options.add_cmake_defines({'BUILD_BENCHMARKS': false})
blas_options.add_cmake_defines({'BUILD_SHARED_LIBS': false})
blas_options.add_cmake_defines({'BUILD_WITHOUT_LAPACK': true})
blas_subproject = cmake.subproject('openblas', options: blas_options, required: true)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't ever test it but worth checking if defining those in native [cmake] section works

if not benchmark_dep.found()
benchmark_options = cmake.subproject_options()
if host_machine.system() == 'windows'
benchmark_options.append_compile_args('c', windows_compile_args)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again native file

meson.build Outdated
libm_dep = cxx.find_library('m') # cmath library
libdl_dep = cxx.find_library('dl') # DL library
if host_machine.system() != 'windows'
libm_dep = cxx.find_library('m') # cmath library

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

required: false should do

meson.build Outdated
libdl_dep = cxx.find_library('dl') # DL library
if host_machine.system() != 'windows'
libm_dep = cxx.find_library('m') # cmath library
libdl_dep = cxx.find_library('dl') # DL library

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

Comment on lines 425 to 429
if get_option('platform') == 'android'
iniparser_root = meson.source_root() / 'third_party' / 'iniparser'
iniparser_root = meson.source_root() / 'subprojects' / 'iniparser'
iniparser_dep = declare_dependency()
else
iniparser_dep = dependency('iniparser', required : false, version : '>=3.2') # iniparser

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could use `dependency(..., fallback='iniparse')

libcurl_dep = dependency('libcurl')
if not tflite_dep.found()
error('Tensorflow-Lite dependency not found')
if host_machine.system() != 'windows'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to make it optional for all platforms in 'Applications', I already do to some degree for openvino.
Warn that something-something is unsupported

meson.build Outdated
endif
subdir('Applications')
endif
endif

if get_option('platform') != 'android'
if get_option('platform') != 'android' and host_machine.system() != 'windows'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use get_option() here really, since it's already optional by meson.options

@@ -207,15 +207,17 @@ std::vector<std::string> getPluginPaths() {
const std::string getFullPath(const std::string &path,
const std::string &base) {
/// if path is absolute, return path
if (path[0] == '/') {
if (std::filesystem::path(path).is_absolute()) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe global alias since it is *.cpp

namespace fs = std::filesystem;

What I already do.

@@ -231,12 +231,12 @@ bool ClContext::clCreateKernel(std::string &kernel_string,
size_t binary_size = fs.tellg();
fs.seekg(0, std::ios::beg);

unsigned char chunk[binary_size];
fs.read((char *)chunk, binary_size);
std::vector<unsigned char> chunk(binary_size);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Brace constructor? Nitpick

@@ -163,6 +163,7 @@ void ReshapeLayerCl::ReshapeProcess(Tensor const &input, Tensor &output) {
}
}

#ifdef ENABLE_FP16

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool

thread_dep,
openmp_dep
]

if host_machine.system() != 'windows'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

required:false should do it

@@ -101,9 +105,13 @@ else
install_dir: nntrainer_libdir
)

nntrainer_lib = nntrainer_shared
if get_option('default_library') == 'static'
if host_machine.system() == 'windows'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment? What is going on here?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should ban default_library=shared build on windows, or override it in native file and warn/error at toplevel

Comment on lines +281 to +290
#if defined(_WIN32)
__m256 temp = _mm256_loadu_ps(&X[i]);
_mm256_storeu_ps(&Y[i], temp);
#else
__asm__ __volatile__("vmovups (%1), %%ymm0\n\t"
"vmovups %%ymm0, (%0)\n\t"
:
: "r"(&Y[i]), "r"(&X[i])
: "ymm0", "memory");
#endif

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonder if we really wan't inline asm here.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be same modulo forcing ymm0 here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Current nntrainer is undergoing major refactor process on blas-level codes, so it is highly recommended to remove any fixes at tensor/blas_* files if not super urgent.

Copy link

@piotrrak piotrrak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't finish this review, but looks good, probably will rebase my changes.

@@ -1,8 +1,15 @@
build_root = meson.build_root()
res_path = meson.current_source_dir() / '..' / 'res'
fs = import('fs')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move closer to begin of file, it'll be useful
It's include/import as in other language.

@gkisalapl
Copy link
Contributor Author

Didn't finish this review, but looks good, probably will rebase my changes.

I'll add proposed modifications in next PR

@piotrrak
Copy link

@gkisalapl fine by me, thanks

This PR add possibility to run soma applications, tests and benchmarks on windows
It aslo fix support for blas and avx on windows

**Self-evaluation:**
1. Build test: [X]Passed [ ]Failed [ ]Skipped
2. Run test:   [X]Passed [ ]Failed [ ]Skipped

Signed-off-by: Grzegorz Kisala <[email protected]>
@dkjung dkjung requested a review from piotrrak February 25, 2025 07:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants