Giter Club home page Giter Club logo

Comments (6)

cdeterman avatar cdeterman commented on September 28, 2024

Hi @beibeijiang, can you provide a short, reproducible script of how you are doing this locking and GPU availability detection? Are you just using gpuInfo() and checking the available field? As far as I know, there isn't a way in OpenCL to detect how much RAM is currently available on a GPU (I will need to look around some more to be sure).

from gpur.

beibeiJ avatar beibeiJ commented on September 28, 2024
GPUsetWorkContext <- function(lock.p = "/var/lock/GPU/lock",...){
  ngpu <- detectGPUs()
  gpubusy.count <- 0
  for (i in 1:ngpu) {
    gpulock <- paste(lock.p, i, sep = "")
    if(!file.exists(gpulock)){
      setContext(i)
      file.create(gpulock)
      return(i)
      break
    }
    else
      gpubusy.count <- gpubusy.count + 1
  }
  if(gpubusy.count == ngpu){
    cat("Error: no avaliable resource!\n")
    q(save = "no")
  } 
}

lock.path = "/var/lock/GPU/lock"
#search free gpu and set working gpu
gpuid <- GPUsetWorkContext(lock.p = lock.path)
...# core functions
#finish work, remove the lock file
file.remove(paste(lock.path, gpuid, sep = "")

from gpur.

cdeterman avatar cdeterman commented on September 28, 2024

@beibeijiang I would recommend using a tryCatch statement around whatever process you are using so that if it fails it has an exception handler to remove the 'lock' file. For example, some pseudo-code would look like this:

result = tryCatch({
    # the gpu call
    expr
}, error = function(e) {
    # error handler code
    print(paste0("the following error happend: ", e))
    file.remove(paste(lock.path, gpuid, sep = ""))
}, finally = {
    # cleanup code
    rm(object)
    gc()
    file.remove(paste(lock.path, gpuid, sep = ""))
}

from gpur.

beibeiJ avatar beibeiJ commented on September 28, 2024

@cdeterman Many thanks for your work and help. It works well.
Look forward to your parallel version of gpuR().

from gpur.

cdeterman avatar cdeterman commented on September 28, 2024

@beibeijiang glad it solved your current problem. The parallel version of gpuR is somewhat complicated do to the fact that R itself is not internally thread safe. I think users may be able to use parallel backends like foreach so long as they don't intend to return any gpuR objects such as gpuMatrix/vclMatrix but this requires some further testing. Given this unforeseen complication the parallel version is likely going to be pushed back to either version 1.3.0 or potentially a separate package. I'm still not sure at the moment.

from gpur.

beibeiJ avatar beibeiJ commented on September 28, 2024

@cdeterman I understand. It takes time to figure out the gpuR parallel Currently I could split the input into chunks then submit simple R script into different gpu. It works well. This is also good for running jobs on gpu cluster. I am satisfied with the high performance. You have already made great work. It helps me a lot. Thank you very much.

from gpur.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.