public CudnnTensorDescriptorParameters(CudnnType type, CudnnTensorFormat format, int n, int c, int h, int w)
        {
            if (n < 1 || c < 1 || h < 1 || w < 1)
            {
                throw new ArgumentException("At least one of the parameters n, c, h, w was negative.");
            }

            this.Type = type;

            this.Num      = n;
            this.Channels = c;
            this.Height   = h;
            this.Width    = w;

            this.NumStride = h * w * c;

            if (format == CudnnTensorFormat.MajorRow)
            {
                this.ChannelsStride = h * w;
                this.HeightStride   = w;
                this.WidthStride    = 1;
            }
            else
            {
                this.ChannelsStride = 1;
                this.HeightStride   = w * c;
                this.WidthStride    = c;
            }
        }
Ejemplo n.º 2
0
 public static extern CudnnStatus cudnnSetTensor4dDescriptor(CudnnTensorDescriptorHandle tensorDesc,
                                                             CudnnTensorFormat format,
                                                             CudnnType dataType,    // image data type
                                                             int n,                 // number of inputs (batch size)
                                                             int c,                 // number of input feature maps
                                                             int h,                 // height of input section
                                                             int w);                // width of input section
Ejemplo n.º 3
0
 public static extern CudnnStatus cudnnGetFilterDescriptor(CudnnFilterDescriptorHandle filterDescriptor,
                                                           out CudnnType dataType,   // image data type
                                                           out int k,                // number of output feature maps
                                                           out int c,                // number of input feature maps
                                                           out int h,                // height of each input filter
                                                           out int w                 // width of  each input filter
                                                           );
Ejemplo n.º 4
0
        public void Cudnn_Descriptors_ConstructTensorWithMajorRow()
        {
            var param = new CudnnTensorDescriptorParameters(CudnnType.Float, CudnnTensorFormat.MajorRow, 10, 5, 2, 4);

            using (var tensor = CudnnContext.CreateTensor(param))
                using (var tensor2 = CudnnContext.CreateTensor())
                {
                    Assert.True(tensor.IsInitialized);
                    Assert.False(tensor2.IsInitialized);

                    CudnnContext.Invoke(() => CudnnNativeMethods.cudnnSetTensor4dDescriptor(tensor2.Handle, CudnnTensorFormat.MajorRow, CudnnType.Float, 10, 5, 2, 4));


                    CudnnType dataType = default(CudnnType);
                    int       n1 = 0, c1 = 0, h1 = 0, w1 = 0;
                    int       nStride1 = 0, cStride1 = 0, hStride1 = 0, wStride1 = 0;
                    CudnnContext.Invoke(() => CudnnNativeMethods.cudnnGetTensor4dDescriptor(tensor.Handle, out dataType, out n1, out c1, out h1, out w1, out nStride1, out cStride1, out hStride1, out wStride1));

                    int n2 = 0, c2 = 0, h2 = 0, w2 = 0;
                    int nStride2 = 0, cStride2 = 0, hStride2 = 0, wStride2 = 0;
                    CudnnContext.Invoke(() => CudnnNativeMethods.cudnnGetTensor4dDescriptor(tensor2.Handle, out dataType, out n2, out c2, out h2, out w2, out nStride2, out cStride2, out hStride2, out wStride2));

                    Assert.Equal(n2, n1);
                    Assert.Equal(c2, c1);
                    Assert.Equal(h2, h1);
                    Assert.Equal(w2, w1);

                    Assert.Equal(nStride2, nStride1);
                    Assert.Equal(cStride2, cStride1);
                    Assert.Equal(hStride2, hStride1);
                    Assert.Equal(wStride2, wStride1);
                }
        }
Ejemplo n.º 5
0
 public static extern CudnnStatus cudnnGetTensor4dDescriptor(CudnnTensorDescriptorHandle tensorDesc,
                                                             out CudnnType dataType,      // image data type
                                                             out int n,                   // number of inputs (batch size)
                                                             out int c,                   // number of input feature maps
                                                             out int h,                   // height of input section
                                                             out int w,
                                                             out int nStride,
                                                             out int cStride,
                                                             out int hStride,
                                                             out int wStride);
Ejemplo n.º 6
0
 public static extern CudnnStatus cudnnSetTensor4dDescriptorEx(CudnnTensorDescriptorHandle tensorDesc,
                                                               CudnnType dataType,    // image data type
                                                               int n,                 // number of inputs (batch size)
                                                               int c,                 // number of input feature maps
                                                               int h,                 // height of input section
                                                               int w,
                                                               int nStride,
                                                               int cStride,
                                                               int hStride,
                                                               int wStride);
        public CudnnFilterDescriptorParameters(CudnnType type, int output, int input, int h, int w)
        {
            if (output < 1 || input < 1 || h < 1 || w < 1)
            {
                throw new ArgumentException("At least one of the parameters output, input, h, w was negative.");
            }

            Contract.EndContractBlock();

            this.Type = type;

            this.Output = output;
            this.Input  = input;
            this.Height = h;
            this.Width  = w;
        }
Ejemplo n.º 8
0
        public void Cudnn_Descriptors_ConstructFilterWithSetup(CudnnFilterDescriptorParameters param)
        {
            using (var filter = CudnnContext.CreateFilter(param))
            {
                Assert.True(filter.IsInitialized);

                CudnnType dataType = default(CudnnType);
                int       k = 0, c = 0, h = 0, w = 0;
                CudnnContext.Invoke(() => CudnnNativeMethods.cudnnGetFilterDescriptor(filter.Handle, out dataType, out k, out c, out h, out w));

                Assert.Equal(filter.Parameters.Type, dataType);
                Assert.Equal(filter.Parameters.Output, k);
                Assert.Equal(filter.Parameters.Input, c);
                Assert.Equal(filter.Parameters.Height, h);
                Assert.Equal(filter.Parameters.Width, w);
            }
        }
Ejemplo n.º 9
0
        private static void CheckIfCompatible(CudnnType type, params ITypeAware[] parameters)

        {
            Contract.Requires(parameters != null);
            Contract.ForAll <ITypeAware>(parameters, x => x != null && x.Type == type);

            foreach (var param in parameters)
            {
                if (param == null)
                {
                    throw new ArgumentNullException("Parameter is null");
                }

                if (param.Type != type)
                {
                    throw new ArgumentException(string.Format("One of the descriptors with type {0} is not CudnnType.{1}", param.GetType().Name, type.ToString()));
                }
            }
        }
Ejemplo n.º 10
0
        public void Cudnn_Descriptors_ConstructTensorWithSetup(CudnnTensorDescriptorParameters param)
        {
            using (var tensor = CudnnContext.CreateTensor(param))
            {
                Assert.True(tensor.IsInitialized);

                CudnnType dataType = default(CudnnType);
                int       n = 0, c = 0, h = 0, w = 0;
                int       nStride = 0, cStride = 0, hStride = 0, wStride = 0;
                CudnnContext.Invoke(() => CudnnNativeMethods.cudnnGetTensor4dDescriptor(tensor.Handle, out dataType, out n, out c, out h, out w, out nStride, out cStride, out hStride, out wStride));

                Assert.Equal(tensor.Parameters.Num, n);
                Assert.Equal(tensor.Parameters.Channels, c);
                Assert.Equal(tensor.Parameters.Height, h);
                Assert.Equal(tensor.Parameters.Width, w);

                Assert.Equal(tensor.Parameters.NumStride, nStride);
                Assert.Equal(tensor.Parameters.ChannelsStride, cStride);
                Assert.Equal(tensor.Parameters.HeightStride, hStride);
                Assert.Equal(tensor.Parameters.WidthStride, wStride);
            }
        }
        public CudnnTensorDescriptorParameters(CudnnType type, int n, int c, int h, int w, int nStride, int cStride, int hStride, int wStride)
        {
            if (n < 1 || c < 1 || h < 1 || w < 1)
            {
                throw new ArgumentException("At least one of the parameters n, c, h, w was negative.");
            }

            if (nStride < 1 || cStride < 1 || hStride < 1 || wStride < 1)
            {
                throw new ArgumentException("At least one of the parameters nStride, cStride,h Stride, wStride is negative.");
            }

            this.Type = type;

            this.Num      = n;
            this.Channels = c;
            this.Height   = h;
            this.Width    = w;

            this.NumStride      = nStride;
            this.ChannelsStride = cStride;
            this.HeightStride   = hStride;
            this.WidthStride    = wStride;
        }
Ejemplo n.º 12
0
 public static extern CudnnStatus cudnnSetTensor4dDescriptorEx(CudnnTensorDescriptorHandle tensorDesc,
                                                               CudnnType dataType,    // image data type
                                                               int n,                 // number of inputs (batch size)
                                                               int c,                 // number of input feature maps
                                                               int h,                 // height of input section
                                                               int w,
                                                               int nStride,
                                                               int cStride,
                                                               int hStride,
                                                               int wStride);
Ejemplo n.º 13
0
 public static extern CudnnStatus cudnnSetFilterDescriptor(CudnnFilterDescriptorHandle filterDescriptor,
                                                           CudnnType dataType,    // image data type
                                                           int k,                 // number of output feature maps
                                                           int c,                 // number of input feature maps
                                                           int h,                 // height of each input filter
                                                           int w                 // width of  each input filter
                                                          );
        public CudnnFilterDescriptorParameters(CudnnType type, int output, int input, int h, int w)
        {
            if (output < 1 || input < 1 || h < 1 || w < 1)
                throw new ArgumentException("At least one of the parameters output, input, h, w was negative.");

            Contract.EndContractBlock();

            this.Type = type;

            this.Output = output;
            this.Input = input;
            this.Height = h;
            this.Width = w;
        }
        public CudnnTensorDescriptorParameters(CudnnType type, CudnnTensorFormat format, int n, int c, int h, int w)
        {
            if (n < 1 || c < 1 || h < 1 || w < 1)
                throw new ArgumentException("At least one of the parameters n, c, h, w was negative.");

            this.Type = type;

            this.Num = n;
            this.Channels = c;
            this.Height = h;
            this.Width = w;

            this.NumStride = h * w * c;

            if ( format == CudnnTensorFormat.MajorRow )
            {
                this.ChannelsStride = h * w;
                this.HeightStride = w;
                this.WidthStride = 1;
            }
            else
            {
                this.ChannelsStride = 1;
                this.HeightStride = w * c;
                this.WidthStride = c;
            }
        }
        public CudnnTensorDescriptorParameters(CudnnType type, int n, int c, int h, int w, int nStride, int cStride, int hStride, int wStride)
        {
            if (n < 1 || c < 1 || h < 1 || w < 1)
                throw new ArgumentException("At least one of the parameters n, c, h, w was negative.");

            if (nStride < 1 || cStride < 1 || hStride < 1 || wStride < 1)
                throw new ArgumentException("At least one of the parameters nStride, cStride,h Stride, wStride is negative.");

            this.Type = type;

            this.Num = n;
            this.Channels = c;
            this.Height = h;
            this.Width = w;

            this.NumStride = nStride;
            this.ChannelsStride = cStride;
            this.HeightStride = hStride;
            this.WidthStride = wStride;
        }
Ejemplo n.º 17
0
        private static void CheckIfCompatible(CudnnType type, params ITypeAware[] parameters)
        {
            Contract.Requires(parameters != null);
            Contract.ForAll<ITypeAware>(parameters, x => x != null && x.Type == type);

            foreach (var param in parameters)
            {
                if (param == null)
                    throw new ArgumentNullException("Parameter is null");

                if (param.Type != type)
                    throw new ArgumentException(string.Format("One of the descriptors with type {0} is not CudnnType.{1}", param.GetType().Name, type.ToString()));
            }
        }
Ejemplo n.º 18
0
 public static extern CudnnStatus cudnnGetTensor4dDescriptor(CudnnTensorDescriptorHandle tensorDesc,
                                                               out CudnnType dataType,    // image data type
                                                               out int n,                 // number of inputs (batch size)
                                                               out int c,                 // number of input feature maps
                                                               out int h,                 // height of input section
                                                               out int w,
                                                               out int nStride,
                                                               out int cStride,
                                                               out int hStride,
                                                               out int wStride);