takagi / cl-cuda

Cl-cuda is a library to use NVIDIA CUDA in Common Lisp programs.
MIT License
279 stars 24 forks source link

to be accepted in Quicklisp distribution #31

Open takagi opened 10 years ago

takagi commented 10 years ago

Currently, cl-cuda is not available in Quicklisp distribution because of its testing policy (see #514 in quicklisp-projects).

It may be accepted if it just finished to be compiled without condition on an environment where CUDA SDK is not installed even though it does not work.

Approach:

  1. try to compile grovel files which include cuda.h before evaluate the defsystem form in cl-cuda.asd
  2. a condition would be signaled since CUDA SDK is not installed
  3. handle the condition and push a flag to *features* which mentions CUDA SDK is not installed
  4. in the defsystem form, avoid cffi-grovel:grovel-file form to be evaluated by looking *features*

Quetions:

melisgl commented 10 years ago

Pushing to FEATURES\ may not interact well with saved images or executables whose runtime environment can vary.

takagi commented 10 years ago

Thanks. I will take it into account.

takagi commented 9 years ago

Following shows how to determine CUDA SDK is already installed or not.

Goal Determining that CUDA SDK is already installed or not.

Approach Processing a CFFI-Grovel specification file without defsystem forms and handling a condition signaled.

Detail Put a CFFI-Grovel specification file foo.lisp containing following contents in cl-cuda system's directory.

(include "cuda.h")

Evaluate the following form to process the CFFI-Grovel specification file.

(asdf:perform
  (make-instance 'cffi-grovel::process-op)
  (make-instance 'cffi-grovel::grovel-file :pathname "foo"
                                           :parent (asdf:find-system "cl-cuda")))

As the result, if CUDA SDK is not installed, the following condition is signaled.

External process exited with code 1.
Command was: "cc" "-m64" "-I" "/opt/local/include/" "-I/Users/mtakagi/Lisp/quicklisp/dists/quicklisp/so..." "-o" "/Users/mtakagi/.cache/common-lisp/sbcl-1.0.55-maco..." "/Users/mtakagi/.cache/common-lisp/sbcl-1.0.55-maco..."
Output was:
/Users/mtakagi/.cache/common-lisp/sbcl-1.0.55-macosx-x64/Users/mtakagi/Lisp/cl-cuda/foo.c:6:10: fatal error: 'cud.h' file not found
#include <cuda.h>
         ^
1 error generated.

   [Condition of type SIMPLE-ERROR]

It can be determined that CUDA SDK is installed or not, although some false negatives remained that the compiler can not find cuda.h file because of some reasons such as appropriate environment variables are not specified.

Problems

guicho271828 commented 9 years ago

how about subclassing cffi-grovel::grovel-file (e.g. cuda-header) and make it have the :around method that handles the error? well, I'm not concerned with cl-cuda, but responding just on curiosity.

takagi commented 9 years ago

What you mean is something like this?

(defclass cuda-header (cffi-grovel:grovel-file) ())

(defmethod asdf:perform :around ((op cffi-grovel::process-op) (c cuda-header))
  (handler-case (call-next-method op c)
    (error (lambda (c) (handle-the-error))))

It would be nice.

takagi commented 9 years ago

Following shows consideration on guicho271828's suggestion.

Goal To finish cl-cuda to be loaded without any conditions on environments where CUDA SDK is not installed even though it does not work.

Approach Subclassing cffi-grovel:grovel-file with an :around method that handles the condition causing if CUDA SDK is not installed.

(defclass cuda-grovel-file (cffi-grovel:grovel-file) ())

(defmethod asdf:perform :around ((op cffi-grovel::process-op) (c cuda-grovel-file))
  (handler-case (call-next-method op c)
    (error (e))))

Then, use the following ASDF components in cl-cuda's defsystem form.

(cuda-grovel-file "type-grovel")
(cuda-grovel-file "enum-grovel")

Result Cl-cuda is finished to be loaded without causing any conditions.

Problems

melisgl commented 9 years ago

Very cool. I hope it's enough for quicklisp.

takagi commented 9 years ago

I rewrite the result and problems on my previous comment.

takagi commented 9 years ago

For resolving undefined symbols, I will define them in working around for the case cuda.h not found. Additionally, I will modify to use grovel only for architecture depending types: CUdeviceptr and size_t.

takagi commented 9 years ago

Another context, I asked Quicklisp again because I found this IRC log and guess he thinks a physical board is required for just building cl-cuda.

https://github.com/quicklisp/quicklisp-projects/issues/514