SPO600 (Project Part 3.0)

For the final version of the program refer to here https://github.com/a-martin94/Spo600 
If the link is broken go here                                   https://github.com/a-martin94/Spo600

For Project details including test code go to here:  https://wiki.cdot.senecacollege.ca/wiki/Fall_2022_SPO600_Project

In Order to run the code: 

You can clone my repo at my get hub posted above, just make sure you have VS code preferable to new users or you can use vim if you clone it to a dir in a cmd line in gitbash. I Would just simply get VS code install python got to git hub and just drag and drop the files or copy them its not a huge project so dont really need to do a git clone, any ways after you have it all just go to the file path in the cmd line or what ever your working on and type "python test.py" and it will run the code.

Important (For not just void use this example and instructions)

This code will work with more then just a void function, If you go to function.c and change void to bool or int or the 6 i covered you can make it in ISREAL just don't run the makefile after the change. In order to make this change the program I made a new header called helpers.py tool that is just a simple loop that takes in two arguments. here is my loop in helpers.py

import re

def whichOne(line, dataTypes):
   
    for i in range(len(dataTypes)):
        if re.search("^" + dataTypes[i] + ".", line):
            return i

    return -1






[amartin35@israel project]$ python test.py
bool
bool adjust_channels(unsigned char *image, int x_size, int y_size,float red_factor, float green_factor, float blue_factor)
[amartin35@israel project]$ 

picture was small so that's the output when changed to bool



I will post My tool in another post as its under 100 lines(Incase git hub did not work at the top part 3.1).

For the final portion of this project I was able to make some final strides to complete the necessary requirements in order to complete the task. I wrote the tool in python and it was a fun challenge and truly showed me and how python is such a great tool for parsing. For the task I really just took the function.c file and busted it up using my tool.py, When I had the string parsed it was just a matter of finding and replacing like I had done in C++ but a lot more friendly given the tools at hand in python. Once I had stripped what I had needed for the function prototype I then stored that string and was able to store that string and manipulate it. After I had the function prototype down I then moved on to the sve,sve2 and asmid suffix task of this project. There where a few different ways to go about this but I just Created an array with with names, and then did a for in range of my count which was 3 and simply looped through and added the suffix's. Next I had to add the pragma targets which was very similar to the previous step and i used the same loop to achieve  this. I had to file open and file close a few times in order to write to the proper file names for the task at hand. In order to get the resolver function to the bottom of the file after writing the 3 functions to the file, I ended up creating a resolver.c file so I could open it in my tool and extract the content. After the looping where I used the loop to add the suffix I noticed in my Ifunc file that I could just simply copy it to the bottom of that ifunc file. So after I got the content from the resolver.c i then simple open and wrote to ifunc.c.

After the tool was built and it was working on my local machine it was time to start testing it on the Israel server which is aarch66. I liked that Chris showed us how to connect the ssh extension in VS code to Israel so it was easy to work with. Now when it was on Israel I had a hard time trying to get the makefile to work. Now a lot of this was because of me not having the main file and the right target in my make file and some other mistakes like not having GCC in front of target. For the makefile I had to contact my professor for a bit of help.

Here is my main parsing tool that busted up the start and stored in orgline

for line in f:
    count = count + 1
    a = line.strip()
    iDataType = helpers.whichOne(a, dataTypes)
    if  iDataType != -1:
        orgLine = a
        dataType = re.split("\s", a, 1)
        print(dataType[0])
        name = re.split("\(", dataType[1], 1)
        #print("Name of func is " + name[0])

        nextLine = f.readline()

        while not re.search(".{.?", nextLine):
            orgLine += nextLine.strip() + " "
            nextLine = f.readline()  
     
        l = re.split(".{.?", nextLine, 1)
        orgLine += l[0].strip()
        print(orgLine)
        a = ""
        break

Next This is where the two arrays and how I got the lines under the prototype

typeCount = 3
# suffix for each function
types = ["sve2", "sve", "asimd"]
targets = ["#pragma GCC target \"arch=armv8-a+sve2\"", "#pragma GCC target \"arch=armv8-a+sve\"", "#pragma GCC target \"arch=armv8-a\""]

bustedUp = re.split("\(", orgLine, 1)
paramList = "(" + bustedUp[1]
#lineToInsert = dataType[0] + " " + name[0] + paramList + "\n"
lineToInsert = ""
# get all lines under prototype of function
for line in f:
    bottomPart += line

My for logic in order to loop through and the suffix and target

for x in range(typeCount):
    lineToInsert += targets[x] + "\n\n"
    lineToInsert += topPart + "\n\n"
    lineToInsert += dataType[0] + " " + name[0] + "_" + types[x] +  paramList + "{"+ "\n"
    content += "\n" + lineToInsert + bottomPart
    content += "\n\n\n"
    lineToInsert = ""


and how I got the resolver to be added last

output.write(content)
output.close()

f = open("resolver.c", "r")
output = open(fileName, "a")
content =""
for line in f :
    content += line


output.write(content)
f.close()
output.close()

This is the out put that we want in yellow green is just a test of the bool again.

***The pictures are coming up to small***


[amartin35@israel project]$ python test.py
bool
bool adjust_channels(unsigned char *image, int x_size, int y_size,float red_factor, float green_factor, float blue_factor)
[amartin35@israel project]$ python test.py
void
void adjust_channels(unsigned char *image, int x_size, int y_size,float red_factor, float green_factor, float blue_factor)
[amartin35@israel project]$ ls
adjust_channels.h  function.c  function_ifunc.c  helpers.py  main  main.c  Makefile  __pycache__  resolver.c  test.py  tests
[amartin35@israel project]$ make
gcc  main.c function_ifunc.c -o main
echo "Making and testing all versions..."
Making and testing all versions...
./main tests/input/bree.jpg 1.0 1.0 1.0 tests/output/bree1a.jpg

****** OUTPUT *******************************************
### Resolver function - selecting the implementation to use for  foo()
File 'tests/input/bree.jpg' loaded: 358x400 pixels, 3 bytes per pixel.
Adjustments:    red: 1.000000   green: 1.000000   blue: 1.000000
./main tests/input/bree.jpg 0.5 0.5 0.5 tests/output/bree1b.jpg

### Resolver function - selecting the implementation to use for  foo()
File 'tests/input/bree.jpg' loaded: 358x400 pixels, 3 bytes per pixel.
Adjustments:    red: 0.500000   green: 0.500000   blue: 0.500000
./main tests/input/bree.jpg 2.0 2.0 2.0 tests/output/bree1c.jpg

### Resolver function - selecting the implementation to use for  foo()
File 'tests/input/bree.jpg' loaded: 358x400 pixels, 3 bytes per pixel.
Adjustments:    red: 2.000000   green: 2.000000   blue: 2.000000
[amartin35@israel project]$ 



Comments

Popular posts from this blog

SPO600 Lab1

SPO600(Project 3.2 FInal Post and thoughts on project and course)

SPO600(Project Part 2.1)