1

I'm using Spring 3.1.1.RELEASE. I'm having difficulty binding a List property of my model to a form:checkboxes element upon form submission. In my model I have

private List<User> users;

On my JSP I have

<form:checkboxes items="${searchResults}" path="users" itemLabel="firstName" itemValue="id" />

However, when I submit my form, I get the exception below. I have registered a property editor to convert Strings to my User objects and back again. Also, I have defined an equals and hashCode method in my User object. Any advice on how I should proceed?

org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 error
Field error in object 'updateRosterForm' on field 'users': rejected value [851202348EC24894B8D11EB01009B053,96A1FE8E034C4470AF7337408B962DF5]; codes [typeMismatch.updateRosterForm.users,typeMismatch.users,typeMismatch.java.util.List,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [updateRosterForm.users,users]; arguments []; default message [users]]; default message [Failed to convert property value of type 'java.lang.String[]' to required type 'java.util.List' for property 'users'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [org.mainco.subco.user.domain.User] for property 'users[0]': no matching editors or conversion strategy found]
org.springframework.web.method.annotation.ModelAttributeMethodProcessor.resolveArgument(ModelAttributeMethodProcessor.java:111)
org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:75)
org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:156)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:117)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:322)
org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:116)
org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:182)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:184)
org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:155)
org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)

Take average over blocks Cuda

Cuda said that the shared memory can only be shared by data in the same block. But a block can only have at most 1024 threads. What if I have a huge matrix, and want to take average of them with maximized threads.

Takes this as an example. (I didn't use the maximized threads in one block, just as a demo)

#include <iostream>
#include <stdio.h>

__global__ void
kernel(int *a, int dimx, int dimy)
{
int ix = blockDim.x * blockIdx.x + threadIdx.x;
int iy = blockDim.y * blockIdx.y + threadIdx.y;

int idx = iy * dimx + ix;

__shared__ int array[64];

a[idx] = a[idx] + 1;

array[idx] = a[idx];

__syncthreads();

int sum=0;
for(int i=0; i<dimx*dimy; i++)
{
    sum += array[i];
}

int average = sum/(dimx*dimy+1.0f);

a[idx] = average;

 }

int
main()
{
int dimx = 8;
int dimy = 8;
int num_bytes = dimx*dimy*sizeof(int);

int *d_a=0, *h_a=0; // device and host pointers
h_a = (int*)malloc(num_bytes);

for (int i=0; i < dimx*dimy; i++){
    *(h_a+i) = i;
}
cudaMalloc( (void**)&d_a, num_bytes );

//cudaMemset( d_a, 0, num_bytes );

cudaMemcpy( d_a, h_a, num_bytes, cudaMemcpyHostToDevice);

dim3 grid, block;
block.x = 4;
block.y = 4;
grid.x = dimx / block.x;
grid.y = dimy / block.y;

kernel<<<grid, block>>>(d_a, dimx, dimy);

cudaMemcpy( h_a, d_a, num_bytes, cudaMemcpyDeviceToHost );


std::cout << "the array a is:" << std::endl;
for (int row = 0; row < dimy; row++)
{
    for (int col =0; col < dimx; col++)
    {
        std::cout << h_a[row * dimx + col] << " ";
    }
    std::cout << std::endl;
}

free(h_a);
cudaFree(d_a);
}

I create four blocks, and want to the results to be average of all of them. Now the result is:

the array a is:
3 3 3 3 4 4 4 4 
3 3 3 3 4 4 4 4 
3 3 3 3 4 4 4 4 
3 3 3 3 4 4 4 4 
11 11 11 11 12 12 12 12 
11 11 11 11 12 12 12 12 
11 11 11 11 12 12 12 12 
11 11 11 11 12 12 12 12

Each block has its own average, rather overall average. How could I take the average over all the blocks?

I'm new to Cuda. Any relevant answer is welcomed.

4

1 回答 1

0

我有点撒谎——虽然我注册了一个编辑,但它是为错误的课程。为 User.class (有问题的对象)注册正确的编辑器解决了我的问题。

于 2013-06-26T16:21:55.500 回答