001/*
002 * JavaCL - Java API and utilities for OpenCL
003 * http://javacl.googlecode.com/
004 *
005 * Copyright (c) 2009-2013, Olivier Chafik (http://ochafik.com/)
006 * All rights reserved.
007 *
008 * Redistribution and use in source and binary forms, with or without
009 * modification, are permitted provided that the following conditions are met:
010 * 
011 *     * Redistributions of source code must retain the above copyright
012 *       notice, this list of conditions and the following disclaimer.
013 *     * Redistributions in binary form must reproduce the above copyright
014 *       notice, this list of conditions and the following disclaimer in the
015 *       documentation and/or other materials provided with the distribution.
016 *     * Neither the name of Olivier Chafik nor the
017 *       names of its contributors may be used to endorse or promote products
018 *       derived from this software without specific prior written permission.
019 * 
020 * THIS SOFTWARE IS PROVIDED BY OLIVIER CHAFIK AND CONTRIBUTORS ``AS IS'' AND ANY
021 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
022 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
023 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
024 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
025 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
026 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
027 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
028 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
029 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
030 */
031        
032
033
034
035
036        
037
038        
039        
040
041
042
043        
044
045        
046        
047        
048
049        
050package com.nativelibs4java.opencl;
051import org.bridj.*;
052import org.bridj.util.*;
053import java.lang.reflect.Type;
054/**
055 * Size in bytes of a __local argument.
056 */
057public class LocalSize {
058        long size;
059        public LocalSize(long size) {
060                this.size = size;
061        }
062        
063        
064        /**
065         * Returns the size in bytes of an array of int values of the specified length.<br>
066         * @return <code>arrayLength * sizeof(int) = arrayLength * 4</code>
067         */
068        public static LocalSize ofIntArray(long arrayLength) {
069                return new LocalSize(arrayLength * 4);
070        }
071        
072        
073        /**
074         * Returns the size in bytes of an array of long values of the specified length.<br>
075         * @return <code>arrayLength * sizeof(long) = arrayLength * 8</code>
076         */
077        public static LocalSize ofLongArray(long arrayLength) {
078                return new LocalSize(arrayLength * 8);
079        }
080        
081        
082        /**
083         * Returns the size in bytes of an array of short values of the specified length.<br>
084         * @return <code>arrayLength * sizeof(short) = arrayLength * 2</code>
085         */
086        public static LocalSize ofShortArray(long arrayLength) {
087                return new LocalSize(arrayLength * 2);
088        }
089        
090        
091        /**
092         * Returns the size in bytes of an array of byte values of the specified length.<br>
093         * @return <code>arrayLength * sizeof(byte) = arrayLength * 1</code>
094         */
095        public static LocalSize ofByteArray(long arrayLength) {
096                return new LocalSize(arrayLength * 1);
097        }
098        
099        
100        /**
101         * Returns the size in bytes of an array of char values of the specified length.<br>
102         * @return <code>arrayLength * sizeof(char) = arrayLength * 2</code>
103         */
104        public static LocalSize ofCharArray(long arrayLength) {
105                return new LocalSize(arrayLength * 2);
106        }
107        
108        
109        /**
110         * Returns the size in bytes of an array of float values of the specified length.<br>
111         * @return <code>arrayLength * sizeof(float) = arrayLength * 4</code>
112         */
113        public static LocalSize ofFloatArray(long arrayLength) {
114                return new LocalSize(arrayLength * 4);
115        }
116        
117        
118        /**
119         * Returns the size in bytes of an array of double values of the specified length.<br>
120         * @return <code>arrayLength * sizeof(double) = arrayLength * 8</code>
121         */
122        public static LocalSize ofDoubleArray(long arrayLength) {
123                return new LocalSize(arrayLength * 8);
124        }
125        
126                
127        /**
128         * Returns the size in bytes of an array of T values of the specified length.<br>
129         */
130        public static LocalSize ofArray(long arrayLength, Type componentType) {
131                PointerIO io = PointerIO.getInstance(componentType);
132                if (io == null)
133                        throw new RuntimeException("Unsupported type : " + Utils.toString(componentType));
134                return new LocalSize(arrayLength * io.getTargetSize());
135        }
136}