Esempio n. 1
0
 public MemoryTier this[Fld fld]
 {
     get
     {
         return this[fld.AssertNotNull().Field];
     }
 }
Esempio n. 2
0
 public MemoryTier this[Fld fld]
 {
     get
     {
         return(this[fld.AssertNotNull().Field]);
     }
 }
Esempio n. 3
0
        public Layout this[Fld fld]
        {
            get
            {
                fld.AssertNotNull();

                var fi = fld.Field;
                fi.AssertNotNull();
                _kernel.DeclaringType.Hierarchy().Contains(fi.DeclaringType).AssertTrue();

                return(_fi_cache.GetOrCreate(fi, () =>
                {
                    var t = fi.FieldType;
                    if (_scheme[fi] == MemoryTier.Private)
                    {
                        if (t.IsArray)
                        {
                            throw AssertionHelper.Fail();
                        }
                        else
                        {
                            throw AssertionHelper.Fail();
                        }
                    }
                    else if (_scheme[fi] == MemoryTier.Shared)
                    {
                        if (t.IsArray)
                        {
                            throw AssertionHelper.Fail();
                        }
                        else
                        {
                            throw AssertionHelper.Fail();
                        }
                    }
                    else if (_scheme[fi] == MemoryTier.Global)
                    {
                        if (fi.FieldType.IsArray)
                        {
                            var p_raw = new Var {
                                Space = space.param, Name = "parm_" + fi.Name, Type = typeof(uint)
                            };
                            var raw = new Reg {
                                Type = typeof(uint), Name = fi.Name
                            };
                            _ptx.Add(new ld {
                                ss = space.param, type = typeof(uint), d = raw, a = p_raw
                            });

                            var p_height = new Var {
                                Space = space.param, Name = "parm_" + fi.Name + "_height", Type = typeof(int)
                            };
                            var height = new Reg {
                                Type = typeof(int), Name = fi.Name + "_height"
                            };
                            _ptx.Add(new ld {
                                ss = space.param, type = typeof(int), d = height, a = p_height
                            });

                            var p_width = new Var {
                                Space = space.param, Name = "parm_" + fi.Name + "_width", Type = typeof(int)
                            };
                            var width = new Reg {
                                Type = typeof(int), Name = fi.Name + "_width"
                            };
                            _ptx.Add(new ld {
                                ss = space.param, type = typeof(int), d = width, a = p_width
                            });

                            _params.AddElements(p_raw, p_height, p_width);
                            return new ArrayLayout(fld, space.global, raw, new [] { height, width }.ToReadOnly());
                        }
                        else
                        {
                            (t.IsCudaPrimitive() || t.IsCudaVector()).AssertTrue();

                            var p_value = new Var {
                                Space = space.param, Name = "parm_" + fi.Name, Type = t
                            };
                            var value = new Reg {
                                Type = t, Name = fi.Name
                            };
                            _ptx.Add(new ld {
                                ss = space.param, type = t, d = value, a = p_value
                            });

                            _params.Add(p_value);
                            return new SlotLayout(fld, value);
                        }
                    }
                    else
                    {
                        throw AssertionHelper.Fail();
                    }
                }));
            }
        }
Esempio n. 4
0
        public Layout this[Fld fld]
        {
            get
            {
                fld.AssertNotNull();

                var fi = fld.Field;
                fi.AssertNotNull();
                _kernel.DeclaringType.Hierarchy().Contains(fi.DeclaringType).AssertTrue();

                return _fi_cache.GetOrCreate(fi, () =>
                {
                    var t = fi.FieldType;
                    if (_scheme[fi] == MemoryTier.Private)
                    {
                        if (t.IsArray)
                        {
                            throw AssertionHelper.Fail();
                        }
                        else
                        {
                            throw AssertionHelper.Fail();
                        }
                    }
                    else if (_scheme[fi] == MemoryTier.Shared)
                    {
                        if (t.IsArray)
                        {
                            throw AssertionHelper.Fail();
                        }
                        else
                        {
                            throw AssertionHelper.Fail();
                        }
                    }
                    else if (_scheme[fi] == MemoryTier.Global)
                    {
                        if (fi.FieldType.IsArray)
                        {
                            var p_raw = new Var{Space = space.param, Name = "parm_" + fi.Name, Type = typeof(uint)};
                            var raw = new Reg{Type = typeof(uint), Name = fi.Name};
                            _ptx.Add(new ld{ss = space.param, type = typeof(uint), d = raw, a = p_raw});

                            var p_height = new Var{Space = space.param, Name = "parm_" + fi.Name + "_height", Type = typeof(int)};
                            var height = new Reg{Type = typeof(int), Name = fi.Name + "_height"};
                            _ptx.Add(new ld{ss = space.param, type = typeof(int), d = height, a = p_height});

                            var p_width = new Var{Space = space.param, Name = "parm_" + fi.Name + "_width", Type = typeof(int)};
                            var width = new Reg{Type = typeof(int), Name = fi.Name + "_width"};
                            _ptx.Add(new ld{ss = space.param, type = typeof(int), d = width, a = p_width});

                            _params.AddElements(p_raw, p_height, p_width);
                            return new ArrayLayout(fld, space.global, raw, new []{height, width}.ToReadOnly());
                        }
                        else
                        {
                            (t.IsCudaPrimitive() || t.IsCudaVector()).AssertTrue();

                            var p_value = new Var{Space = space.param, Name = "parm_" + fi.Name, Type = t};
                            var value = new Reg{Type = t, Name = fi.Name};
                            _ptx.Add(new ld{ss = space.param, type = t, d = value, a = p_value});

                            _params.Add(p_value);
                            return new SlotLayout(fld, value);
                        }
                    }
                    else
                    {
                        throw AssertionHelper.Fail();
                    }
                });
            }
        }