/robowaifu/ - DIY Robot Wives

Advancing robotics to a point where anime catgrill meidos in tiny miniskirts are a reality.

Build Back Better

Sorry for the delays in the BBB plan. An update will be issued in the thread soon in late August. -r

Max message length: 6144

Drag files to upload or
click here to select them

Maximum 5 files / Maximum size: 20.00 MB

More

(used to delete files and postings)


“In the confrontation between the stream and the rock, the stream always wins- not through strength but by perseverance.” -t. H. Jackson Brown


C++ General Robowaifu Technician 09/09/2019 (Mon) 02:49:55 No.12
C++ Resources general The C++ programming language is currently the primary AI-engine language in use. >browsable copy of the latest C++ standard draft: https://eel.is/c++draft/ isocpp.org/get-started https://archive.is/hp4JR stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list https://archive.is/OHw9L en.cppreference.com/w/ https://archive.is/gt73H www.youtube.com/user/CppCon https://archive.is/QGynC BTW if you're new to C++ and you're stuck on Windows (either you can't or won't upgrade to Linux) then you can at least incorporate a good, open shell into your system to begin with so you can follow along. Start at this link, and if you have any questions just ask ITT: www.msys2.org/ https://archive.fo/p3EUc >=== -add standard draft hotlink
Edited last time by Chobitsu on 10/10/2024 (Thu) 03:01:26.
>>28906 >(sorry for the necrobump) NONSENSE! :^) We here on /robowaifu/ don't believe in any such thing! :D BTW, if you do create a site, please allow for Torposting of files. Also, a post 'move' feature (such as the one supported by JSchan server software) would be very nice. And lastly, I may say that having a JSON API for your pages would be very welcome, since it would allow tools like our BUMP (and soon, Bumpmaster) to effectively access/archive your site's boards. Good luck with your project, Anon. Cheers. :^) >=== -add 'JSON' cmnt
Edited last time by Chobitsu on 04/04/2024 (Thu) 21:44:08.
>>28906 That's great. Can it import backups of boards via json? You probably just use the database, so is it documented where what belongs or is it only in the code? Also, did you share it in other places, so people who know Zig look at the code?
Just a heads-up that I've picked back up work on the PPP2 project to support our C++ Classroom thread : (>>19777) , and as a direct part of our accompanying /robowaifu/ C++ Textbook thread : (>>18749) . Here's an early peek at the new files layout. I hope to be ready and pick the classroom back up around late May/early June. [1] We'll see. Cheers. >main_p415.cpp : // filename: ./ch_12/main_p415.cpp // Code derived from Bjarne Stroustrup's PPP2 book // § 12.3 A first example // -and beginning on p415 // -Instead of using the recommended Meson project way, this file can be built // and run standalone (from the root directory of the overall PPP2 project) : /* g++ ./ch_12/main_p415.cpp ./lib_src/all_srcs.cpp \ `fltk-config --ldflags --use-images` \ -I./lib_include/ -std=c++20 -O2 -Wall -pedantic -o p415 ./p415 */ // --=^=-- #include "Graph.h" // get access to our graphics library facilities #include "Simple_window.h" // get access to our window library //------------------------------------------------------------------------------ /** */ int main() { using namespace rw::Graph_lib; // our graphics facilities are in Graph_lib Point tl{100, 100}; // to become top left corner of window Simple_window win{tl, 600, 400, "Canvas"}; // make a simple window Polygon poly; // make a shape (a polygon) poly.add(Point{300, 200}); // add a point poly.add(Point{350, 100}); // add another point poly.add(Point{400, 200}); // add a third point poly.set_color(Color::red); // adjust properties of poly win.attach(poly); // connect poly to the window win.wait_for_button(); // give control to the display engine } // --=^=-- // Copyright (2024), the anonymous collective // License MIT (Expat) https://opensource.org/licenses/MIT --- 1. Planned schedule cancelled. cf. : (>>31023) >=== -minor edit -patch crosslinks -minor code patch -add cancel notice
Edited last time by Chobitsu on 04/26/2024 (Fri) 17:30:28.
Great good Sepples news -- particularly for /robowaifu/ ! (>>31023)
Open file (861.06 KB 600x620 2b dancing.gif)
Hello, I've posted on this board pretty much on and off since 8chan. I'm glad to see a lot of the familiar faces here, especially chobitsu. remember that time we all thought he was dead? Anyways, I came here primarily to ask a question. Should I devote more time to learning C++ or python? I feel more comfortable with C++ but it's a lot more complicated than python. Python on the other hand, is much more simpler however a problem with it is I dislike how the loops and if statements work, you know how you have to have everything perfectly indented. I am almost done with my computer programming AS degree, as in at the end of July is the end of my final class, coincidentally which is python. I want to take things further but I'm not sure which one is more useful.
>>32122 Most of the open-source AI stuff is done in python. There's some editors that can help with the indenting thing (thonny not being one of them)
>>32122 Depends what you want to work on. If you want to do robotics, you should focus on C++. If you want to do AI, then focus on Python. Or you can do both, writing C++ and calling it from Python to enjoy the ease of Python and raw performance of C++. There has been rising interest lately in CUDA and C++ to squeeze the maximum performance out of hardware while training and to put models into production. A few years ago I would say you only need to know Python for AI but you should know both now, starting with Python first and moving onto C++ to optimize when you're ready to deploy. You do not want to ship your product with 10 GB of bloated Python libraries and hope it runs well on systems running at 1/20th the speed and using HDDs instead of NVMe.
>>32122 Hello, Anon. Welcome back! >we all thought he was dead? Eheh, sorry 'bout that Anons... :P >C++ or python? Long story short, my answer is obviously C++ . We have far more need of -- and far fewer of -- C++ devs here on /robowaifu/ . For more info, see: -All AI programming is done in Python. So why are you using C & C++ here? (>>21057, >>21091, >>27167, >>29994) BTW, JetBrains (the company) makes world-class IDEs for both languages. And CLion (their C++ IDE) in particular, currently stands alone apart from all the rest in the field IMHO. ABTW, as full-time students, we get free access to their entire product line for at least a year. I recommend you take advantage of this before you graduate, Anon. https://www.jetbrains.com/store/?section=students&billing=yearly Good luck, Anon! Cheers. :^) --- One other thing: the well-known Tiobe Index has C++ moving into the #2 position -- surpassing C for the first time in history! Interesting times ahead. The Robowaifu Age dawns soon, I'd wager. :^) https://www.tiobe.com/tiobe-index/ >=== -fmt, minor edit -add Tiobe cmnt
Edited last time by Chobitsu on 07/11/2024 (Thu) 02:10:14.
>>32122 >C++ or Python Chobitsu likes C++ and seemingly doesn't like Python. That should be obvious. Programmers tend to always be biased toward certain languages so here I go as a non programmer (but i have done a little C++ ages ago). Julia may be a better language to use in case of autonomous robotics since it is a data science language including ML and AI and doesnt require a license like MATLAB which is unfortunate since MATLAB has libraries for humanoid robots. Julia uses a Python like syntax but i recall reading it removes the space sensitivity i see so many get troubled over with Python. It is also able to call on C/C++, R, Python, Rust, Fortran. It has been claimed it may solve the issue of having to use two languages for robotics because it is fast enough to operate in real time while Python is less than ideal even though pretty much all the recent ML stuff is written in Python. Since Julia is similar enough in syntax you possibly could more easily language migrate programs written in Python than you could going Python to C++ but that is just an assumption. https://ieeexplore.ieee.org/document/8793875 https://juliarobotics.org/tutorials/ But since this is for a degree you should just focus on Python so you can avoid confusion mixing up Julia and Python code while in your final class.
>>32178 >Chobitsu likes C++ Quite true, and for one reason alone: it's simply the single best language selection currently for robowaifu systems programming. No other language choice will afford us such good odds for success at devising appealing & effective, totally-Globohomo-unencumbered, secure, private & disconnected DIY waifus at home. C will be important as well for smol <=32K devices; things like tiny onboard microcontrollers & sensors, which will communicate data back & forth with the robowaifu's core systems. We'll likely even need a tiny bit of ASM before all's said and done. >and seemingly doesn't like Python. Heh, I'm almost fully self-taught in programming. The single exception to this is the one programming class I've had in college. Namely, Python. I made perfect scores on every assignment in the class that semester: 4.0+ . So yeah, IMO Python's fine...as long as it's used for what it's intended for. To wit (and in a word): scripting. But it's essentially useless to us all for the highly-critical systems programming areas of robowaifu development. Both will be needed in the end. But the basic fact is that we have a glut of Python devs here, and a dearth of Modern C++ devs. Until we get on top of the realtime-systems design & engineering needs for DIY robowaifu creation, being able to script them is of little utility -- basically a 'company bikeshed'. Simple as. Cheers, Anon. :^) >=== -fmt, prose edit
Edited last time by Chobitsu on 07/12/2024 (Fri) 18:27:36.
>>32182 what would you need asm for? even the most obscure devices have a c compiler and trying to write better code than the compiler is almost impossible when they use every trick youre probably not even aware of like xor %rax %rax which seems like a pointless inefficiency sprinkled in the code for no reason except its just a register renaming trick to get rid of false dependencies even vectorising isnt that bad but c++ already has intrinsics for that
>>32185 It's a fair question, Anon. Short answer: Hopefully we won't. But this is frontiersman's work in many respects. I don't consider it at all unlikely that we'll need to devise custom hardware & the electronics to go with. This is going to also require new drivers to be written in the event. Since some of these custom boards are likely going to be venturing deep into the hard-realtime time domains, it's not at all impossible that ASM turns out to be the only feasible choice. But again, hopefully we can solve the majority of all cases at the highest levels -- in this order: >1. C++ >2. C >3. ASM Then Python/Lua for scripting everything. Cheers.
Got bored and tried some C over past few days and it is pretty annoying how easy it is to write code that executes without mention of an error but is bad code or something that follows same pattern that works say for an integer, float or character but doesnt work when you use a string in same place which seems illogical to me. But i also dont have a working machine to code on so just using an online compiler to play around with simple things.
>>32342 by design, warnings are optional you have to enable them, in gcc its -Wall -pedantic -Werror i think youre confusing datatypes with an array of that datatype ( char / char[] ), theres no string type in c because theres no such thing really it doesnt make sense, its string as in literally a string of characters as in an array of chars, writing "asd" is just for convince for not having to write (char[4]){'a','s','d','\0'}
>>32342 If you're annoyed by that, then it's possible that C or C-style C++ might not be your thing. The opus of such devs has always been "Trust the Developer!" :^) OTOH, if you're still keen on doing systems work (as opposed to say, scripting, where Python is a clear choice), then Modern C++ should fit the bill. For example, regarding this complaint: >or something that follows same pattern that works say for an integer, float or character but doesnt work when you use a string in same place which seems illogical to me. These types are actually consistent in their behavior in C++, with only the char type having a caveat : >operators.cpp [1] #include <iostream> #include <string> using namespace std; int main() { int a{1}, b{2}; float c{3.}, d{4.}; char e{'e'}, f{'f'}; string g{"foo"}, h{"bar"}; // each of these types has an '<<' operator defined already : cout << a << ' ' << b << ' ' << c << ' ' << d << ' ' << e << ' ' << f << ' ' << g << ' ' << h << '\n'; // each of these types also has a '+' operator defined already : auto ab{a + b}; auto cd{c + d}; auto ef{e + f}; // operator+ for char will decay into an int-based-ASCII value, so use as string efs{e, f}; // a string init-list of elements to preserve them concatenated instead auto gh{g + h}; cout << ab << ' ' << cd << ' ' << ef << ' ' << efs << ' ' << gh << '\n'; } >output: 1 2 3 4 e f foo bar 3 7 203 ef foobar --- With C++ you can define your own custom operators, so something like this is doable as well : >robowaifu_FKIK.cpp class RW_elbow_joint { //... }; // one type class RW_wrist_joint { //... }; // one similar, but distinct type // both types can work with a special custom operator+ that you would devise : bool precheck_forearm_FK_solve(RW_elbow_joint const& ej, RW_wrist_joint const& wj) { //... auto FK{ej + wj}; // the new, custom operator+ in action return FK.is_valid(); } --- 1. https://coliru.stacked-crooked.com/a/e64b062b6db0eb6a >=== -minor edit -add FKIK snippet -add coliru hotlink
Edited last time by Chobitsu on 07/28/2024 (Sun) 04:13:45.
>>32343 What I did was take this lesson #include <stdio.h> int main() { char chr; printf("Enter a character: "); scanf("%c",&chr); printf("You entered %c.", chr); return 0; } Then I realized this seems similar to a messaging system so I tried to see what happens. I was able to replace it for integers and that ran so then I tried to see if I could make it give me all the characters I type in a sentence. #include <stdio.h> int main() { char chr; printf("Enter a message: "); //%s short for string scanf("%s",&chr); printf("You wrote %s.", chr); return 0; } I know this is wrong since I get a segmentation fault but the logic of the syntax structure doesnt follow the same pattern as I would expect. >>32346 Maybe. Nothing drew me to the language, just it being so common I thought I should look at C and then C++ To be familiarized with it.
>>32351 Here's a couple of operator>> examples : >char_str_inputs.cpp [1] #include <iostream> #include <string> using namespace std; int main() { char foo{' '}; string bar; // as with operator<< , these types each already have operator>> defined cin >> foo; // example input: 'Z' cin >> bar; // example input: "Robowaifus" cout << "You input '" << foo << "', and \"" << bar << "\"\n"; } >output: You input 'Z', and "Robowaifus" As before, both types are consistent in their usage. String type also supports getline() operations. https://en.cppreference.com/w/cpp/string/basic_string/getline --- 1. https://coliru.stacked-crooked.com/a/6bb9cdec84af3c45 >=== -add coliru hotlink
Edited last time by Chobitsu on 07/28/2024 (Sun) 02:46:16.
>>32352 I was focusing on C first since C++ is technically an extension of C so I wanted to see the barrier. That code must be C++ because it wouldnt run as C but did for C++ but I put in "test words" and it gave me "you input 't' and 'est' " which is different from what I was going for though interesting to see if I put multiple words separated by a space it behaves that way different from one word and enter then another and enter. Tried seeing if changing it to string bar and removing all foo references which still only output a single word. Then when I look up how to do it, it's totally different setup for a getline...bleh #include <iostream> #include <string> using namespace std; int main() { string usr_str; getline(cin, usr_str); cout << "You input: " << usr_str << endl; return 0; }
>>32354 Good job, Anon! Way to do research on your own. Yes, you've found the way to do regularized input for a char (your first 't'), string, and whitespace-separated string collections. As your example shows, it's both simple to do, and pretty much bulletproof from unintentional crashing (since the resources are properly managed through the type's handle (ie, std::string).
>>32354 >>32355 Also, filestreams (in or out) work the same as textstreams do. >fortune_cookie.cpp [1] #include <fstream> #include <iostream> #include <string> using namespace std; // given: a multi-line textfile named 'fortunes.txt' in the project path, containing : /* you will be singled out for promotion good ideas will spring forth naturally from your mind in the coming week good health will be yours for a long time you will be spending time outdoors in the mountains near water you will soon take a very pleasant and successful trip you will be blessed with longevity your secret desire to completely change your life will manifest */ // demo: that filestreams work just like textstreams do : int main() { // similar to cin & cout, but for input files ifstream ifs{"fortunes.txt"}; // C++ streams also have an operator bool() return value, which lets us write this code : for (string line; getline(ifs, line);) cout << line << '\n'; } >output: you will be singled out for promotion good ideas will spring forth naturally from your mind in the coming week good health will be yours for a long time you will be spending time outdoors in the mountains near water you will soon take a very pleasant and successful trip you will be blessed with longevity your secret desire to completely change your life will manifest --- 1. https://coliru.stacked-crooked.com/a/b36921b1bc408268 >=== -sp, minor edit -add coliru hotlink
Edited last time by Chobitsu on 07/28/2024 (Sun) 02:54:52.
>>32361 Of course, output filestreams also work in C++ as well. >time_is_now.cpp [1] #include <fstream> #include <iostream> #include <string> using namespace std; // demo: C++ output filestreams are just streams, like all the rest : int main() { ofstream ofs{"timing.txt"}; // this will create a file if it doesn't already exist string s{ "Now is the time for all good men, with their robowaifus by their side, " "to come to the aid of their country." }; ofs << s << '\n'; ofs.close(); // IMHO, always a good idea to explicitly close output files when done writing to them //--- ifstream ifs{"timing.txt"}; string word; while (ifs >> word) // stream's operator>> parses on whitespace cout << word << '\n'; } >output: Now is the time //... aid of their country. --- 1. https://coliru.stacked-crooked.com/a/4ef7677ea61a19a4 >=== -minor edit -add coliru hotlink
Edited last time by Chobitsu on 07/28/2024 (Sun) 02:58:11.
>>32342 >But i also dont have a working machine to code on so just using an online compiler to play around with simple things. Ahh, so I added coliru hotlinks to my examples above so you could play with them directly without a local dev box. Cheers. :^)
>>32375 how do you change the delimiter for <<, it just stops reading after any whitespace it makes slurping a file a pain like with json files you use {:} as delims not whitespace
>>32436 Good question, Anon. We actually had a class lesson in our textbook here for just that, for stream's operator>> : (>>21874, >>21886) . You'd simply do similar code to write your custom operator<< . Give it a shot and please post your results here. Feel free to ask any questions, and good luck Anon! Cheers. :^)
'C++26 Senders'' (the std::execute namespace) /comfy/ funposting-related : https://trashchan.xyz/comfy/thread/9418.html#10396 It already has a working implementation today, Anon. Check it out: :^) https://godbolt.org/z/3cseorf7M --- >note: The C++ Standards Committee of today strongly encourages members to create practical, working examples before submitting proposals. Eric Niebler [1] has done just that via this repo. 1. https://github.com/ericniebler
>>32610 Decided to copypasta the Senders example code here too, since the Godbolt site can make things tight on a smol screen. >main.cpp #include <exec/static_thread_pool.hpp> #include <stdexec/execution.hpp> int main() { // Declare a pool of 3 worker threads: exec::static_thread_pool pool(3); // Get a handle to the thread pool: auto sched = pool.get_scheduler(); // Describe some work: // Creates 3 sender pipelines that are executed concurrently by passing to // `when_all` Each sender is scheduled on `sched` using `starts_on` and starts // with `just(n)` that creates a Sender that just forwards `n` to the next // sender. After `just(n)`, we chain `then(fun)` which invokes `fun` using the // value provided from `just()` Note: No work actually happens here. // Everything is lazy and `work` is just an object that statically represents // the work to later be executed auto fun = [](int i) { return i * i; }; auto work = stdexec::when_all( stdexec::starts_on(sched, stdexec::just(0) | stdexec::then(fun)), stdexec::starts_on(sched, stdexec::just(2) | stdexec::then(fun)), stdexec::starts_on(sched, stdexec::just(4) | stdexec::then(fun))); // Launch the work and wait for the result auto [i, j, k] = stdexec::sync_wait(std::move(work)).value(); // Print the results: std::printf("%d %d %d\n", i, j, k); } // sauce: https://github.com/NVIDIA/stdexec // also cf. CMake's missing Package Manager: https://github.com/cpm-cmake/CPM.cmake >output: 0 4 16 >CMakeLists.txt: # Actually, further dependencies on down the line for the STDEXEC project requires >CMake v3.25 currently. # -if your CMake is older and your package manager doesn't have the needed level, here's how I did it on Ubuntu Jammy: # sudo apt purge --auto-remove cmake # wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | sudo tee /usr/share/keyrings/kitware-archive-keyring.gpg >/dev/null # echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ jammy main' | sudo tee /etc/apt/sources.list.d/kitware.list >/dev/null # sudo apt update # sudo apt install cmake # # -cf. https://askubuntu.com/questions/355565/how-do-i-install-the-latest-version-of-cmake-from-the-command-line # (2nd answer) # cmake_minimum_required(VERSION 3.14 FATAL_ERROR) project(stdexecExample) # Downloading CMake's missing Package Manager: # # mkdir -p build/cmake # wget -O build/cmake/CPM.cmake https://github.com/cpm-cmake/CPM.cmake/releases/latest/download/get_cpm.cmake # # -cf. https://github.com/cpm-cmake/CPM.cmake # -also cf. https://github.com/cpm-cmake/CPM.cmake/wiki/Downloading-CPM.cmake-in-CMake include(build/cmake/CPM.cmake) # NOTE: This step can take a while to DL; check your network connection(s) & be patient... CPMAddPackage( NAME stdexec GITHUB_REPOSITORY NVIDIA/stdexec GIT_TAG main # This will always pull the latest code from the `main` branch. You may also use a specific release version or tag ) add_executable(main main.cpp) target_link_libraries(main STDEXEC::stdexec) >=== -patch 'stdexec::starts_on()' statements to reflect the current C++26 draft standard -add 'output:' codeblock -minor tweak of async work params 'stdexec::just(n)' -add 'sauce', 'also' hotlinks to code -ren codefile name to 'main.cpp' -add, patch 'CMakeLists.txt' contents
Edited last time by Chobitsu on 10/06/2024 (Sun) 23:31:31.
> ( C++ safety -related : >>33548 )
Gonna give it a try, any advice welcome. Also, any way to upload code without converting it to pdf?
>>33816 Hello, HCSM. Welcome! >Also, any way to upload code without converting it to pdf? A) If it's a snippet less than 6144 chars long, simply post it here using the code block tags. (cf. the little help link in the page header bar above). B) If you do the file route, then don't 'convert' to a pdf file, Anon. Simply rename the cleartext codefile with a .pdf extension, then post it. I'm personally fond of the muh_foo_file.ren_ext_to.cpp.pdf naming form. >any advice welcome. Very likely just one, at this point in your C++ career. Namely PPP3 : (cf. >>31023 ). Good luck, Anon. Hope to hear more from you here on /robowaifu/ . Cheers. :^) >=== -minor edit
Edited last time by Chobitsu on 10/05/2024 (Sat) 02:46:41.
>>33817 Thanks. Any one knows if using the gpu through OpenGL is worth it?
>>33829 Y/w, Anon. <---> >Any one knows if using the gpu through OpenGL is worth it? Please define 'worth it' ? If you're interested in creating your own high-performance rendering system (say your own game, or your own Robowaifu Simulator [1][2] ), then learning OpenGL from scratch [3] is a very good thing. OTOH, if you just want to use OpenGL (et al) in such a project, then simply taking advantage of an already-existing framework is probably a smarter choice. There are many out there, but for a number of reasons I think we'd recommend Raylib [4] first & foremost here, Anon. <---> If instead you mean you want to use the GPU's processing power for non-graphical, general computing purposes (so-called GPGPU), then that's a whole other (and complex) discussion we can also have ITT. --- 1. ( >>155 ) 2. https://gitlab.com/Chobitsu/muh-robowaifu-simulator 3. https://learnopengl.com/ 4. https://www.raylib.com/ >=== -minor edit
Edited last time by Chobitsu on 09/30/2024 (Mon) 23:57:12.
>>33831 https://gitlab.com/Chobitsu/muh-robowaifu-simulator I hadn't seen this before. Very nice. Thanks!
>>33866 Y/w Grommet. >Very nice. Thanks! Heh, it mostly was just a learning experience for me at that time (though it did run really fast on my non-gpu potatoe-top back then. :D >=== -minor edit
Edited last time by Chobitsu on 10/04/2024 (Fri) 16:23:14.
>>32632 Here's my own CMakeLists.txt file, w/o most comments, and also auto-DL'g cpm-make so I can just copypasta this into new projects. >CMakeLists.txt cmake_minimum_required(VERSION 3.14 FATAL_ERROR) project(stdexecExample) # download CPM.cmake file( DOWNLOAD https://github.com/cpm-cmake/CPM.cmake/releases/download/v0.40.2/CPM.cmake ${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake SHOW_PROGRESS EXPECTED_HASH SHA256=c8cdc32c03816538ce22781ed72964dc864b2a34a310d3b7104812a5ca2d835d ) include(${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake) CPMAddPackage( NAME stdexec GITHUB_REPOSITORY NVIDIA/stdexec GIT_TAG main # This will always pull the latest code from the `main` branch. ) add_executable(main main.cpp) target_link_libraries(main STDEXEC::stdexec)
>>32610 >>32632 >C++ Senders >current draft standard -related: https://en.cppreference.com/w/cpp/execution
>>33899 I discovered tonight that this experimental Senders implementation includes a working implementation of this work-stealing queue within the static threadpool tree [1][2][3][4] (Apache 2 license) : >"BWoS: Formally Verified Block-based Work Stealing for Parallel Processing" >Abstract: >"Work stealing is a widely-used scheduling technique for parallel processing on multicore. Each core owns a queue of tasks and avoids idling by stealing tasks from other queues. Prior work mostly focuses on balancing workload among cores, disregarding whether stealing may adversely impact the owner’s performance or hinder synchronization optimizations. Realworld industrial runtimes for parallel processing heavily rely on work-stealing queues for scalability, and such queues can become bottlenecks to their performance. >"We present Block-based Work Stealing (BWoS), a novel and pragmatic design that splits per-core queues into multiple blocks. Thieves and owners rarely operate on the same blocks, greatly removing interferences and enabling aggressive optimizations on the owner’s synchronization with thieves. Furthermore, BWoS enables a novel probabilistic stealing policy that guarantees thieves steal from longer queues with higher probability. In our evaluation, using BWoS improves performance by up to 1.25x in the Renaissance macrobenchmark when applied to Java G1GC, provides an average 1.26x speedup in JSON processing when applied to Go runtime, and improves maximum throughput of Hyper HTTP server by 1.12x when applied to Rust Tokio runtime. In microbenchmarks, it provides 8-11x better performance than state-of-the-art designs. We have formally verified and optimized BWoS on weak memory models with a model-checking-based framework. https://people.mpi-sws.org/~viktor/papers/osdi2023-bwos.pdf https://www.usenix.org/conference/osdi23/presentation/wang-jiawei https://www.youtube.com/watch?v=kQ3tRrM69UQ --- 1. ./build/_deps/stdexec-src/include/exec/__detail/__bwos_lifo_queue.hpp -(you will probably first need to query a library type declaration to DL the sauce files -- I did) -(ie, r-click a type, choose 'Go to declaration'. This triggers the file DLs in Juci++) 2. https://github.com/NVIDIA/stdexec/blob/main/include/exec/static_thread_pool.hpp 3. https://github.com/NVIDIA/stdexec/blob/main/include/exec/__detail/__bwos_lifo_queue.hpp 4. cf. exceptional ease of use in the final exec library call (ie, just werks fire-&-forget): // Declare a pool of 3 worker threads: exec::static_thread_pool pool(3); ( >>32632 ) >=== -add paper abstract -add/rm pixeldrain hotlink -minor edit -wrap hotlink in codeblock to patch L*nxchan's mangling of system lib file-naming within a hotlink :^)
Edited last time by Chobitsu on 10/07/2024 (Mon) 05:17:20.
Open file (3.79 MB 680x844 asd.gif)
made an ascii art generator for bmp files, couldnt figure out a spacing algorithm but tweaking the contrast or brightness was good enough for most images #include <iostream> #include <wchar.h> #include <locale> #include <stdlib.h> #define XMAX 80 #define YMAX 50 #define BRIGHTNESS 30 // shading level #define CONTRAST 20 // contour level using namespace std; struct bitmap { int w, h; char *data; }; class framebuffer { /* using brail unicode chars dotmatri: [4][2] { 0 3 1 4 2 5 6 7 } char = 16bit value is 0x2800 + dotmatrix read as binary */ public: int width = XMAX; int hieght = YMAX; int dotn[8] = { 0, 3, 1, 4, 2, 5, 6, 7 }; wchar_t *buffer = (wchar_t*)malloc( width * hieght * sizeof(wchar_t) ); void clear( void ) { for ( int r=0; r < hieght; r++ ) wmemset( &buffer[ r*width ], 0x2800, width ); } void draw( void ) { for ( int r=0; r < hieght; r++ ) wprintf( L"%*.*ls\n", width,width, &buffer[ r*width ] ); } void putpixel( unsigned int x, unsigned int y ) { int posx = x/2; int posy = y/4; x %= 2; y %= 4; if ( posx > width || posy > hieght ) // out of bounds return; wchar_t pixel = buffer[ posy * width + posx ]; pixel -= 0x2800; if ( pixel & ( 1 << dotn[ y*2 + x ] ) ) // already set return; pixel |= 1 << dotn[ y*2 + x ]; pixel += 0x2800; buffer[ posy * width + posx ] = pixel; } void putbitmap( int x, int y, struct bitmap *bmp ) { for ( int yc=0; yc < bmp->h; yc++ ) for ( int xc=0; xc < bmp->w; xc++ ) if ( bmp->data[ (yc * bmp->w) + xc ] ) putpixel( x + xc , y + yc ); } } FB; struct bitmap *loadfile( const char *filename ) { FILE *fp = fopen( filename, "r" ); if ( !fp ) wcout << L"! ERROR couldnt open " << filename << L'\n', exit(1); struct Header { unsigned int size; unsigned int x; unsigned int y; unsigned short int planec; unsigned short int depth; unsigned int compression; unsigned int rez; unsigned int xbitc; unsigned int ybitc; unsigned int biClrUsed; unsigned int biClrImportant; } __attribute__ ((packed)) Header; fseek( fp, 14, SEEK_SET ); fread( (char*)&Header.size, 1, sizeof( struct Header ), fp ); if ( Header.depth != 32 ) wcout << L"! ERROR file must be a 32bit .bmp\n" << (wchar_t)0x1F620, exit(2); struct bitmap *bmp = (struct bitmap*) malloc( sizeof(struct bitmap) ); // resize to framebuffer float xscale = ( Header.x > (XMAX*2) ) ? (float)Header.x / (float)(XMAX*2) : 1; float yscale = ( Header.y > (YMAX*4) ) ? (float)Header.y / (float)(YMAX*4) : 1; bmp->w = (float)Header.x / xscale; bmp->h = (float)Header.y / yscale; bmp->data = (char*) malloc( bmp->h * bmp->w + bmp->w ); char *file = (char*) malloc( Header.x * Header.y * 32 ); fread( file, 1, Header.x * Header.y * 32, fp ); int x=0, y=0; for ( float r=Header.y -1; r >= 0; r -= yscale, y++, x=0 ) for ( float c=0; c < Header.x; c += xscale, x++ ) { int check; // check pixel for brightness int32_t pixle = ((int32_t*)file)[ (int)r * Header.x + (int)c ]; unsigned char cur = 0; cur |= ( pixle & (0xff) ); cur |= ( pixle & (0xff<<8) ); cur |= ( pixle & (0xff<<16) ); check = ( cur < BRIGHTNESS ); // check surounding pixels for contrast for ( int yd=-1; yd<2; yd++ ) for ( int xd=-1; xd<2; xd++ ) { int y = (int)r + yd; int x = (int)c + xd; if ( ( !yd && !xd ) || // same pixel ( y < 0 || y >= Header.y ) || // out of bounds ( x < 0 || x >= Header.x ) // out of bounds ) continue; int32_t pixle = ((int32_t*)file)[ y * Header.x + x ]; unsigned char near = 0; near |= ( pixle & (0xff) ); near |= ( pixle & (0xff<<8) ); near |= ( pixle & (0xff<<16) ); if ( near > cur ) check |= ( (near - cur) > CONTRAST ); else check |= ( (cur - near) > CONTRAST ); } bmp->data[ y*bmp->w + x ] = check; } free( file ); fclose( fp ); return bmp; } int main( int argc, char **args ) { if ( argc < 2 ) exit(1); setlocale(LC_CTYPE, ""); struct bitmap *pic = loadfile( args[1] ); if ( pic ) { FB.clear(); FB.putbitmap( 0, 0, pic ); FB.draw(); } return 0; }
>>33909 POTD > saved LOL THIS IS GREAT ANON! :DD This whole arena of terminal vidya & media has been abandoned for the most part by newfags & scrubs. :^) BTW, I suggest you owe it to yourself to watch all this guy's stuff, Anon: 4'000fps+ FPS on the terminal!! https://www.youtube.com/watch?v=xW8skO7MFYw https://github.com/OneLoneCoder/CommandLineFPS >=== -fmt, minor edit -add code hotlink
Edited last time by Chobitsu on 10/08/2024 (Tue) 15:43:36.
Edited last time by Chobitsu on 10/08/2024 (Tue) 15:56:10.
>>33911 nice, just realized theres already bitmap tools on linux that makes it easy to edit and make files you can just #include in your code, its actual bitmaps though, in my code is technically using bytemaps lol
>>33922 >just realized theres already bitmap tools on linux Nice. Sauce, Anon?
Slightly cleaned-up (suited to my tastes, anyway -- I find this easier to reason about) working version of the current nonworking example of std::execution::scheduler [1] >main.cpp // orig. sauce (working) : https://godbolt.org/z/146fY4Y91 #include <stdexec/execution.hpp> // LOL, injecting into std:: namespaces... :D // namespace std::execution { using namespace stdexec; } // namespace std::execution //--- #include <iostream> #include <thread> //--- using namespace std::execution; using std::cout; using std::jthread; //--- class Single_thrd_cntx { public: Single_thrd_cntx() : thread_{[this] { loop_.run(); }} {} ~Single_thrd_cntx() { loop_.finish(); } auto get_scheduler() noexcept { return loop_.get_scheduler(); } private: Single_thrd_cntx(Single_thrd_cntx&&) = delete; // no move ctor run_loop loop_{}; // DESIGN: this init needed?? jthread thread_; }; int main() { Single_thrd_cntx ctx; // Note: No work actually happens here; the compute graph is simply enqueued auto sndr = schedule(ctx.get_scheduler()) | then([] { cout << "Hello world! Have an int.\n"; return 12; }) | then([](int arg) { return arg + 42; }); // work happens here auto [i] = sync_wait(sndr).value(); // what is this syntax ( `[i]` ) called? cout << "Back in the main thread, result is " << i << '\n'; } >output: Hello world! Have an int. Back in the main thread, result is 54 >CMakeLists.txt cmake_minimum_required(VERSION 3.25) project(test_cppref_sched) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++20 -pthread \ -O2 \ -Wall -Wextra -pedantic \ -Wno-unused-parameter" # b/c getting this error in latest stdexec impl ) # download CPM.cmake file( DOWNLOAD https://github.com/cpm-cmake/CPM.cmake/releases/download/v0.40.2/CPM.cmake ${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake SHOW_PROGRESS EXPECTED_HASH SHA256=c8cdc32c03816538ce22781ed72964dc864b2a34a310d3b7104812a5ca2d835d ) include(${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake) CPMAddPackage( NAME stdexec GITHUB_REPOSITORY NVIDIA/stdexec GIT_TAG main # This will always pull the latest code from the `main` branch. ) add_executable(test_cppref_sched main.cpp) target_link_libraries(test_cppref_sched STDEXEC::stdexec) --- 1. https://en.cppreference.com/w/cpp/execution/scheduler >=== -minor edit -add output, cmakelists codeblocks
Edited last time by Chobitsu on 10/09/2024 (Wed) 03:21:44.
>>33930 https://linux.die.net/man/1/bmtoa its in the x11-apps package
>>33932 Thanks! Frankly your power-level is greater IMO. :^)
>>33931 I felt it might be helpful for some, to simplify the Scheduler statement, by moving the embedded lambdas out into named ones: >snippet: // note: no work actually happens here; the compute graph is simply enqueued: // auto hello_work = [] { cout << "Hello world! Have an int.\n"; return 12; }; auto add_work = [](int arg) { return arg + 42; }; // // breaking out the two lambdas into named functions, this call is clearer IMO auto sndr = schedule(ctx.get_scheduler()) | then(hello_work) | then(add_work); Other than breaking out this one compound statment into 3, everything else remains identical. Cheers. :^)
>>33931 Lol, I answered my own question which was staring me in the face, if I'd just hovered over the `i` from within JuCi++ to see it's derived type. It's a C++17 structured binding. [1] // work happens here auto [i] = sync_wait(sndr).value(); // what is this syntax ( `[i]` ) called? // -C++17 structured bindings? (ie [0th] // position; tuple<int> ret from value() --- 1. https://en.cppreference.com/w/cpp/language/structured_binding >=== -fmt, minor edit -add footnote/hotlink
Edited last time by Chobitsu on 10/10/2024 (Thu) 18:11:58.
>>33909 fixed a bunch of stuff, its doing outlines right now and its more usable, dont know if c++ has a better way of doing bit manipulation since it makes the code a mess [code]#include <iostream> #include <wchar.h> #include <locale> #include <stdlib.h> using namespace std; struct bitmap { int w, h; unsigned char *bits; // changed to actual bitmap, read using bitmasks }; class framebuffer { public: unsigned int width; unsigned int height; wchar_t *buffer; int dotn[8] = { 0, 3, 1, 4, 2, 5, 6, 7 }; void init( unsigned int xmax, unsigned int ymax ) { width = xmax; height = ymax; buffer = (wchar_t*) malloc( width * height * sizeof(wchar_t) ); } void clear( void ) { wmemset( buffer, 0x2800, width * height ); } void draw( void ) { for ( int r=0; r < height; r++ ) wprintf( L"%*.*ls\n", width,width, &buffer[ r*width ] ); } void putpixel( unsigned int x, unsigned int y ) { int posx = x/2; int posy = y/4; x %= 2; y %= 4; if ( posx > width || posy > height ) // out of bounds return; wchar_t pixel = buffer[ posy * width + posx ]; pixel -= 0x2800; if ( pixel & ( 1 << dotn[ y*2 + x ] ) ) // already set return; pixel |= 1 << dotn[ y*2 + x ]; pixel += 0x2800; buffer[ posy * width + posx ] = pixel; } void putbitmap( int x, int y, struct bitmap *bmp ) { for ( int yc=0; yc < bmp->h; yc++ ) for ( int xc=0; xc < bmp->w/8; xc++ ) for ( int bit=0; bit < 8; bit++ ) if ( bmp->bits[ yc * (bmp->w/8) + xc ] & (1<<bit) ) putpixel( x + xc*8 + bit, y + yc ); } } FB; struct bitmap *loadfile( const char *filename, unsigned char brightness, unsigned char contrast, int invert ) { FILE *fp = fopen( filename, "r" ); if ( !fp ) wcout << L"! ERROR couldnt open " << filename << L'\n', exit(1); struct Header { unsigned int size; unsigned int x; unsigned int y; unsigned short int planec; unsigned short int depth; unsigned int compression; unsigned int rez; unsigned int xbitc; unsigned int ybitc; unsigned int biClrUsed; unsigned int biClrImportant; } attribute ((packed)) Header; fseek( fp, 14, SEEK_SET ); fread( (char*)&Header.size, 1, sizeof( struct Header ), fp ); fseek( fp, 32*4, SEEK_SET ); // XXX misalignment since my header def is wrong or something if ( Header.depth != 32 ) wcout << L"! ERROR file must be a 32bit .bmp\n" << (wchar_t)0x1F620, exit(2); struct bitmap *bmp = (struct bitmap*) malloc( sizeof(struct bitmap) ); // resize to framebuffer float xscale = ( Header.x > (FB.width *2) ) ? (float)Header.x / (float)(FB.width*2) : 1; float yscale = ( Header.y > (FB.height *4) ) ? (float)Header.y / (float)(FB.height*4) : 1; bmp->w = (float)Header.x / xscale; bmp->h = (float)Header.y / yscale; bmp->bits = (unsigned char*) malloc( (bmp->h) * (1 + bmp->w/8) ); char *file = (char*) malloc( Header.x * Header.y * 32 ); fread( file, 1, Header.x * Header.y * 32, fp ); int32_t prev = 0; int x=0, y=0; for ( float r=Header.y -1; r >= 0; r -= yscale, y++, x=0 ) for ( float c=0; c < Header.x; c += xscale, x++ ) { int check = 0; // check pixel for brightness int32_t pixel = ((int32_t*)file)[ (int)r * Header.x + (int)c ]; unsigned char cur = 0; cur |= ( pixel & (0xff) ); cur |= ( pixel & (0xff<<8) ); cur |= ( pixel & (0xff<<16) ); check = ( cur < brightness ); check ^= invert; // check surounding pixels for contrast unsigned int check2 = 0; for ( int yd=-3; yd<4; yd++ ) // TODO test size should be based on resolution for ( int xd=-3; xd<4; xd++ ) { int y = (int)r + yd; int x = (int)c + xd; if ( ( !yd && !xd ) || // same pixel ( y < 0 || y >= Header.y ) || // out of bounds ( x < 0 || x >= Header.x ) // out of bounds ) continue; int32_t pixel = ((int32_t*)file)[ y * Header.x + x ]; unsigned char near = 0; near |= ( pixel & (0xff) ); near |= ( pixel & (0xff<<8) ); near |= ( pixel & (0xff<<16) ); if ( near > cur ) check2 += ( (near - cur) > contrast ); else check2 += ( (cur - near) > contrast ); } if ( check2 >= 16 ) // invert if in a cluster else outline check = 0; else check |= check2; int bit = x % 8; if ( !bit ) bmp->bits[ y *( bmp->w/8 ) + x/8 ] = 0; if ( check ) bmp->bits[ y *( bmp->w/8) + x/8 ] |= (1 << bit); } free( file ); fclose( fp ); return bmp; } int main( int argc, char **args ) { if ( argc < 2 ) exit(1); setlocale(LC_CTYPE, ""); // defaults unsigned int xmax = 40; // terminal width unsigned int ymax = 20; // terminal height unsigned int brightness = 30; // shading level unsigned int contrast = 20; // contour level unsigned int xrez = xmax * 2; // pixel resolution unsigned int yrez = ymax * 4; // pixel resolution int invert = 0; char *file; for ( int i=1; i<argc; i++ ) { char *arg = *(++args); if ( *arg == '-' ) switch ( *(++arg) ) { case 'r': // set resolution in pixels args++; i++; sscanf( *(args), "%dx%d", &xrez, &yrez ); xmax = xrez / 2; ymax = yrez / 4; break; case 's': // set resolution in chars args++; i++; sscanf( *(args), "%dx%d", &xmax, &ymax ); xrez = xmax * 2; yrez = ymax * 4; break; case 'b': // set brightness level args++; i++; sscanf( *(args), "%d", &brightness ); break; case 'c': // et contrast level args++; i++; sscanf( *(args), "%iu", &contrast ); break; case 'i': // invert shading invert = 1; break; } else file = arg; } FB.init( xmax, ymax ); struct bitmap *pic = loadfile( file, brightness, contrast, invert ); if ( pic ) { FB.clear(); wprintf( L"res: %dx%d\nsize: %dx%d\nb=%d c=%d\n", xrez, yrez, xmax, ymax, brightness, contrast ); FB.putbitmap( 0, 0, pic ); FB.draw(); } return
>>33965 Wow, that's really becoming sophisticated, Anon. Why don't you publish this on a repo now? >dont know if c++ has a better way of doing bit manipulation since it makes the code a mess Most of it's original capability for this is directly derived from C, of course. OTOH, C++ now has intrinsic support for so-called bitfields, bitsets, & vector<bool> 's [1][2][3], so all the benefits of containers (ie, iterators, algorithms, span views, etc.) all come into play there. There are also a fair collection of bit manipulation functions in the numerics library now, too. [4] You might explore those spaces and see if they help you any. Regardless, very cool work, Anon! Grats. :^) --- 1. https://en.cppreference.com/w/cpp/language/bit_field 2. https://en.cppreference.com/w/cpp/utility/bitset 3. https://en.cppreference.com/w/cpp/container/vector_bool 4. https://en.cppreference.com/w/cpp/numeric#Bit_manipulation_.28since_C.2B.2B20.29 >=== -add'l footnotes -prose edit
Edited last time by Chobitsu on 10/11/2024 (Fri) 04:27:29.
Since glowniggers finally destroyed the based Anonfiles a while back (and since that's where the standardized .clang-format file I use was stored to share with the Anons here on /robowaifu/ ), I'll just copypasta the thing directely here. If you want to use it too, then: A. Install clang-format (the tool) B. Copypasta this codeblock into a new file named .clang-format (don't forget the leading dot!) into the base dir where you store all your C++ / C development projects. Then just execute the command: clang-format against any files you want properly formatted to the standard. <---> update: Well, lol. My file won't fit into a single post. Probably why I didn't just post it here last year or so :D I'll find a spot to host it again and link that instead. >=== -add/rm codeblock -add 'update' msg
Edited last time by Chobitsu on 10/15/2024 (Tue) 16:50:01.
Figuring out how to work with C++20 Modules under GCC. This is preparatory to starting up the new C++ Learning Classroom based on PPP3 here at some point : ( >>TBD ; cf. >>19777 , >>31023 ). Since support for modules is still sketchy at best rn for the big three compilers, it can be a bit of a challenge (at least is has been for me, heh :D. But here's an example setup [1] that I got to work, and g++ auto-pre-compiled the so-called '.gcm' file, and placed it in the right spot in the build tree for me. [2][3] >main.cpp import hello; int main() { greeter("world"); } // https://gcc.gnu.org/wiki/cxx-modules >hello_m.cpp module; #include <iostream> #include <string_view> export module hello; export void greeter(std::string_view const& name) { std::cout << "Hello " << name << "!\n"; } >CMakeLists.txt cmake_minimum_required(VERSION 3.5) project(test_gcc_wiki_modules) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++20 -Wall -Wextra -fmodules-ts") add_executable(test_gcc_wiki_modules main.cpp hello_m.cpp) <---> Next I'll try to get working with GCC the four example files Stroustrup gives on his site for modules. I'll post back here with any updates+caveats, etc. Cheers. :^) --- 1. https://gcc.gnu.org/wiki/cxx-modules 2. note: I had to build the project twice; the first time generates the .gcm (and gives errors about no .gcm lol), the second time finds the .gcm and builds the project correctly (and correctly thereafter too). The point being that the .gcm must be present before g++ will fully build successfully at all; but once it's there, then the process works OK. 3. update: Hmm, when compiling this example as shown here on another system with a higher version number of g++ (g++ (GCC) 14.2.1 20240910), this 'compile twice in juCi++ and things just werk' approach didn't pan out. Easy enough two-step fix, but still: A. Go to terminal in the root directory of the project, and run: g++ -std=c++20 -fmodules-ts main.cpp hello_m.cpp B. Then just move the resulting gcm.cache/ directory over into the build/ directory (instead of the project's root), and it works OK inside the IDE thereafter. TBH, this may just be an artifact of my systems. I haven't tested this stuff thoroughly yet. YMMV, Anon. Good luck. :^) >=== -minor edit -code patch -add add'l footnotes
Edited last time by Chobitsu on 10/17/2024 (Thu) 00:29:07.

Report/Delete/Moderation Forms
Delete
Report