Exemple #1
0
        /// <summary>
        /// Constructs a new cuRand wrapper.
        /// </summary>
        /// <param name="accelerator">The associated Cuda accelerator.</param>
        /// <param name="rngType">The cuRand RNG type.</param>
        /// <param name="apiVersion">The cuRand API version.</param>
        private GPUCuRand(
            CudaAccelerator accelerator,
            CuRandRngType rngType,
            CuRandAPIVersion?apiVersion)
            : base(accelerator)
        {
            API = CuRandAPI.Create(apiVersion);

            CuRandException.ThrowIfFailed(
                API.CreateGenerator(out IntPtr nativePtr, rngType));
            GeneratorPtr = nativePtr;

            CuRandException.ThrowIfFailed(
                API.GetVersion(out int version));
            Version = version;

            Stream = accelerator.DefaultStream as CudaStream;
        }
Exemple #2
0
        /// <summary>
        /// Constructs a new cuRand wrapper.
        /// </summary>
        /// <param name="context">The parent ILGPU context.</param>
        /// <param name="rngType">The cuRand RNG type.</param>
        /// <param name="apiVersion">The cuRand API version.</param>
        private CPUCuRand(
            Context context,
            CuRandRngType rngType,
            CuRandAPIVersion?apiVersion)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            // Note: We currently do not use the context parameter to instantiate the API.
            // However, we do pass the context instance to this constructor to ensure
            // upward compatibility.

            API = CuRandAPI.Create(apiVersion);

            CuRandException.ThrowIfFailed(
                API.CreateGeneratorHost(out IntPtr nativePtr, rngType));
            GeneratorPtr = nativePtr;

            CuRandException.ThrowIfFailed(
                API.GetVersion(out int version));
            Version = version;
        }