Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Working on Min -> Minimum rename.

I plan to release this to CPAN under CUDA::Minimal, not CUDA::Min,
since, as Chris Marshall pointed out, CUDA::Min could be ambiguous.
I am in the middle of this work, though, and I have not tested it.
  • Loading branch information...
commit 64d3b84d5fad524581ba23965f84dea566147498 1 parent 801ef1e
David Mertens run4flat authored
4 Build.PL
... ... @@ -1,6 +1,6 @@
1 1 use Module::Build;
2 2 my $build = Module::Build->new(
3   - module_name => 'CUDA::Min',
  3 + module_name => 'CUDA::Minimal',
4 4 license => 'perl',
5 5 build_requires => {
6 6 'ExtUtils::nvcc' => '0.01',
@@ -10,7 +10,7 @@ my $build = Module::Build->new(
10 10 'perl' => '0',
11 11 },
12 12 dist_author => 'David Mertens <dcmertens.perl@gmail.com>',
13   - config => {cc => 'perl_nvcc', ld => 'perl_nvcc'},
  13 + config => {ExtUtils::nvcc::MB},
14 14 include_dirs => '.',
15 15 );
16 16
8 MANIFEST
... ... @@ -1,8 +1,8 @@
1 1 Build.PL
2   -lib/CUDA/Min.pm
3   -lib/CUDA/Min.xs
4   -lib/CUDA/Min/Tests.pm
5   -lib/CUDA/Min/Tests.xs
  2 +lib/CUDA/Minimal.pm
  3 +lib/CUDA/Minimal.xs
  4 +lib/CUDA/Minimal/Tests.pm
  5 +lib/CUDA/Minimal/Tests.xs
6 6 MANIFEST This list of files
7 7 mytest.pl
8 8 ppport.h
4 README
... ... @@ -1,5 +1,5 @@
1   -CUDA-Min version 0.01
2   -=====================
  1 +CUDA-Minimal version 0.01
  2 +=========================
3 3
4 4 The README is used to introduce the module and provide instructions on
5 5 how to install the module, any machine dependencies it may have (for
32 lib/CUDA/Min.pm → lib/CUDA/Minimal.pm
... ... @@ -1,4 +1,4 @@
1   -package CUDA::Min;
  1 +package CUDA::Minimal;
2 2
3 3 use 5.010001;
4 4 use strict;
@@ -39,11 +39,11 @@ sub is_an_object ($) {
39 39
40 40 =head1 NAME
41 41
42   -CUDA::Min - A minimal set of Perl bindings for CUDA.
  42 +CUDA::Minimal - A minimal set of Perl bindings for CUDA.
43 43
44 44 =head1 SYNOPSIS
45 45
46   - use CUDA::Min;
  46 + use CUDA::Minimal;
47 47 # Create a host-side array of 10 sequential
48 48 # single-precision floating-point values:
49 49 my $N_values = 10;
@@ -105,7 +105,7 @@ CUDA::Min - A minimal set of Perl bindings for CUDA.
105 105
106 106 # The order of inclusion is not important:
107 107 use PDL;
108   - use CUDA::Min;
  108 + use CUDA::Minimal;
109 109 use PDL::NiceSlice;
110 110
111 111 # Create a double array of 20 sequential elements:
@@ -287,7 +287,7 @@ is CUDA's reason, not mine.)
287 287
288 288 Usage example:
289 289
290   - use CUDA::Min;
  290 + use CUDA::Minimal;
291 291 my $data = pack('f*', 1..10);
292 292 my $dev_input_ptr = MallocFrom($data);
293 293 my $dev_output_ptr = Malloc($data);
@@ -876,7 +876,7 @@ sub ThereAreCudaErrors () {
876 876 }
877 877
878 878 require XSLoader;
879   -XSLoader::load('CUDA::Min', $VERSION);
  879 +XSLoader::load('CUDA::Minimal', $VERSION);
880 880
881 881 ##############################
882 882 # OBJECT ORIENTED INTERFACES #
@@ -886,7 +886,7 @@ XSLoader::load('CUDA::Min', $VERSION);
886 886
887 887 The documentation made many references to objects that mimic device or host
888 888 memory. Objects that 'mimic' device or host memory have a handful of methods
889   -that C<CUDA::Min> expects to be able to call on them.
  889 +that C<CUDA::Minimal> expects to be able to call on them.
890 890
891 891 =head2 Host memory
892 892
@@ -952,7 +952,7 @@ or nothing at all.
952 952
953 953 =head1 PDL METHODS
954 954
955   -As an illustration of an object-oriented interface, CUDA::Min supports using
  955 +As an illustration of an object-oriented interface, CUDA::Minimal supports using
956 956 piddles in its arguments. It provides two
957 957 PDL methods for data transfer, L</send_to> and L</get_from>, and another method
958 958 for getting and setting the number of bytes, L</nbytes>. Both of the transfer
@@ -1343,22 +1343,22 @@ functions exported if you wish.
1343 1343 If you're a purist and don't want anything in your current package, there's
1344 1344 nothing stopping you from saying
1345 1345
1346   - use CUDA::Min '';
  1346 + use CUDA::Minimal '';
1347 1347
1348 1348 which won't import anything. If you only want one or two functions, you can
1349 1349 get at them with their fully-qualified name, like this:
1350 1350
1351   - my $error_string = CUDA::Min::GetLastError;
  1351 + my $error_string = CUDA::Minimal::GetLastError;
1352 1352
1353 1353 or you can import specific functions by name:
1354 1354
1355   - use CUDA::Min qw(GetLastError);
  1355 + use CUDA::Minimal qw(GetLastError);
1356 1356
1357 1357 =head2 Memory functions
1358 1358
1359 1359 You can export the memory-related functions using the C<:memory> tag, like so:
1360 1360
1361   - use CUDA::Min qw(:memory);
  1361 + use CUDA::Minimal qw(:memory);
1362 1362
1363 1363 That will make L</Malloc>, L</MallocFrom>, L</Transfer>, and L</Free> available.
1364 1364
@@ -1368,15 +1368,15 @@ Suppose you have some module that invokes various CUDA stuff for you. It handles
1368 1368 all of the memory internally. If you want to benchmark that code, you will
1369 1369 want L</ThreadSynchronize>, which you get by either of the following:
1370 1370
1371   - use CUDA::Min ':sync';
1372   - use CUDA::Min 'ThreadSynchronize';
  1371 + use CUDA::Minimal ':sync';
  1372 + use CUDA::Minimal 'ThreadSynchronize';
1373 1373
1374 1374 =head2 Error functions
1375 1375
1376 1376 If you want to have access to the error-handling functions L</GetLastError>
1377 1377 and L</ThereAreCudaErrors>, you can use the C<:error> tag:
1378 1378
1379   - use CUDA::Min qw(:error);
  1379 + use CUDA::Minimal qw(:error);
1380 1380
1381 1381 =head2 Utility functions
1382 1382
@@ -1384,7 +1384,7 @@ The functions for setting the size of host memory or determining the size of
1384 1384 an allocation are L</SetSize> and L</Sizeof>. You can import those using the
1385 1385 C<:util> tag:
1386 1386
1387   - use CUDA::Min ':util';
  1387 + use CUDA::Minimal ':util';
1388 1388
1389 1389 =head1 TODO
1390 1390
2  lib/CUDA/Min.xs → lib/CUDA/Minimal.xs
@@ -4,7 +4,7 @@
4 4
5 5 #include "ppport.h"
6 6
7   -MODULE = CUDA::Min PACKAGE = CUDA::Min
  7 +MODULE = CUDA::Minimal PACKAGE = CUDA::Minimal
8 8
9 9 void
10 10 _free(SV * dev_ptr_SV)
12 lib/CUDA/Min/Tests.pm → lib/CUDA/Minimal/Tests.pm
... ... @@ -1,16 +1,16 @@
1 1 =head1 NAME
2 2
3   -CUDA::Min::Tests - a collection of tests for CUDA::Min.
  3 +CUDA::Minimal::Tests - a collection of tests for CUDA::Minimal.
4 4
5 5 =head1 USAGE
6 6
7   -This provides a couple of CUDA kernels used in the CUDA::Min test suite.
  7 +This provides a couple of CUDA kernels used in the CUDA::Minimal test suite.
8 8 You probably won't have need for any of these, unless you want to take a look at
9 9 the XS code in Test.xs for an idea of how to wrap CUDA kernel calls.
10 10
11 11 =head1 COPYRIGHT AND LICENSE
12 12
13   -Copyright (C) 2010 by David Mertens
  13 +Copyright (C) 2010, 2011 by David Mertens
14 14
15 15 This library is free software; you can redistribute it and/or modify
16 16 it under the same terms as Perl itself, either Perl version 5.10.1 or,
@@ -18,7 +18,7 @@ at your option, any later version of Perl 5 you may have available.
18 18
19 19 =cut
20 20
21   -package CUDA::Min::Tests;
  21 +package CUDA::Minimal::Tests;
22 22
23 23 use 5.010001;
24 24 use strict;
@@ -30,9 +30,9 @@ BEGIN {
30 30 our $VERSION = '0.01';
31 31
32 32 require XSLoader;
33   -XSLoader::load('CUDA::Min::Tests', $VERSION);
  33 +XSLoader::load('CUDA::Minimal::Tests', $VERSION);
34 34
35   -use CUDA::Min;
  35 +use CUDA::Minimal;
36 36 use Carp 'croak';
37 37
38 38 #####################
10 lib/CUDA/Min/Tests.xs → lib/CUDA/Minimal/Tests.xs
@@ -2,6 +2,8 @@
2 2 #include "perl.h"
3 3 #include "XSUB.h"
4 4
  5 +// See Tests.pm for the associated copyright and license details.
  6 +
5 7 #include "ppport.h"
6 8
7 9 //////////////////////////////////
@@ -20,7 +22,7 @@
20 22 #define N_LAYERS 8
21 23
22 24 // This is part of a hack prevent the BOOT section from being included in
23   -// Min.xs's boot section, an error I do not understand at all:
  25 +// Minimum.xs's boot section, an error I do not understand at all:
24 26 #define TESTS_BOOT
25 27
26 28 /////////////////
@@ -206,19 +208,19 @@ float divide_and_conquer_sum (float * data, int length) {
206 208 + divide_and_conquer_sum(data + length, length));
207 209 }
208 210
209   -MODULE = CUDA::Min::Tests PACKAGE = CUDA::Min::Tests
  211 +MODULE = CUDA::Minimal::Tests PACKAGE = CUDA::Minimal::Tests
210 212
211 213 ########################
212 214 # Export the constants #
213 215 ########################
214 216
215 217 BOOT:
216   -// This boot seciton does NOT belong in Min.c, but it somehow ends up there
  218 +// This boot seciton does NOT belong in Minimal.c, but it somehow ends up there
217 219 // anyway! This #ifdef prevents stupidity from happening:
218 220 #ifdef TESTS_BOOT
219 221 # Add the preprocessor constants to the namespace:
220 222 HV * stash;
221   - stash = gv_stashpv("CUDA::Min::Tests", TRUE);
  223 + stash = gv_stashpv("CUDA::Minimal::Tests", TRUE);
222 224 newCONSTSUB(stash, "N_THREADS", newSViv( N_THREADS ));
223 225 newCONSTSUB(stash, "MIN_PER_BLOCK", newSViv( MIN_PER_BLOCK ));
224 226 newCONSTSUB(stash, "N_LAYERS", newSViv( N_LAYERS ));
2  mytest.pl
@@ -2,7 +2,7 @@
2 2 use strict;
3 3 use warnings;
4 4 use blib;
5   -use CUDA::Min;
  5 +use CUDA::Minimal;
6 6 use feature 'say';
7 7
8 8 SetSize(my $test_scalar, Sizeof(f => 30));
4 t/00_load.t
@@ -2,7 +2,7 @@
2 2
3 3 use Test::More tests => 2;
4 4
5   -use_ok('CUDA::Min');
6   -use_ok('CUDA::Min::Tests');
  5 +use_ok('CUDA::Minimal');
  6 +use_ok('CUDA::Minimal::Tests');
7 7
8 8
2  t/Index-Manipulation.t
... ... @@ -1,7 +1,7 @@
1 1 # A set of tests for the index manipulation functions.
2 2
3 3 use Test::More tests => 7;
4   -use CUDA::Min;
  4 +use CUDA::Minimal;
5 5
6 6 # Check that Sizeof computes values correctly, and croaks on bad input:
7 7 ok(Sizeof(c => 20) == 20, "20 chars take 20 bytes");
2  t/Memory.t
... ... @@ -1,7 +1,7 @@
1 1 # A collection of tests for the memory functions
2 2
3 3 use Test::More tests => 8;
4   -use CUDA::Min;
  4 +use CUDA::Minimal;
5 5 use strict;
6 6 use warnings;
7 7
2  t/Transfer.t
... ... @@ -1,7 +1,7 @@
1 1 # A collection of tests for the Transfer function
2 2
3 3 use Test::More tests => 21;
4   -use CUDA::Min;
  4 +use CUDA::Minimal;
5 5 use strict;
6 6 use warnings;
7 7
12 t/z_PDL.t
... ... @@ -1,9 +1,9 @@
1   -# Tests for the PDL functionality of CUDA::Min
  1 +# Tests for the PDL functionality of CUDA::Minimal
2 2
3 3 use strict;
4 4 use warnings;
5 5 use Test::More;
6   -use CUDA::Min;
  6 +use CUDA::Minimal;
7 7
8 8 # Put this in a begin block so that I don't get to the NiceSlice include
9 9 # if PDL is not on their machine.
@@ -24,9 +24,9 @@ use PDL::NiceSlice;
24 24
25 25 my $data = sequence(50);
26 26 my $slice = $data(0:9);
27   -ok(CUDA::Min::_piddle_is_mmap_or_slice($slice),
  27 +ok(CUDA::Minimal::_piddle_is_mmap_or_slice($slice),
28 28 "Utility function correctly identifies slice");
29   -ok(!CUDA::Min::_piddle_is_mmap_or_slice($data),
  29 +ok(!CUDA::Minimal::_piddle_is_mmap_or_slice($data),
30 30 "Utility function correctly identifies non-slice");
31 31
32 32 use PDL::IO::FastRaw;
@@ -37,7 +37,7 @@ SKIP:
37 37 {
38 38 my $mmap = eval {mapfraw $test_fname};
39 39 skip('because PDL does not support mmap for your system', 1) if $@;
40   - ok(CUDA::Min::_piddle_is_mmap_or_slice($mmap),
  40 + ok(CUDA::Minimal::_piddle_is_mmap_or_slice($mmap),
41 41 "Utility function correctly identifies mmap");
42 42 }
43 43
@@ -55,7 +55,7 @@ $results(0:9) .= -1;
55 55 ok(all($data == $results), 'Direct data updates work');
56 56
57 57 # Data should still not be considered a slice
58   -ok(!CUDA::Min::_piddle_is_mmap_or_slice($data),
  58 +ok(!CUDA::Minimal::_piddle_is_mmap_or_slice($data),
59 59 "Utility function still correctly identifies non-slice");
60 60
61 61
28 t/z_kernel_invocations.t
@@ -2,10 +2,10 @@ use Test::More tests => 25;
2 2
3 3 # This file starts with z_ to ensure that it runs last.
4 4
5   -# Load CUDA::Min::Tests, which provides functions to facilitate testing
  5 +# Load CUDA::Minimal::Tests, which provides functions to facilitate testing
6 6 # kernel invocations:
7   -use CUDA::Min;
8   -use CUDA::Min::Tests;
  7 +use CUDA::Minimal;
  8 +use CUDA::Minimal::Tests;
9 9
10 10 use strict;
11 11 use warnings;
@@ -16,7 +16,7 @@ is($string, 'no error', "With no error, GetLastError should return 'no error'");
16 16 ok(not (ThereAreCudaErrors), 'ThereAreCudaErrors should return false when there are none');
17 17 ok($@ eq '', 'ThereAreCudaErrors does not set $@ when there are no problems');
18 18 # Make sure the kernel that's supposed to always succeed does, in fact, succeed:
19   -CUDA::Min::Tests::succeed_test();
  19 +CUDA::Minimal::Tests::succeed_test();
20 20 ok(not (defined ThereAreCudaErrors), 'succeed_test does not set a CUDA error');
21 21
22 22 # Create a collection of values to sum and copy them to the device:
@@ -26,7 +26,7 @@ my $dev_ptr = MallocFrom($host_array);
26 26
27 27 # Run the multiply kernel; copy back 10 random values and make sure they are
28 28 # what they are supposed to be:
29   -CUDA::Min::Tests::cuda_multiply_by_constant($dev_ptr, $N_elements, 4);
  29 +CUDA::Minimal::Tests::cuda_multiply_by_constant($dev_ptr, $N_elements, 4);
30 30 my $test_val = pack 'f', 1;
31 31 for (1..10) {
32 32 my $offset = int rand $N_elements;
@@ -35,11 +35,11 @@ for (1..10) {
35 35 }
36 36
37 37 # Return the values to their original state:
38   -CUDA::Min::Tests::cuda_multiply_by_constant($dev_ptr, $N_elements, 0.25);
  38 +CUDA::Minimal::Tests::cuda_multiply_by_constant($dev_ptr, $N_elements, 0.25);
39 39
40 40 # Test the sum:
41   -CUDA::Min::Tests::sum_reduce_test($host_array, $dev_ptr, 'a single block');
42   -CUDA::Min::Tests::sum_reduce_test($host_array, $dev_ptr, '32 blocks', 32);
  41 +CUDA::Minimal::Tests::sum_reduce_test($host_array, $dev_ptr, 'a single block');
  42 +CUDA::Minimal::Tests::sum_reduce_test($host_array, $dev_ptr, '32 blocks', 32);
43 43
44 44 # Free the current device memory before moving forward:
45 45 Free($dev_ptr);
@@ -47,9 +47,9 @@ Free($dev_ptr);
47 47 # Now I'm going to try a nontrivial sum of 65536 floats:
48 48 $host_array = pack 'f*', map {sin ($_/10)} 1..65536;
49 49 $dev_ptr = MallocFrom($host_array);
50   -CUDA::Min::Tests::sum_reduce_test($host_array, $dev_ptr, 'single block sine-sum');
51   -CUDA::Min::Tests::sum_reduce_test($host_array, $dev_ptr, '32 block sine-sum', 32);
52   -CUDA::Min::Tests::sum_reduce_test($host_array, $dev_ptr, '1024,32 block sine-sum', 1024, 32);
  50 +CUDA::Minimal::Tests::sum_reduce_test($host_array, $dev_ptr, 'single block sine-sum');
  51 +CUDA::Minimal::Tests::sum_reduce_test($host_array, $dev_ptr, '32 block sine-sum', 32);
  52 +CUDA::Minimal::Tests::sum_reduce_test($host_array, $dev_ptr, '1024,32 block sine-sum', 1024, 32);
53 53
54 54 # Don't forget to clean up:
55 55 Free($dev_ptr);
@@ -64,7 +64,7 @@ Free($dev_ptr);
64 64 # GetLastError and the documentation should be updated accordingly.
65 65
66 66 # Run the kernel that is supposed to fail and see what we get:
67   -CUDA::Min::Tests::fail_test();
  67 +CUDA::Minimal::Tests::fail_test();
68 68 ThreadSynchronize();
69 69 ok(ThereAreCudaErrors, "ThereAreCudaErrors returns a true value when an error occurs");
70 70 # Check that ThereAreCudaErrors sets $@
@@ -76,13 +76,13 @@ $@ = '';
76 76 ok(not (defined ThereAreCudaErrors), "ThereAreCudaErrors clears the last error");
77 77
78 78 # Check that the next kernel invocation trips an error
79   -CUDA::Min::Tests::succeed_test();
  79 +CUDA::Minimal::Tests::succeed_test();
80 80 ok(ThereAreCudaErrors, "Good kernels invoked after a failed kernel launch also fail");
81 81 like($@, qr/unspecified/, 'ThereAreCudaErrors properly sets $@ on error');
82 82 $@ = '';
83 83
84 84 # Check the return value of GetLastError:
85   -CUDA::Min::Tests::succeed_test();
  85 +CUDA::Minimal::Tests::succeed_test();
86 86 like(GetLastError, qr/unspecified/, 'Further kernel invocations return an unspecified launch failure');
87 87
88 88

0 comments on commit 64d3b84

Please sign in to comment.
Something went wrong with that request. Please try again.