+ Reply to Thread
Page 1 of 3 123 LastLast
Results 1 to 10 of 26

Thread: G3P - The GPU General Graphing Project

  1. #1
    Master of Mars Magos Mechanicus's Avatar
    Join Date
    May 2008
    Posts
    852

    Default G3P - The GPU General Graphing Project

    G3P
    The GPU General Graphing Project
    The GPU General Graphing Project aims to create a system for producing, on the GPU, graphs of arbitrary input functions.
    This thread will be used as a project hub, so will include everything from status reports to help requests to (hopefully) 1 or more releases.
    Any help is very welcome!

    Current status (20/04/2010):
    Function return values work! Time to start writing the GPU.

    Jobs to do/Roadmap:
    1. Write the GPU framework - displaying (graduated?) coordinate axes, function outputs as dlines etc.
    2. Write the GPU components to compute the required input functions and give them to the GPU display portion.
    3. Parsing of infix notation input?
    4. Go 3D?
    5. Port parser+compiler from E2 to CPU?
    Last edited by Magos Mechanicus; 04-20-2010 at 03:36 AM.
    I can wire anything directly into anything! I'm the Professor!
    -Professor Hubert Farnsworth

  2. #2
    Master of Mars Magos Mechanicus's Avatar
    Join Date
    May 2008
    Posts
    852

    Default Re: G3P - The GPU General Graphing Project

    The reason I'm coming to you now is that I'm in a bit of a pickle in terms of getting my E2's machine code to execute and then hand control back to the main program.
    First up, of course: Show the compiler in case that's screwing up.
    Code:
    @name G3P Compiler
    @inputs RPN:string Device:wirelink Offset
    @persist Bytecodes:table Index Compiling:array
    @outputs Compiled:array
    if(~RPN & RPN:length()){Compiled = array(30,4)
        #All functions produced start by popping (30) 
        #the return value off the stack into edx (4)
        #Make sure to push it back on before the ret! (9,4,40)
        Compiling = RPN:explode(" ")
        }
        
    while(Compiling:count()){
        if(minquota()<300){interval(20) break} #Don't run out of quota
        Token = Compiling:shiftString()
        if(Token:toNumber()|Token == "0"){Compiled:pushNumber(9)
        Compiled:pushNumber(0)
        Compiled:pushNumber(Token:toNumber())}
        elseif(Bytecodes[Token,string]){
        Temp = Bytecodes[Token,string]:explode(",")
        while(Temp:count()){Compiled:pushNumber(Temp:shiftString():toNumber())}
        }
        else{print("Compiler error: \"" + Token + "\" is not a recognized token.")}
        #Todo: Finish clause, including pushing the return pointer onto stack
        #Todo: Check for stack safety. Balance between pushes(9) and pops(30)
            #How to exclude values which are not code but the numbers?
            #Check for next value being 1-4?
        #Output to hispeed memory
    }
    if(!Compiling:count()){Compiled:pushNumber(9)
        Compiled:pushNumber(4)
        Compiled:pushNumber(40)
        printTable(Compiled)}
    
    if(first()){
        #Initialize bytecodes for operations
        #General structure of operations: Pop any arguments off stack, do operation, push result back on
        #Numbers: handled at compiletime, except for
        Bytecodes["par",string] = "9,3" #The parameter, which is kept in ecx and can be pushed to stack as needed
        #Operators:
        Bytecodes["+",string] = "30,1,30,2,10,20001,9,1" 
        Bytecodes["-",string] = "30,1,30,2,11,20001,9,1"
        Bytecodes["*",string] = "30,1,30,2,12,20001,9,1"
        Bytecodes["/",string] = "30,1,30,2,14,20001,9,1"
        Bytecodes["^",string] = "30,1,30,2,80,20001,9,1"
        #Functions:
        Bytecodes["sin",string] = "30,1,54,10001,9,1"
        Bytecodes["cos",string] = "30,1,55,10001,9,1"
        Bytecodes["tan",string] = "30,1,57,10001,9,1"
        Bytecodes["asin",string] = "30,1,58,10001,9,1"
        Bytecodes["acos",string] = "30,1,59,10001,9,1"
        Bytecodes["asin",string] = "30,1,58,10001,9,1"
        Bytecodes["log",string] = "30,1,82,10001,9,1" #Natural logarithm
        Bytecodes["log10",string] = "30,1,83,10001,9,1" #Briggs logarithm
        }
    A sample of its output is perhaps also in order. For the input "3 8 * sin 20 *", or in other words the calculation 20*sin(3*8) ~ -18.1, it outputs this machine code:
    Code:
    db 30,4,9,0,3,9,0,8,30,1,30,2,12,20001,9,1,30,1,54,10001,9,1,9,0,20,30,1,30,2,12,20001,9,1,9,4,40
    or, in zASM
    Code:
    pop edx; //Pop the return value for safekeeping
    push 3; //Numbers are simply pushed on
    push 8;
    pop eax;//Operators pop arguments off, then operate on them
    pop ebx;
    mul eax,ebx;
    push eax;//then push results
    pop eax;
    fsin eax,eax;//The same applies for functions
    push eax;
    push 20;
    pop eax;
    pop ebx;
    mul eax,ebx;
    push eax;
    push edx; // And lastly we put the return value back on top
    ret;
    To me, it looks like it should work. then there's trying to get the CPU to execute this, which is much harder.
    My test CPU is this:
    Code:
    // G3P Evaluation test
    main:
    in ecx,0;
    cmp #20000,0;
    je main;
    call 32000;
    pop eax;
    out 0,eax;
    out 1,1;
    jmp main;
    Which steadfastly outputs 0 to its port 0 and 1 no matter how I try to first write the machine code to cell 32000, then a 1 to cell 20000.
    HALP PLOX!

    I'm also very interested in opinions/experience with job 2: Can I actually do the calculation on the GPU, or will it have to be done on a CPU which provides ready made coordinates to dline?
    Last edited by Magos Mechanicus; 04-18-2010 at 01:55 PM.
    I can wire anything directly into anything! I'm the Professor!
    -Professor Hubert Farnsworth

  3. #3
    I think I think too much -HP-'s Avatar
    Join Date
    Feb 2009
    Location
    Behind you with a very sharp knife.
    Posts
    2,466

    Default Re: G3P - The GPU General Graphing Project

    Expression 2 RPN compiler... damn you. I was doing that too :P

  4. #4
    Developer Matte's Avatar
    Join Date
    Jan 2009
    Location
    Norway
    Posts
    3,109

    Default Re: G3P - The GPU General Graphing Project

    If I understood your question right:
    I think, for this project, the GPU would suffice in computing the functions. From my understanding, nothing you're trying to do is too heavy.
    "If anybody says he can think about quantum physics without getting giddy, that only shows he has not understood the first thing about them."
    -- Niels Bohr

  5. #5
    Master of Mars Magos Mechanicus's Avatar
    Join Date
    May 2008
    Posts
    852

    Default Re: G3P - The GPU General Graphing Project

    The main thing worrying me was the client/server divide and lagging people's computers since the GPU executes every frame. I guess there is much that can be done by staggering the computation of the points, though.
    I can wire anything directly into anything! I'm the Professor!
    -Professor Hubert Farnsworth

  6. #6
    Wire Sofaking Hitman271's Avatar
    Join Date
    Feb 2008
    Location
    Why? You looking for somebody?
    Posts
    731

    Default Re: G3P - The GPU General Graphing Project

    haha, I'm actually also working on something like this.

    My parser turns a chat string like this " -27x^3 + 6x - 10" and turns it into an array: ' -27x3, 0x2, 6x1, -10x0" (those zeroes are for the synthetic division)

    I'm using mine to determine the roots using Newton's approximation and synthetic division aswell
    Quote Originally Posted by Anticept View Post
    This is not some place where you can toss your dick around and expect people to suck it.
    Community Gpu Thread. Post Yours!

    Bouncy Ball

  7. #7
    That furred thing Black Phoenix's Avatar
    Join Date
    Feb 2007
    Location
    Kyiv, Ukraine
    Posts
    3,565

    Default Re: G3P - The GPU General Graphing Project

    You can draw function of any complexity (including 3D) if you draw it in blocks - spreading the whole rendering over several frames. You can draw graph with 1000 points if you wish, it'll just take some time. Or surface with 1000 polygons.
    I'm a wire-crazy person with a tail.

    Take a daily journey into my brain

    D2K5

  8. #8
    Master of Mars Magos Mechanicus's Avatar
    Join Date
    May 2008
    Posts
    852

    Default Re: G3P - The GPU General Graphing Project

    Well, a little progress - I've successfully demonstrated that the functions can be called and then return properly. Their return value is not working so well, however. Even
    Code:
    30,4,9,0,3,9,4,40
    i.e.
    pop edx; push 3; push edx; ret;
    somehow manages to return 8.48 instead of 3. Every function regardless of the input ends up doing so. I'll keep plugging away at it.

    Interesting that so many of us started doing this kind of thing simultaneously. Wonder if there was anything that set us all off?
    I can wire anything directly into anything! I'm the Professor!
    -Professor Hubert Farnsworth

  9. #9
    I think I think too much -HP-'s Avatar
    Join Date
    Feb 2009
    Location
    Behind you with a very sharp knife.
    Posts
    2,466

    Default Re: G3P - The GPU General Graphing Project

    Quote Originally Posted by Magos Mechanicus View Post
    Well, a little progress - I've successfully demonstrated that the functions can be called and then return properly. Their return value is not working so well, however. Even
    Code:
    30,4,9,0,3,9,4,40
    i.e.
    pop edx; push 3; push edx; ret;
    somehow manages to return 8.48 instead of 3. Every function regardless of the input ends up doing so. I'll keep plugging away at it.

    Interesting that so many of us started doing this kind of thing simultaneously. Wonder if there was anything that set us all off?
    I thought of it when you posted somewhere something about compiling CPU and how the code works etc. - Even if I already knew it, that put me on the idea. And since I already had an RPN E2 thing, I thought I might give it a shot. But I never really got started, I don't play GMod very much any more.

  10. #10
    Wire Sofaking Fizyk's Avatar
    Join Date
    Jun 2008
    Location
    Łomianki, Poland
    Posts
    740
    Blog Entries
    1

    Default Re: G3P - The GPU General Graphing Project

    I thought once of making a program that would graph functions on a digital screen My approach would be a bit different though - I would make a parser function, that would parse the whole expression for each point to generate table of values, and then graph it. This wouldn't require compiling anything (I made something like that a long time ago in Pascal).

    Quote Originally Posted by Magos Mechanicus
    Well, a little progress - I've successfully demonstrated that the functions can be called and then return properly. Their return value is not working so well, however. Even
    Code:
    30,4,9,0,3,9,4,40
    i.e.
    pop edx; push 3; push edx; ret;
    somehow manages to return 8.48 instead of 3. Every function regardless of the input ends up doing so. I'll keep plugging away at it.
    Try returning values through eax instead of stack, usually it's a better idea.

    My programs: BIOS - Alcyone - Calculator - Notepad - Movie Player
    My tutorials: applyTorque - Quaternions - PID controllers
    Some other things I made: FT Chip - RK4 Solar System

+ Reply to Thread
Page 1 of 3 123 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
proceed-collector
proceed-collector
proceed-collector
proceed-collector
linguistic-parrots
linguistic-parrots
linguistic-parrots
linguistic-parrots