Scripting in Visual Studio: It's Not a Pain in the Ass Actually

2:20 PM

Recently, I ran into a stumbling block with a project and want to share my solution. Even if you're a super-beginner, this will show you how to automate running a program you're working on in Visual Studio. 


This quarter I'm taking a Parallel Programming course. Our 6th project required the use of a GPU to run OpenCL code. The default for our class is to SSH into the professor's Linux server Rabbit, which has a nice beefy graphics card. That stopped being an option when we accidentally killed it. Some of us with a GPU at home were skittish about the idea of running it locally in Visual Studio (me). We were unsure of how to automate running the program hundreds of times in Windows, with the way our skeleton code was set up, so this tutorial is for my CS 475 classmates and for Professor Bailey's poor Rabbit.

Onto the tutorial!

I will be using our Project 6 as an example. We were given some skeleton code to benchmark, so I will show the modifications I made to that, the script I wrote, and how I ran it.

Code Modifications


The code I'm working with is a program to perform benchmark tests on the compute performance of simple calculations using OpenCL with differing values for the global and local work sizes each run. We are supposed to run the program many times with different combinations of these values and analyze the results. The idea is that the GPU is good for running certain things really fast. Understanding OpenCL is not at all needed for this simple tutorial, but if you're curious, here's a little bit more.

Here is the top of the file for the original first.cpp given to us by the professor. In its original form, it looks for variables defined at compile-time: NUM-ELEMENTS, and LOCAL_SIZE. If those are not defined, it sets a default:



I moved the definition of these into main() at the very top. I defined them as command line arguments, with defaults if they do not exist. I shouldn't have them in all-caps, but this was a quick "I want to go to bed" solution.


The basic idea here is that we just need to accept command line arguments!

Build the Solution


Now that the modifications are done, let's compile this thing.
Build->Rebuild in Visual Studio




Now we have an executable. If you want to look at it, open the VS solution from File Explorer, go into the Debug folder, and look for solutionname.exe, in this case mine is first.exe.

This is something we can run from the command line!

The Command Line


Open your command prompt. Hit the windows key and type "cmd". If you want to be lazy, open File Explorer to your solutions folder, and copy the address at the top into your clipboard. Type cd and paste that into cmd.

 cd C:\Users\Sara\Documents\School\Spring18\475\P6\First

This will move us into the directory we need to run our program. In this case, we need a .cl file in the code that sits outside of where the exe file is, so we're not going to cd all the way into the debug folder where the executable is.  To get around that, we're going to run
Debug/first.exe.
This will run the program with the default values. To run it with custom values, run
Debug/first.exe 1024 16
1024 will be assigned to NUM_ELEMENTS, and 16 will be assigned to LOCAL_SIZE

Script

But we want to run this code hundreds of times! On top of that, I'm dyslexic as hell and won't be able to keep track of all the values I want to run the code for. This is where a script comes in! I used bash since I have that installed, but batch files, python or c-shell work just fine.

Here's how it works:
The loops loop through the values that we were asked to run the program with in the assignment. The code will be run for every combination. The command we give it inside the nested loops is to run that executable file, using the current value for t and the current value for s, which are respectively assigned to NUM_ELEMENTS and LOCAL_SIZE.

From this point I started Bash in the command line with bash.exe, which allows me to use the "./" notation. If you don't have Bash on Windows, it's easy to install, or you can use a Batch file. The idea is the same though: run the executable that Visual Studio spits out from your script as many times as you need with whatever variables you need, then use cmd to run your script.

To run the Bash script , simply go back to the command line and run ./scriptname.sh. For example,
./loop.sh
That will handle everything for you! You can get fancy and have output to text handled in your script. I have that sitting in my code itself for now.

Wrapping up

This scripting technique prevents us from having to manually change values, and really cuts down on the time needed to collect our data (and finish the assignment). I hadn't ever played with scripts before this class, and I found them really helpful so I can't wait to poke around with them some more. Big shoutout to my partner for helping me out and showing me some tricks!

Hopefully that was helpful, feel free to ask any questions!




asm

Computer Architecture + Assembly Language Class

10:18 PM

I realized, in the course of posting my recent school projects to my GitHub, that there is nothing here on my blog about the small programs I've made using x86 Assembly! I studied hard to learn it, and have understood higher level languages better in the process. I don't do much for personal reasons with Assembly, but I don't want to neglect the time I spent learning it, so I'd like to give it some love in this post!




I learned some x86 Assembly in the Computer Architecture + Assembly Language course I took in Spring quarter. I found it very fascinating, like a small puzzle. Sometimes I feel like my strength is systems and bigger-picture implementations, so getting into very granular instructions definitely. put me out of my element. Nonetheless, I found it rather fun. Biology was always my best subject in elementary through high school, but studying computer architecture scratched that same itch. It was intensely interesting to get down to the most granular levels and understand the entire system from the ground up. I'm genuinely sad my school doesn't offer advanced architecture courses, I absolutely loved the section we did on digital logic gates!

I'd like to do a writeup for each program I did as part of this class, but in the meantime, here are the ones I've posted to my GitHub!

css

Udemy Web Dev Course, Episode 1

10:45 AM

I decided to take the summer off from school to intern and focus on preparing for Fall quarter. One way I've been doing that is by taking a Web Development course on Udemy. Part of my required curriculum at school is a Web class. After hearing stories of people leaving the class hating Web work because they felt rushed, I decided to front-load my learning as much as possible.



I'm not new to Web Development. I taught myself HTML and CSS in middle school so I could customize my MySpace profile (really), and my last internship involved full-stack development, with a mix of HTML, CSS, JS in the front, and C# and SQL in the back. I built a couple things from the ground up there, which was fun!

I wanted to learn more advanced JS tricks, as well as to un-rust myself and get back some web-related muscle memory. In addition, the Web Development I learned at my last internship was in the ASP.NET framework, and I wanted to expand my horizons beyond that realm ahead of learning it in school. I've always found Web to be enjoyable, so I've been having fun!

The course I selected is pretty comprehensive, so it starts from absolute beginner. Instead of skipping ahead, I've been working through each video and exercise. This is to get my brain used to regularly working with HTML and CSS again, but also to try to pick up a few new tricks, or things I may have missed self-teaching. So far, that strategy has been really effective. 

c++

Sweet Lolita Print Name Generator, Visual C++ Program

5:54 PM



Hello again! This entry is to talk about a simple little "name generator" program I made with Visual C++. You give it some information about you, and it gives you a name. This one is a bit different, though. It's based off the often absurd-yet-endearing names for dresses and collections put out by the Japanese street fashion design house Angelic Pretty. Before I get into the technical details, a little context. Click to continue reading.