Skip to content

Commit 2a439c5

Browse files
Moved nitpick and cases to test folder
Simplified nitpick related macros in CMakeLists.txt Provided a README to test/cases
1 parent f131413 commit 2a439c5

13 files changed

Lines changed: 56 additions & 33 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,5 @@ build/*
4141
.vs
4242
CMakeSettings.json
4343

44+
# Autogenerated files
45+
test/cases/*_gen.hh

CMakeLists.txt

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -291,51 +291,34 @@ define_test(test_processor bparser) #is it broken? -LV
291291
define_test(test_speed bparser)
292292
define_test(test_simd)
293293

294-
macro(define_nit_gen make_name def_file gen_file)
295-
set(src_name "nitpick_generate")
296-
set(nit_source "${CMAKE_CURRENT_SOURCE_DIR}/nitpick/${src_name}.cc")
294+
macro(define_nit_target make_name def_file gen_file src_name)
295+
set(nit_source "${CMAKE_CURRENT_SOURCE_DIR}/test/nitpick/${src_name}.cc")
297296
set(nit_name "${src_name}_${make_name}")
298297
set(nit_binary "${nit_name}_bin")
299298

300299
add_executable(${nit_binary} EXCLUDE_FROM_ALL ${nit_source} )
301300
add_dependencies(${nit_binary} bparser)
302301
target_link_libraries(${nit_binary} bparser)
303-
#set_property(TARGET ${nit_binary} PROPERTY COMPILE_DEFINITIONS "DEF_FILE=$<PATH:NORMAL_PATH,\"${def_file}\">;GEN_FILE=$<PATH:NORMAL_PATH,\"${gen_file}\">")
304302
set_property(TARGET ${nit_binary} PROPERTY COMPILE_DEFINITIONS "DEF_FILE=\"${def_file}\";GEN_FILE=\"${gen_file}\"")
305303

306304
add_custom_target(${nit_name}
307305
COMMAND "$<TARGET_FILE:${nit_binary}>"
308306
DEPENDS ${nit_binary}
309-
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/cases")
307+
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/test/cases")
310308
endmacro()
311309

312-
macro(define_nit_run make_name def_file gen_file)
313-
set(src_name "nitpick_run")
314-
set(nit_source "${CMAKE_CURRENT_SOURCE_DIR}/nitpick/${src_name}.cc")
315-
set(nit_name "${src_name}_${make_name}")
316-
set(nit_binary "${nit_name}_bin")
317-
318-
add_executable(${nit_binary} EXCLUDE_FROM_ALL ${nit_source} )
319-
add_dependencies(${nit_binary} bparser)
320-
target_link_libraries(${nit_binary} bparser)
321-
#set_target_properties(${nit_binary} PROPERTIES COMPILE_DEFINITIONS "DEF_FILE=$<PATH:NORMAL_PATH,${def_file}>;GEN_FILE=$<PATH:NORMAL_PATH,${gen_file}>")
322-
set_property(TARGET ${nit_binary} PROPERTY COMPILE_DEFINITIONS "DEF_FILE=\"${def_file}\";GEN_FILE=\"${gen_file}\"")
323-
324-
add_custom_target(${nit_name}
325-
COMMAND "$<TARGET_FILE:${nit_binary}>"
326-
DEPENDS ${nit_binary}
327-
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/cases")
328-
endmacro()
310+
macro(define_nit make_name)
311+
set(nit_def_file "${make_name}_def.hh")
312+
set(nit_gen_file "${make_name}_gen")
329313

330-
macro(define_nit make_name def_file gen_file)
331-
define_nit_gen(${make_name} ${def_file} ${gen_file})
314+
define_nit_target(${make_name} ${nit_def_file} "${nit_gen_file}.hh" "nitpick_generate") #generate the _gen.hh file
332315

333-
define_nit_run(${make_name} ${def_file} ${gen_file})
316+
define_nit_target(${make_name} ${nit_def_file} "${nit_gen_file}_ref.hh" "nitpick_run") #run the _gen_ref.hh file
317+
define_nit_target("${make_name}_edit" ${nit_def_file} "${nit_gen_file}_edit.hh" "nitpick_run") #run the _gen_edit.hh file
334318
endmacro()
335319

336-
define_nit(basic_expr basic_expr_def.hh basic_expr_gen.hh)
337-
define_nit(norm2 norm2_def.hh norm2_gen.hh)
338-
define_nit_run(norm2_mac norm2_def.hh norm2_gen_edit.hh)
320+
define_nit(basic_expr)
321+
define_nit(norm2)
339322

340323

341324
#set(src_name "nitpick_generate")

test/cases/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
# Nitpick test cases
3+
The nitpick test cases allows developers to time and compare different Directed Acyclic Graphs (DAG) of ScalarNodes for various bparser expressions.
4+
5+
## File structure
6+
7+
There are 4 different files for each case:
8+
* `<name>_def.hh` - Defines what the parser expression is, what are the variable shapes and names and the result shape
9+
* `<name>_gen.hh` - Autogenerated file containing a reconstruction of the parser's DAG. This file is in .gitignore
10+
* `<name>_gen_ref.hh` - The autogenerated file before being edited.
11+
Most likely identical to `<name>_gen.hh` but the autogenerated file can look different now than how it would generate before.
12+
* `<name>_gen_edit.hh` - Former file, but edited. The DAG may be constructed more optimally or is using different ScalarNode operations
13+
14+
## Adding a case
15+
16+
1. Create a `<name>_def.hh` file.
17+
* This file must define the function `void def(ExprCase&)`
18+
* You must call the `ExprCase::parse` method to set the bparser's expression.
19+
* You must specify the result shape using the `ExprCase::set_result_shape` method.
20+
* You may use the `ExprCase::set_variable` and `ExprCase::set_var_copy` methods.
21+
They are similar to `Parser::set_variable` and `Parser::set_var_copy`, except you don't need a double pointer.
22+
* You may use `#ifndef NITPICK_IDE_IGNORE #endif` to trick the IDE into thinking something exists and/or is included. This block will not actually be compiled.
23+
2. Declare the case in CMakeLists.txt
24+
* Add `define_nit(<name>)` near similar definitions
25+
3. Generate the file
26+
* Make the `nitpick_generate_<name>` target
27+
4. Copy the autogenerated file
28+
* First copy should have `_ref` at the end of the filename
29+
* Second copy should have `_edit` at the end of the filename
30+
5. Run and compare
31+
* Use the `nitpick_run_<name>` and `nitpick_run_<name>_edit` Make targets to run and time the original or edited file
32+
33+
34+
## Timing
35+
The nitpick_run.cc file will repeatedly:
36+
1. Allocate \<variable_size> × vec_size for each variable set in the ExprCase object where vec_size changes every iteration
37+
2. Run and time the autogenerated DAG for N ÷ vec_size times, where N is a very high constant integer
38+
* This is to spend more time computing small vec_sizes
39+
3. Deallocate memory from step 1.
40+
41+
This is done for every vec_size which is an array of integers set in the nitpick_run.cc file

0 commit comments

Comments
 (0)