Array create expressions are not supported.

Jan 8, 2014 at 8:25 PM
I have an array inside a struct and I can't initialize it in the struct because the compiler gives me an error. If I tried to initialize it in a kernl it gives me "Array create expressions are not supported."!!

What is the solution for this problem ?

Waiting your reply A.S.A.P. and thank you in advance.
class Program
    {
        // Don't forget to decleare the current player 
        [Cudafy]
        public struct CheckersBoard
        {
            // Holds the checkers board representation.
            public int[] pieces;
            // Piece counters for each side.
            public int whitePieces;
            public int blackPieces;
            // As it implies, holds the current player
            public int currentPlayer;
        };

        static void Main(string[] args)
        {
            CudafyModule km = CudafyTranslator.Cudafy(eArchitecture.sm_35);

            GPGPU gpu = CudafyHost.GetDevice(CudafyModes.Target, CudafyModes.DeviceId);
            gpu.LoadModule(km);

            CheckersBoard [] initialBoard = gpu.Allocate <CheckersBoard>(1);

            gpu.Launch().clearBoardKernl(initialBoard);
        }


        [Cudafy]
        public static void clearBoardKernl(CheckersBoard[] board)
        {
            // Pieces used in the game
            int EMPTY = 0;
            int WHITE = 2;
            int WHITE_KING = 3;
            int BLACK = 4;
            int BLACK_KING = 5;

            // Allows the game to know which pieces are promoted
            //to king
            int KING = 1;


            int i;
            board[0].whitePieces = 12;
            board[0].blackPieces = 12;

            board[0].currentPlayer = BLACK;

            board[0].pieces = new int[32];

            // Convert it later to threadIDx after making it a kernl
            for (i = 0; i < 12; i++)
                board[0].pieces[i] = BLACK;

            for (i = 12; i < 20; i++)
                board[0].pieces[i] = EMPTY;

            for (i = 20; i < 32; i++)
                board[0].pieces[i] = WHITE;
        }
    }
Coordinator
Jan 9, 2014 at 8:11 AM
The line board[0].pieces = new int[32]; is not valid in device code. You would need to allocate the pieces member as a fixed array in your CheckersBoard struct.
The aim of GPU code is to have lots of threads in parallel, here you have one. Threads in a single block can make use of shared memory arrays which is efficient.
Take a look at CudafyByExample and CudafyExamples projects to see a wide range of what is possible.
       [Cudafy]
       [StructLayout(LayoutKind.Sequential)]
        public struct CheckersBoard
        {
            // Holds the checkers board representation.
            public fixed int pieces[32];
            // Piece counters for each side.
            public int whitePieces;
            public int blackPieces;
            // As it implies, holds the current player
            public int currentPlayer;
        };